public sealed class RunicViewDriver<TModel> where TModel : class Sends the Views protocol 4 requests of one TModel route by ViewModel member, as the generated TypeScript client does, on the transport's test connection.
Remarks
Each request has an asynchronous method, such as RunicViewDriver.SnapshotAsync and RunicViewDriver.SetAsync, that never blocks a thread. The synchronous methods, such as RunicViewDriver.Snapshot and RunicViewDriver.Set, block the calling thread until the reply, while the window's own asynchronous work continues on thread-pool threads. In a suite that runs many tests in parallel on thread-pool threads, each blocked test holds a thread that the replies it waits for need, which can starve the pool and slow the suite down; use the asynchronous methods there.
Example
var editor = await (await host.Root.ViewAsync<DocumentViewModel>(vm => vm.Main)).ViewAsync<EditorViewModel>(vm => vm.CurrentPane);
(await editor.SetAsync(vm => vm.Title, "Groceries")).ThrowIfFailed();
(await editor.ExecuteAsync(vm => vm.SaveCommand)).ThrowIfFailed();
(await editor.ExecuteAsync(vm => vm.RenameCommand, new RenameInput("Groceries", Pinned: true))).ThrowIfFailed();Properties
ClientKey
public string ClientKey { get; } The client of this driver's connection: the one passed to RunicViewDriver.ForConnection, else InMemoryBridgeTransport.DefaultClientKey.
Connection
public RunicConnection? Connection { get; } The window's own connection for this driver's connection, as IRunicConnections reports it, while it is open; null before its first request and after it closed.
Remarks
The window gives each connection a key of its own, which no later connection reuses: on this transport, whose keys can repeat, it is RunicViewDriver.ConnectionKey with a #n suffix. Compare a command's IRunicConnections.Caller with it.
ConnectionKey
public string ConnectionKey { get; } The connection this driver's requests use: InMemoryBridgeTransport.DefaultConnectionKey, or the one passed to RunicViewDriver.ForConnection.
Reference
public PageReference? Reference { get; } The content reference this driver presents, or null for the root route.
Route
public string Route { get; } The route: the root name, or content{id} for presented content.
Methods
CanExecute
public bool CanExecute(Expression<Func<TModel, object?>> command, string argumentJson) Asks whether a command with an input can execute (can{Command}(input)).
Remarks
A command with an asynchronous key resolver answers only after the resolver finishes. A resolver that waits on the host's fake clock blocks this call; use RunicViewDriver.CanExecuteAsync.
CanExecuteAsync
public Task<bool> CanExecuteAsync(Expression<Func<TModel, object?>> command, string argumentJson, CancellationToken cancellationToken = default) Asks whether a command with an input can execute (can{Command}(input)), waiting for an asynchronous key resolver.
Parameters
commandThe command property, such as
vm => vm.DeleteCommand.argumentJsonThe command input or key as wire JSON.
cancellationTokenCancels the resolution, as a closed client connection does.
Exceptions
OperationCanceledExceptioncancellationTokenwas cancelled.
CanExecuteAsync
public Task<bool> CanExecuteAsync<TArgument>(Expression<Func<TModel, object?>> command, TArgument argument, CancellationToken cancellationToken = default) Asks whether a command with an input can execute (can{Command}(input)), with the input encoded as RunicViewDriver.ExecuteAsync encodes it, waiting for an asynchronous key resolver.
Parameters
commandThe command property, such as
vm => vm.DeleteCommand.argumentThe command input or key.
cancellationTokenCancels the resolution, as a closed client connection does.
Exceptions
OperationCanceledExceptioncancellationTokenwas cancelled.
CloseRegionAsync
public Task<RunicCallReply<TModel>> CloseRegionAsync(Expression<Func<TModel, object?>> collection, string key, CancellationToken cancellationToken = default) Closes the region with key of a region collection and removes it, as the client's close{Name}(key) does (region-collections/1). Every entry of the region is asked to retire; RunicCallReply.RegionOutcome says how it ended.
Parameters
collectionThe region collection property, such as
vm => vm.Documents.keyA region's key, from
RunicViewState.Regions.cancellationTokenCancels the request, as a closed client connection does.
ExecuteAsync
public Task<RunicCallReply<TModel>> ExecuteAsync(Expression<Func<TModel, object?>> command, string? argumentJson = null, CancellationToken cancellationToken = default) Executes a command, as the client's {command}(input) does, and waits for an asynchronous command to finish.
Parameters
commandThe command property, such as
vm => vm.SaveCommand.argumentJsonThe command input as wire JSON, for a command with an input. Use
RunicViewDriver.ExecuteAsyncto pass the input as a .NET value.cancellationTokenCancels an awaited command, as a closed client connection does.
Exceptions
ArgumentExceptionargumentJsonis not one JSON value.
Remarks
A command that waits on the host's fake clock finishes only after the test advances it: start the call, advance RunicWindowTestHost.Time, then await the call.
ExecuteAsync
public Task<RunicCallReply<TModel>> ExecuteAsync<TArgument>(Expression<Func<TModel, object?>> command, TArgument argument, CancellationToken cancellationToken = default) Executes a command with an input, as the client's {command}(input) does, and waits for an asynchronous command to finish. The input is encoded as the generated client encodes it.
Parameters
commandThe command property, such as
vm => vm.RenameCommand.argumentThe command input.
cancellationTokenCancels an awaited command, as a closed client connection does.
Remarks
The input follows the Bridge's JSON rules: scalars as RunicViewDriver.SetAsync encodes them, a record or class as an object of its public properties by wire name (camelCase, or its [RunicAlias] or [JsonPropertyName], without [RunicIgnore] and, unless the assembly opts out, [JsonIgnore] members), a case of a [RunicUnion] with its $case, a list or array as an array, a dictionary with string keys as an object, and a type with a [RunicCodec] by its codec.
A String input selects the overload that takes wire JSON unless you name the type: ExecuteAsync<string>(vm => vm.SearchCommand, "groceries").
ForConnection
public RunicViewDriver<TModel> ForConnection(string connectionKey, string? clientKey = null) Returns a driver of this route whose requests, and the drivers and operations it returns, use another page connection, as a second browser tab of a multi-client window does.
Parameters
connectionKeyThe connection's key, as the transport would authenticate it.
clientKeyThe client's key; by default
InMemoryBridgeTransport.DefaultClientKey.
Returns
The driver of the same route on that connection.
Remarks
The connection sends its hello with its first request, and then is one of the window's IRunicConnections.Current; a command it executes runs with it as IRunicConnections.Caller. Close it with InMemoryBridgeTransport.CloseConnection.
var bob = host.Root.ForConnection("bob-tab", clientKey: "bob");
(await bob.ExecuteAsync(vm => vm.JoinCommand)).ThrowIfFailed();IndexOfAsync
public Task<int> IndexOfAsync<TRow, TKey>(Expression<Func<TModel, RunicQueryCollection<TRow, TKey>>> collection, string key, CancellationToken cancellationToken = default) where TKey : notnull Finds the position of a row in a query collection's current query, as a page's scrollToKey does (query-index).
Parameters
collectionThe query collection property, such as
vm => vm.Rows.keyThe row's wire key: the string, a lowercase GUID or an
Int32in decimal.cancellationTokenStops waiting for the reply.
Returns
The row's position, or -1 when no row has the key.
Mount
public string Mount(string? presentation = null, string? clientKey = null, string? connectionKey = null) Opens a presentation of this route, as a page that shows the View sends open.
Parameters
presentationThe presentation id; the host issues
test-presentation{n}when omitted.clientKeyThe client identity, for tests of several browser clients.
connectionKeyThe connection identity, for tests of a client disconnect.
Returns
The presentation id; pass it to RunicViewDriver.Unmount.
Exceptions
InvalidOperationExceptionThe open was not answered
ok; the message names the reply.
MountAsync
public Task<string> MountAsync(string? presentation = null, string? clientKey = null, string? connectionKey = null, CancellationToken cancellationToken = default) Opens a presentation of this route, as a page that shows the View sends open, without blocking a thread.
Parameters
presentationThe presentation id; the host issues
test-presentation{n}when omitted.clientKeyThe client identity, for tests of several browser clients.
connectionKeyThe connection identity, for tests of a client disconnect.
cancellationTokenStops waiting for the reply.
Returns
The presentation id; pass it to RunicViewDriver.UnmountAsync.
Exceptions
InvalidOperationExceptionThe open was not answered
ok; the message names the reply.
MountPresentation
public RunicTestPresentation<TModel> MountPresentation(string? presentation = null, string? clientKey = null, string? connectionKey = null) Opens a presentation of this route that acts as a page's View: it handles every ViewRequest of TModel, so RunicTestPresentation.TakeViewRequests returns the requests it receives, and answers the interactions its Handle registers. Blocks the calling thread until it is open.
Parameters
presentationThe presentation id; the host issues
test-presentation{n}when omitted.clientKeyThe client identity, for tests of several browser clients.
connectionKeyThe connection identity, for tests of a client disconnect.
Returns
The presentation; dispose it to stop answering, or unmount it.
Exceptions
InvalidOperationExceptionThe open or the registration was not answered
ok; the message names the reply.
MountPresentationAsync
public Task<RunicTestPresentation<TModel>> MountPresentationAsync(string? presentation = null, string? clientKey = null, string? connectionKey = null, CancellationToken cancellationToken = default) Opens a presentation that acts as a page's View, as RunicViewDriver.MountPresentation does, without blocking a thread.
Parameters
presentationThe presentation id; the host issues
test-presentation{n}when omitted.clientKeyThe client identity, for tests of several browser clients.
connectionKeyThe connection identity, for tests of a client disconnect.
cancellationTokenStops waiting for the replies.
Returns
The presentation; dispose it to stop answering, or unmount it.
Exceptions
InvalidOperationExceptionThe open or the registration was not answered
ok; the message names the reply.
NextPublicationAsync
public Task<RunicViewPublication> NextPublicationAsync(TimeSpan? timeout = null, CancellationToken cancellationToken = default) Waits for the next state or frame pushed to this route.
Parameters
timeoutReal time to wait; defaults to the host's publication timeout.
cancellationTokenStops waiting.
Exceptions
TimeoutExceptionNothing was pushed in time.
QueryRowsAsync
public Task<RunicQueryRows> QueryRowsAsync<TRow, TKey>(Expression<Func<TModel, RunicQueryCollection<TRow, TKey>>> collection, int start, int count, string? connectionKey = null, CancellationToken cancellationToken = default) where TKey : notnull Reads rows of a RunicQueryCollection as a page's queries.{name}.setRange(start, count) does (query-rows), on the test connection or on connectionKey, as another page.
Parameters
collectionThe query collection property, such as
vm => vm.Rows.startThe first row.
countThe number of rows, at most
RunicQueryCollectionOptions.MaximumRangeCount.connectionKeyThe connection, or
nullfor the test connection.cancellationTokenStops waiting for the reply.
Returns
The rows as the page receives them.
Exceptions
InvalidOperationExceptionThe route answered with a failure.
SelectRegionAsync
public Task<RunicCallReply<TModel>> SelectRegionAsync(Expression<Func<TModel, object?>> collection, string key, CancellationToken cancellationToken = default) Selects the region with key of a region collection, as the client's select{Name}(key) does (region-collections/1), and waits until the selection settled. The departure guards of the region left decide; RunicCallReply.RegionOutcome says how it ended.
Parameters
collectionThe region collection property, such as
vm => vm.Documents.keyA region's key, from
RunicViewState.Regions.cancellationTokenCancels the request, as a closed client connection does.
Set
public RunicCallReply<TModel> Set<TValue>(Expression<Func<TModel, TValue>> property, TValue value) Sends the generated setter's set request with the next edit number of the member, blocking the calling thread until the reply. The value is encoded as its wire type, as RunicViewDriver.SetAsync encodes it.
Remarks
Prefer RunicViewDriver.SetAsync in suites that run tests in parallel; see the class remarks.
SetAsync
public Task<RunicCallReply<TModel>> SetAsync<TValue>(Expression<Func<TModel, TValue>> property, TValue value, CancellationToken cancellationToken = default) Sends the generated setter's set request with the next edit number of the member, without blocking a thread. The value is encoded as its wire type: an Int64 or decimal as a string, an enum by name, null for a nullable value, and a DTO, list or union with the Bridge's JSON rules (see RunicViewDriver.ExecuteAsync). Use RunicViewDriver.SetJsonAsync for a value already encoded.
Parameters
propertyThe state property, such as
vm => vm.Title.valueThe value the page sets.
cancellationTokenStops waiting for the reply.
SetJson
public RunicCallReply<TModel> SetJson<TValue>(Expression<Func<TModel, TValue>> property, string wireJson) Sends a set request with a value already encoded as wire JSON, blocking the calling thread.
Remarks
Prefer RunicViewDriver.SetJsonAsync in suites that run tests in parallel; see the class remarks.
SetJsonAsync
public Task<RunicCallReply<TModel>> SetJsonAsync<TValue>(Expression<Func<TModel, TValue>> property, string wireJson, CancellationToken cancellationToken = default) Sends a set request with a value already encoded as wire JSON, without blocking a thread.
Parameters
propertyThe state property, such as
vm => vm.Title.wireJsonThe value as wire JSON.
cancellationTokenStops waiting for the reply.
SetQueryAsync
public Task<RunicCallReply<TModel>> SetQueryAsync<TRow, TKey>(Expression<Func<TModel, RunicQueryCollection<TRow, TKey>>> collection, RunicQuery query, CancellationToken cancellationToken = default) where TKey : notnull Changes the query of a query collection as a page's setQuery does (query-set).
Parameters
collectionThe query collection property, such as
vm => vm.Rows.queryThe query.
cancellationTokenStops waiting for the reply.
Returns
The reply, with the state after it.
Snapshot
public RunicViewState<TModel> Snapshot() Reads the current state with a snapshot request, blocking the calling thread until the reply.
Exceptions
InvalidOperationExceptionThe route answered with a failure, such as
released.
Remarks
Prefer RunicViewDriver.SnapshotAsync in suites that run tests in parallel; see the class remarks.
SnapshotAsync
public Task<RunicViewState<TModel>> SnapshotAsync(CancellationToken cancellationToken = default) Reads the current state with a snapshot request, without blocking a thread.
Parameters
cancellationTokenStops waiting for the reply.
Exceptions
InvalidOperationExceptionThe route answered with a failure, such as
released.
Start
public RunicTestOperation Start(Expression<Func<TModel, object?>> command, string? argumentJson = null, string? requestId = null) Starts an asynchronous command as a recoverable operation with a start request, blocking the calling thread until the admission.
Parameters
commandThe command property.
argumentJsonThe command input as wire JSON, for a command with an input.
requestIdThe operation id; the host issues
request{n}when omitted.
Remarks
Prefer RunicViewDriver.StartAsync in suites that run tests in parallel; see the class remarks.
StartAsync
public Task<RunicTestOperation> StartAsync(Expression<Func<TModel, object?>> command, string? argumentJson = null, string? requestId = null, CancellationToken cancellationToken = default) Starts an asynchronous command as a recoverable operation with a start request, and completes with the admission. Await RunicTestOperation.WaitAsync for the outcome.
Parameters
commandThe command property.
argumentJsonThe command input or key as wire JSON, for a command with an input.
requestIdThe operation id; the host issues
request{n}when omitted.cancellationTokenCancels the resolution, as a closed client connection does.
StartAsync
public Task<RunicTestOperation> StartAsync<TArgument>(Expression<Func<TModel, object?>> command, TArgument argument, string? requestId = null, CancellationToken cancellationToken = default) Starts an asynchronous command with an input as a recoverable operation with a start request, with the input encoded as RunicViewDriver.ExecuteAsync encodes it, and completes with the admission.
Parameters
commandThe command property.
argumentThe command input or key.
requestIdThe operation id; the host issues
request{n}when omitted.cancellationTokenCancels the resolution, as a closed client connection does.
TakePublications
public IReadOnlyList<RunicViewPublication> TakePublications() Returns and removes the states and frames pushed to this route so far.
Track
public RunicStateTracker<TModel> Track() Follows this route's state from a snapshot through its pushed states and frames, applying their changes as the client does and failing on a frame the client could not apply.
Remarks
Its first snapshot blocks the calling thread; prefer RunicViewDriver.TrackAsync in suites that run tests in parallel.
TrackAsync
public Task<RunicStateTracker<TModel>> TrackAsync(CancellationToken cancellationToken = default) Follows this route's state from a snapshot through its pushed states and frames, as RunicViewDriver.Track does, reading the first snapshot without blocking a thread.
Parameters
cancellationTokenStops waiting for the snapshot.
Unmount
public void Unmount(string presentation, string? clientKey = null, string? connectionKey = null) Closes a presentation, as a page that stops showing the View sends close.
Parameters
presentationThe id
RunicViewDriver.Mountreturned.clientKeyThe client identity the presentation was opened with.
connectionKeyThe connection identity the presentation was opened with.
Exceptions
InvalidOperationExceptionThe route did not close it, for example because another client opened it (
ignored) or the route was released (released). The message names the reply.
UnmountAsync
public Task UnmountAsync(string presentation, string? clientKey = null, string? connectionKey = null, CancellationToken cancellationToken = default) Closes a presentation, as a page that stops showing the View sends close, without blocking a thread.
Parameters
presentationThe id
RunicViewDriver.MountAsyncreturned.clientKeyThe client identity the presentation was opened with.
connectionKeyThe connection identity the presentation was opened with.
cancellationTokenStops waiting for the reply.
Exceptions
InvalidOperationExceptionThe route did not close it; the message names the reply.
View
public RunicViewDriver<TContent> View<TContent>(Expression<Func<TModel, object?>> property) where TContent : class Drives the content that a ViewModel content property presents now, reading it with a snapshot that blocks the calling thread.
Type parameters
TContentThe presented ViewModel type, checked against the reference's kind.
Remarks
Prefer RunicViewDriver.ViewAsync in suites that run tests in parallel; see the class remarks.
ViewAsync
public Task<RunicViewDriver<TContent>> ViewAsync<TContent>(Expression<Func<TModel, object?>> property, CancellationToken cancellationToken = default) where TContent : class Drives the content that a ViewModel content property presents now, without blocking a thread.
Type parameters
TContentThe presented ViewModel type, checked against the reference's kind.
Parameters
propertyThe content property, such as
vm => vm.Main.cancellationTokenStops waiting for the snapshot.
Views
public IReadOnlyList<RunicViewDriver<TContent>> Views<TContent>(Expression<Func<TModel, object?>> property) where TContent : class Drives each item that a ViewModel content collection presents now, blocking the calling thread.
Remarks
Prefer RunicViewDriver.ViewsAsync in suites that run tests in parallel; see the class remarks.
ViewsAsync
public Task<IReadOnlyList<RunicViewDriver<TContent>>> ViewsAsync<TContent>(Expression<Func<TModel, object?>> property, CancellationToken cancellationToken = default) where TContent : class Drives each item that a ViewModel content collection presents now, without blocking a thread.
Parameters
propertyThe content collection property, such as
vm => vm.Tabs.cancellationTokenStops waiting for the snapshot.
Write
public RunicFieldWriteReceipt<TModel> Write<TValue>(Expression<Func<TModel, TValue>> property, TValue value, long? expectedVersion = null) Writes a checked field, encoded as RunicViewDriver.Set encodes values, as the client's write{Property}(value, { requestId, baseline }) does, blocking the calling thread. The baseline is the current value and, unless given, its current version.
Remarks
Prefer RunicViewDriver.WriteAsync in suites that run tests in parallel; see the class remarks.
WriteAsync
public Task<RunicFieldWriteReceipt<TModel>> WriteAsync<TValue>(Expression<Func<TModel, TValue>> property, TValue value, long? expectedVersion = null, CancellationToken cancellationToken = default) Writes a checked field, encoded as RunicViewDriver.SetAsync encodes values, as the client's write{Property}(value, { requestId, baseline }) does, without blocking a thread. The baseline is the current value and, unless given, its current version.
Parameters
propertyThe checked state property.
valueThe value to write.
expectedVersionThe baseline version; by default the current one.
cancellationTokenStops waiting for the replies.
WritePath
public RunicFieldWriteReceipt<TModel> WritePath<TValue>(Expression<Func<TModel, object?>> member, IReadOnlyList<string> path, TValue value, long? expectedVersion = null) Writes a field path below a member (field-paths/1), as a generated field path descriptor such as InvoiceFields.lines.at(7).quantity does, blocking the calling thread. The path is in wire names: for a RunicCollectionAttribute collection, the row's key and then the cell, such as ["7", "quantity"]; for an object member, its members, such as ["street"]. The baseline is the path's value in the current state (null when the path reaches no value) and, unless given, the state's revision.
Remarks
Prefer RunicViewDriver.WritePathAsync in suites that run tests in parallel; see the class remarks.
WritePathAsync
public Task<RunicFieldWriteReceipt<TModel>> WritePathAsync<TValue>(Expression<Func<TModel, object?>> member, IReadOnlyList<string> path, TValue value, long? expectedVersion = null, CancellationToken cancellationToken = default) Writes a field path below a member (field-paths/1), as RunicViewDriver.WritePath does, without blocking a thread. A cell that changed after expectedVersion is a RunicFieldWriteReceiptKind.Conflict.
Parameters
memberThe object member or keyed collection, such as
vm => vm.Lines.pathThe path below it in wire names: a row key and the cell, or the object's members.
valueThe value to write.
expectedVersionThe baseline version; by default the state's revision.
cancellationTokenStops waiting for the replies.