public sealed class RunicServeOnlyTestPlatform : IDisposable Scripts the platform fakes of an application that a browser test runs with RunicServeOnlyApplication, and reads what the application did with them: the file dialogs, message boxes, context menus and clipboard of RunicTestPlatform, across the process boundary.
Remarks
The application opts in from a test build with RunicTestPlatformServiceCollectionExtensions.AddRunicServeOnlyTestPlatform. The test creates this object, passes the start information through RunicServeOnlyTestPlatform.Configure, and queues responses before the page action that shows a dialog; the application applies them in order at its next platform call. The fakes have the names of RunicTestPlatform's (FileDialogs.EnqueueOpen, Clipboard.SetText, ContextMenus.EnqueueChoice), so a test moves between the in-process host and serve-only unchanged:
using var platform = RunicServeOnlyTestPlatform.Create();
var start = platform.Configure(RunicServeOnlyApplication.CreateStartInfo(appPath));
await using var app = await RunicServeOnlyApplication.StartAsync(start);
platform.FileDialogs.EnqueueOpen("notes.txt", "Hello");
await page.GetByRole(AriaRole.Button, new() { Name = "Open" }).ClickAsync();
var shown = await platform.WaitForEventAsync(e => e.Operation == "openFile");The script and the record are JSON-lines files in a temporary directory that disposing deletes. Each method is safe to call from any thread.
Properties
Clipboard
public RunicServeOnlyClipboard Clipboard { get; } Scripts the application's clipboard, with the names of RunicTestPlatform.Clipboard.
ContextMenus
public RunicServeOnlyContextMenus ContextMenus { get; } Scripts the application's context menus, with the names of RunicTestPlatform.ContextMenus.
Directory
public string Directory { get; } The directory of the script and the record.
FileDialogs
public RunicServeOnlyFileDialogs FileDialogs { get; } Scripts the application's file dialogs, with the names of RunicTestPlatform.FileDialogs.
MessageBoxes
public RunicServeOnlyMessageBoxes MessageBoxes { get; } Scripts the application's message boxes, with the names of RunicTestPlatform.MessageBoxes.
Methods
Configure
public ProcessStartInfo Configure(ProcessStartInfo startInfo) Points the application at this script: sets RunicTestPlatformServiceCollectionExtensions.DirectoryEnvironmentVariable.
Parameters
startInfoThe start information for
RunicServeOnlyApplication.StartAsync, which is changed.
Returns
startInfo.
Create
public static RunicServeOnlyTestPlatform Create() Creates an empty script in a new temporary directory.
Returns
The script.
Dispose
public void Dispose() Deletes the script's directory.
ReadEvents
public IReadOnlyList<RunicTestPlatformEvent> ReadEvents() The calls the application made so far, oldest first.
Returns
The calls.
WaitForEventAsync
public Task<RunicTestPlatformEvent> WaitForEventAsync(Func<RunicTestPlatformEvent, bool> match, TimeSpan? timeout = null, CancellationToken cancellationToken = default) Waits for the first call that match accepts, including calls made before this one.
Parameters
matchThe condition.
timeoutHow long to wait; 10 seconds by default.
cancellationTokenCancels the wait.
Returns
The call.
Exceptions
TimeoutExceptionNo such call arrived in time; the message lists the calls that did.
InvalidOperationExceptionThe application rejected a scripted line, which it records as a
scripterrorevent, and no earlier call matched; the message is the application's.