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
environmentstring
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
processProcess
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
environmentstringmediatrCfgAction<MediatRServiceConfiguration>serviceCollectionActionFunc<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
workingDirectorystringThe server project directory.
serverProjectstringThe .csproj file of the server project.
launchProfilestringDefined in its Properties\launchSettings.json.
portintThe main port to wait for accepting TCP connections.
oldPortinthe 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)