RunicTestPresentation<TModel> class

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

public sealed class RunicTestPresentation<TModel> : IDisposable where TModel : class

Inherits or implements IDisposable.

A presentation of a route that a test opened as a page does, which answers the ViewModel's interactions and questions with the handlers the test registers and receives its view requests. Create it with RunicViewDriver.MountPresentation.

Type parameters

TModel

The ViewModel of the route.

Remarks

It registers every ViewRequest of TModel when it opens, so the ViewModel's requests reach it by their ViewRequestDelivery; a presentation that RunicViewDriver.Mount opened registers none. Each RunicTestPresentation.Handle registers one more interaction handler, as the generated client's interactions.<name>.handle does.

var page = await editor.MountPresentationAsync();
page.Handle<DiscardRequest, bool>(vm => vm.ConfirmDiscard, request => true);
(await editor.ExecuteAsync(vm => vm.DiscardCommand)).ThrowIfFailed();
var focus = Assert.Single(page.TakeViewRequests(vm => vm.Focus));

Properties

ClientKey

public string? ClientKey { get; }

The client identity the presentation was opened with, or null for the default.

ConnectionKey

public string? ConnectionKey { get; }

The connection identity the presentation was opened with, or null for the default.

Id

public string Id { get; }

The presentation id.

Route

public string Route { get; }

The route of the presentation.

Methods

Dispose

public void Dispose()

Stops answering interactions and taking view requests; the presentation stays open.

Handle

public RunicTestPresentation<TModel> Handle<TInput, TOutput>(Expression<Func<TModel, object?>> interaction, Func<TInput, TOutput> answer)

Answers a ViewModel's interaction, such as a ReactiveUI Interaction<TInput, TOutput>, with answer, as a page's handler does, from now on; it replaces an earlier handler of the member. Blocks the calling thread until the window registered it.

Type parameters

TInput

The interaction's input type.

TOutput

The interaction's output type.

Parameters

interaction

The interaction property, such as vm => vm.ConfirmDiscard.

answer

Answers each request; an exception answers failed.

Returns

This presentation.

Exceptions

InvalidOperationException

The window did not register the handler; the message names its reply.

Handle

public RunicTestPresentation<TModel> Handle<TInput, TOutput>(Expression<Func<TModel, ViewQuestion<TInput, TOutput>>> question, Func<TInput, TOutput> answer)

Answers a ViewQuestion with answer, as a page's handler does.

Type parameters

TInput

The interaction's input type.

TOutput

The interaction's output type.

Parameters

interaction

The interaction property, such as vm => vm.ConfirmDiscard.

answer

Answers each request; an exception answers failed.

Returns

This presentation.

Exceptions

InvalidOperationException

The window did not register the handler; the message names its reply.

Documentation from RunicTestPresentation.Handle.

HandleAsync

public Task<RunicTestPresentation<TModel>> HandleAsync<TInput, TOutput>(Expression<Func<TModel, object?>> interaction, Func<TInput, CancellationToken, ValueTask<TOutput>> answer, CancellationToken cancellationToken = default)

Answers a ViewModel's interaction with an asynchronous handler, which is cancelled when .NET cancels the request, without blocking a thread.

Type parameters

TInput

The interaction's input type.

TOutput

The interaction's output type.

Parameters

interaction

The interaction or ViewQuestion property.

answer

Answers each request; an exception answers failed, a cancellation cancelled.

cancellationToken

Stops waiting for the registration's reply.

Returns

This presentation, once the window registered the handler.

Exceptions

InvalidOperationException

The window did not register the handler; the message names its reply.

NextViewRequestAsync

public Task<RunicViewRequest> NextViewRequestAsync(TimeSpan? timeout = null, CancellationToken cancellationToken = default)

Waits for the next view request this presentation receives, and removes it.

Parameters

timeout

Real time to wait; five seconds by default.

cancellationToken

Stops waiting.

Exceptions

TimeoutException

No view request arrived in time.

TakeViewRequests

public IReadOnlyList<RunicViewRequest> TakeViewRequests(Expression<Func<TModel, object?>>? request = null)

Returns and removes the view requests this presentation received, in order.

Parameters

request

Only the requests of this ViewRequest property, such as vm => vm.Focus; by default all.

Unmount

public void Unmount()

Closes the presentation, as a page that stops showing the View sends close, and stops answering.

Exceptions

InvalidOperationException

The route did not close it; the message names the reply.

UnmountAsync

public Task UnmountAsync(CancellationToken cancellationToken = default)

Closes the presentation without blocking a thread, and stops answering.

Parameters

cancellationToken

Stops waiting for the reply.

Exceptions

InvalidOperationException

The route did not close it; the message names the reply.