RunicTestPlatformServiceCollectionExtensions class

Namespace Runic.Application.Testing in Runic.Application.Testing 0.23.0

public static class RunicTestPlatformServiceCollectionExtensions

Registers the test platform fakes in place of the application's platform services.

Fields

DirectoryEnvironmentVariable

public const string DirectoryEnvironmentVariable = "RUNIC_TEST_PLATFORM_DIRECTORY"

The environment variable that names a RunicServeOnlyTestPlatform's directory.

Methods

AddRunicServeOnlyTestPlatform

public static IServiceCollection AddRunicServeOnlyTestPlatform(this IServiceCollection services)

In a test build of an application started by a serve-only browser test with a RunicServeOnlyTestPlatform, registers test platform fakes that the test scripts across the process boundary; otherwise does nothing.

Parameters

services

The application's services.

Returns

services.

Exceptions

InvalidOperationException

Serve-only mode and RunicTestPlatformServiceCollectionExtensions.DirectoryEnvironmentVariable are set, but the application's entry assembly does not carry RunicServeOnlyTestPlatformAttribute, or the directory does not exist or other users can write to it.

Remarks

The fakes are registered only when the build opted in and both RUNIC_APPLICATION_SERVE_ONLY=1 and RunicTestPlatformServiceCollectionExtensions.DirectoryEnvironmentVariable are set, which RunicServeOnlyTestPlatform.Configure does. The build opts in with [assembly: RunicServeOnlyTestPlatform] on the entry assembly, which a test-only configuration adds, for example with an AssemblyAttribute item; see the package README. When the fakes are registered, the first window logs warning 1158 ServeOnlyTestPlatformActive.

Every window shares one RunicTestPlatform, since the script is one queue; closing a window does not close it. Call this method after the application's own AddRunicPlatformServices().

Production builds must not reference this package. Call this method only from a test build of the application.

AddRunicTestPlatform

public static IServiceCollection AddRunicTestPlatform(this IServiceCollection services)

Registers a RunicTestPlatform for each window scope, as IWindowPlatformServices, IFileDialogs, ITextClipboard, IDesktopClipboard, IDesktopFileLauncher and IDesktopMessageBoxes, and one RunicTestNotifications as IDesktopNotifications for the application.

Parameters

services

The application's services.

Returns

services.

Remarks

The registrations replace those of AddRunicPlatformServices(), whether it ran before or after this call. RunicWindowTestHost.Create resolves the scope's platform as RunicWindowTestHost.Platform; the scope closes it when it is disposed, and so does disposing the host.