RunicTestWindow class

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

public sealed class RunicTestWindow : IAsyncDisposable

Inherits or implements IAsyncDisposable.

A real RunicWindow opened headless by RunicWindowTestHost.CreateWindowAsync, or by the application while it runs, for example from a command through IRunicWindowService.

Remarks

The Window opens as on Runic Desktop: in a new scope of the application's services, with its parameter, its result, its IRunicWindowContext and its close guard. RunicTestWindow.RequestUserCloseAsync is the user's close button, which asks RunicWindow.CanCloseAsync when the Window guards its close. Each Window has a RunicTestWindowPresentation, so IRunicWindowService.ActivateAsync and IRunicWindowService.FindOrOpenAsync are recorded as RunicTestWindowPresentation.PresentCount.

An owned Window (RunicWindowOptions.Owner) closes when its owner closes, and a window-modal one sets RunicTestWindow.IsBlocked on its owner while it is open, as on Runic Desktop.

Properties

IsBlocked

public bool IsBlocked { get; }

Whether a window-modal Window that this Window owns is open, so the user cannot use this one.

IsDraining

public bool IsDraining { get; }

Whether the Window's close was decided and it stays open while its accepted work drains (RunicWindowOptions.CloseDrain, RunicWindowTestHostOptions.CloseDrain): its operation admission stopped, its page received closing with draining: true and still receives its state. It closes by itself when the work has ended or the drain's timeout passed on the Window's clock.

IsOpen

public bool IsOpen { get; }

Whether the Window is open: it has not closed, by the user or the application.

Remarks

A Window that drains after its close was decided (RunicTestWindow.IsDraining) is still open.

Key

public object? Key { get; }

Modality

public RunicWindowModality Modality { get; }

Whether this Window blocks its RunicTestWindow.Owner; RunicWindowModality.None without one.

OpenedWindows

public IReadOnlyList<RunicTestWindow> OpenedWindows { get; }

The Windows the application opened after this one, in the order they opened, including those that closed since.

Options

public RunicWindowOptions Options { get; }

The options the Window opened with.

Owner

public RunicTestWindow? Owner { get; }

The Window that owns this one (RunicWindowOptions.Owner), or null.

Parameter

public object? Parameter { get; }

The parameter the Window opened with (IRunicWindowParameter), or null.

Presentation

public RunicTestWindowPresentation Presentation { get; }

The Window's recording presentation.

Services

public IServiceProvider Services { get; }

The services of the Window's scope.

ViewModel

public object ViewModel { get; }

The Window's root ViewModel.

Window

public IRunicWindow Window { get; }

The Window.

Methods

DisposeAsync

public ValueTask DisposeAsync()

Closes this Window and releases its scope. For the Window that RunicWindowTestHost.CreateWindowAsync returned, it closes and releases every Window of the application; for one of RunicTestWindow.OpenedWindows, only that Window and the Windows it owns, which close with it.

Host

public RunicWindowTestHost<TViewModel> Host<TViewModel>() where TViewModel : class

The test host of the Window's content session, which drives its root ViewModel and the Views it presents.

Type parameters

TViewModel

The Window's root ViewModel type.

Exceptions

InvalidOperationException

The Window's ViewModel is not a TViewModel.

RequestUserCloseAsync

public Task<bool> RequestUserCloseAsync(CancellationToken cancellationToken = default)

Closes the Window as the user's close button does, and returns whether it closed: a Window that guards its close (RunicWindow.GuardClose) first asks RunicWindow.CanCloseAsync and stays open when that returns false.

Parameters

cancellationToken

Stops this caller's wait; the decision continues.

Returns

true when the Window closed.

Exceptions

InvalidOperationException

A window-modal Window blocks this one.

Remarks

The Windows it owns are asked first, innermost first, as Runic Desktop does: one that refuses keeps this Window open, and a window-modal one that agrees closes before this Window's own guard is asked. A request while another request or IRunicWindow.RequestCloseAsync is being decided waits for the same decision. A closed Window returns true. The Windows it owns close with it.

A Window with a close drain (RunicWindowOptions.CloseDrain) returns true once the close was decided and stays open while it drains (RunicTestWindow.IsDraining); IRunicWindow.WaitForCloseAsync waits until it closed. A request during the drain is ignored and returns true, as the user's second close is.

The user cannot close a Window that a window-modal Window blocks (RunicTestWindow.IsBlocked), as on Windows and macOS: the call throws instead of passing where the application could not. Its page takes no input either: its root driver's commands, operation starts, sets and writes throw InvalidOperationException, while snapshots still read its state. IRunicWindow.RequestCloseAsync, the application's request, still works.

Root

public RunicViewDriver<TViewModel> Root<TViewModel>() where TViewModel : class

Drives the Window's root ViewModel, as RunicWindowTestHost.Root does.

Type parameters

TViewModel

The Window's root ViewModel type.

WaitForOpenedWindowAsync

public Task<RunicTestWindow> WaitForOpenedWindowAsync<TWindow>(TimeSpan? timeout = null, CancellationToken cancellationToken = default) where TWindow : class, IRunicWindow

Waits until the application opened a TWindow after this Window and returns the last one still open, for example a dialog that a command opened with IRunicWindowService.OpenForResultAsync.

Parameters

timeout

How long to wait in real time; null for 5 seconds.

cancellationToken

Cancels the wait.

Exceptions

TimeoutException

No such Window opened in time.