RunicWindowTestHost<TViewModel> class

Namespace Runic.Application.Testing · Runic.Application.Testing 0.7.0-preview.5

public sealed class RunicWindowTestHost<TViewModel> : IDisposable where TViewModel : class

Inherits or implements IDisposable.

Owns one headless Window content session and its generated root attachment. The caller retains ownership of the ViewModel and any dependency injection scope.

Constructors

RunicWindowTestHost

public RunicWindowTestHost(TViewModel viewModel, string rootRoute, Func<IBridgeTransport, WindowContentSession, TViewModel, IDisposable> attach, IRunicViewLocator? viewLocator = null, CancellationToken operationShutdown = default, IRunicModelContext? modelContext = null)

Creates a content session for viewModel and attaches its generated root bridge.

Parameters

viewModel

The root ViewModel; the caller keeps ownership.

rootRoute

The generated root route name.

attach

The generated bridge factory.

viewLocator

Resolves .NET Views for presented content.

operationShutdown

Cancels window-owned operations when signalled.

modelContext

The model context the window graph must share, if any.

Remarks

This host uses the system clock and random content ids. The constructor that takes RunicWindowTestHostOptions uses a fake clock and sequential ids.

RunicWindowTestHost

public RunicWindowTestHost(TViewModel viewModel, Func<IBridgeTransport, WindowContentSession, TViewModel, IDisposable> attach, RunicWindowTestHostOptions? options)

Creates a content session for viewModel and attaches its generated root bridge. By default the window uses a FakeTimeProvider and sequential ids.

Parameters

viewModel

The root ViewModel; the caller keeps ownership.

attach

The generated bridge factory, such as the Func<IBridgeTransport, WindowContentSession, TViewModel, IDisposable> that the generated AddRunicBridges() registers.

options

The root route, View locator, clock and id source.

RunicWindowTestHost

public RunicWindowTestHost(TViewModel viewModel, Func<IBridgeTransport, WindowContentSession, TViewModel, IDisposable> attach)

Creates a content session for viewModel with a FakeTimeProvider and sequential ids, and attaches its generated root bridge.

Parameters

viewModel

The root ViewModel; the caller keeps ownership.

attach

The generated bridge factory.

Properties

Content

public WindowContentSession Content { get; }

The window content session.

Root

public RunicViewDriver<TViewModel> Root { get; }

Drives the root ViewModel's generated routes.

RootRoute

public string RootRoute { get; }

The generated root route name.

Time

public TimeProvider Time { get; }

The window's clock. With the options constructor it is a FakeTimeProvider unless the options supply another clock.

Transport

public InMemoryViewTransport Transport { get; }

The in-memory transport that records routes and publications.

ViewModel

public TViewModel ViewModel { get; }

The root ViewModel.

Methods

BeginCloseAsync

public ValueTask<BridgeWindowCloseResult> BeginCloseAsync(TimeSpan timeout)

Stops admission and waits for accepted Window operations.

Dispose

public void Dispose()

Detaches the root bridge and disposes the content session and transport.

Mount

public string Mount(PageReference reference, string token, string? clientKey = null, string? connectionKey = null)

Acknowledges that a frontend View was mounted.

Snapshot

public JsonDocument Snapshot()

Reads a generated snapshot from the root route.

Snapshot

public JsonDocument Snapshot(PageReference reference)

Reads a generated snapshot from a routed View.

Unmount

public string Unmount(PageReference reference, string token, string? clientKey = null, string? connectionKey = null)

Acknowledges that a frontend View was unmounted.

View

public RunicViewDriver<TContent> View<TContent>(PageReference reference) where TContent : class

Drives the routes of presented content, such as a reference from a snapshot.