Class TestSetUp
- Namespace
- DMediatR
- Assembly
- DMediatR.dll
Helper methods for setting up a DMediatR environment in functional unit tests without a dependency to a specific test framework.
public static class TestSetUp
- Inheritance
-
TestSetUp
- Inherited Members
Fields
ServerStartTimeout
public const int ServerStartTimeout = 1
Field Value
Properties
CertificateOptions
public static CertificateOptions CertificateOptions { get; }
Property Value
ServerProcesses
public static List<Process> ServerProcesses { get; }
Property Value
ServiceProvider
public static ServiceProvider ServiceProvider { get; }
Property Value
Methods
AssertServersStarted(Action<Process, string>)
public static void AssertServersStarted(Action<Process, string> processAssert)
Parameters
DeployCertificate(string, string)
public static void DeployCertificate(string certificate, string node)
Parameters
GetConfiguration(string)
public static IConfiguration GetConfiguration(string environment)
Parameters
environment
string
Returns
GetHttpClientAsync()
Side-effect free HTTPS client using the client certificate.
public static Task<HttpClient> GetHttpClientAsync()
Returns
GetProcessProfile(Process)
Extracts the profile name out of a StartInfo string like FileName = "C:\Program Files\dotnet\dotnet.exe", Arguments = "run --no-build --project DMediatRNode.csproj --launch-profile Monolith", WorkingDirectory = ...
public static string GetProcessProfile(Process process)
Parameters
process
Process
Returns
SetUpDMediatRServices(string?, Action<MediatRServiceConfiguration>, Func<IServiceCollection, IServiceCollection>?)
Instantiate the ServiceProvider with appsettings[.environment].json
public static void SetUpDMediatRServices(string? environment, Action<MediatRServiceConfiguration> mediatrCfg, Func<IServiceCollection, IServiceCollection>? serviceCollectionAction = null)
Parameters
environment
stringmediatrCfg
Action<MediatRServiceConfiguration>serviceCollectionAction
Func<IServiceCollection, IServiceCollection>
SetUpInitialCertificates()
Create an initial valid X509 certificate chain in the directory configured in the Certificate section.
public static void SetUpInitialCertificates()
StartServer(string, string, string, int, int)
Start the gRPC server project with the launch profile.
public static void StartServer(string workingDirectory, string serverProject, string launchProfile, int port, int oldPort)
Parameters
workingDirectory
stringThe server project directory.
serverProject
stringThe .csproj file of the server project.
launchProfile
stringDefined in its Properties\launchSettings.json.
port
intThe main port to wait for accepting TCP connections.
oldPort
inthe TCP renewal port to wait for accepting TCP connections.
StopAllServers()
public static void StopAllServers()
WaitForServerPort(int, int)
Poll for a successful TCP connection at the given port
public static void WaitForServerPort(int port, int timeout = 1)