Table of Contents

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

int

Properties

CertificateOptions

public static CertificateOptions CertificateOptions { get; }

Property Value

CertificateOptions

ServerProcesses

public static List<Process> ServerProcesses { get; }

Property Value

List<Process>

ServiceProvider

public static ServiceProvider ServiceProvider { get; }

Property Value

ServiceProvider

Methods

AssertServersStarted(Action<Process, string>)

public static void AssertServersStarted(Action<Process, string> processAssert)

Parameters

processAssert Action<Process, string>

DeployCertificate(string, string)

public static void DeployCertificate(string certificate, string node)

Parameters

certificate string
node string

GetConfiguration(string)

public static IConfiguration GetConfiguration(string environment)

Parameters

environment string

Returns

IConfiguration

GetHttpClientAsync()

Side-effect free HTTPS client using the client certificate.

public static Task<HttpClient> GetHttpClientAsync()

Returns

Task<HttpClient>

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

string

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 string
mediatrCfg 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 string

The server project directory.

serverProject string

The .csproj file of the server project.

launchProfile string

Defined in its Properties\launchSettings.json.

port int

The main port to wait for accepting TCP connections.

oldPort int

he 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)

Parameters

port int

port to listen on

timeout int

expected duration of all tests in sec