public sealed class RunicTestPresentation<TModel> : IDisposable where TModel : class 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
TModelThe 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
TInputThe interaction's input type.
TOutputThe interaction's output type.
Parameters
interactionThe interaction property, such as
vm => vm.ConfirmDiscard.answerAnswers each request; an exception answers
failed.
Returns
This presentation.
Exceptions
InvalidOperationExceptionThe 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
TInputThe interaction's input type.
TOutputThe interaction's output type.
Parameters
interactionThe interaction property, such as
vm => vm.ConfirmDiscard.answerAnswers each request; an exception answers
failed.
Returns
This presentation.
Exceptions
InvalidOperationExceptionThe 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
TInputThe interaction's input type.
TOutputThe interaction's output type.
Parameters
interactionThe interaction or
ViewQuestionproperty.answerAnswers each request; an exception answers
failed, a cancellationcancelled.cancellationTokenStops waiting for the registration's reply.
Returns
This presentation, once the window registered the handler.
Exceptions
InvalidOperationExceptionThe 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
timeoutReal time to wait; five seconds by default.
cancellationTokenStops waiting.
Exceptions
TimeoutExceptionNo 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
requestOnly the requests of this
ViewRequestproperty, such asvm => 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
InvalidOperationExceptionThe 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
cancellationTokenStops waiting for the reply.
Exceptions
InvalidOperationExceptionThe route did not close it; the message names the reply.