RunicPathWatchTester class

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

public sealed class RunicPathWatchTester : IDisposable

Inherits or implements IDisposable.

Drives the RunicPathWatchers started with its RunicPathWatchTester.Options: their debounce and polling run on a FakeTimeProvider, a test awaits the next reported change, and a test can report a change of a path it cannot modify, such as /run/current-system.

Remarks

Pass RunicPathWatchTester.Options to the ViewModel that starts the watcher, typically through its constructor or dependency injection. One tester can serve several watchers; their changes are returned in the order their callbacks ran. Dispose the tester at the end of the test to stop the watchers its options started.

Constructors

RunicPathWatchTester

public RunicPathWatchTester(TimeSpan? debounce = null)

Creates a tester with a new FakeTimeProvider.

Parameters

debounce

The watchers' debounce; null keeps the default of RunicPathWatcherOptions.

Properties

ActiveWatchers

public int ActiveWatchers { get; }

Gets the number of watchers started with RunicPathWatchTester.Options and not yet disposed.

Options

public RunicPathWatcherOptions Options { get; }

Gets the options to start watchers with.

Time

public FakeTimeProvider Time { get; }

Gets the clock of the watchers' debounce and polling. Time passes only when the test advances it.

Methods

Dispose

public void Dispose()

Stops the active watchers started with RunicPathWatchTester.Options, drops the changes not returned yet and detaches from the options: a watcher started with them later runs on RunicPathWatchTester.Time but is not tracked.

Remarks

Disposing a watcher again, as its ViewModel does, has no effect.

DrainAsync

public Task<IReadOnlyList<RunicPathChange>> DrainAsync(TimeSpan? quiet = null, CancellationToken cancellationToken = default)

Waits until no change is reported for quiet of real time while RunicPathWatchTester.Time advances, and returns the changes reported meanwhile; use it to assert that nothing (more) is reported.

Parameters

quiet

The real time to wait; null waits 300 ms.

cancellationToken

Stops waiting; the changes reported meanwhile stay queued.

Exceptions

OperationCanceledException

cancellationToken was cancelled.

NextChangeAsync

public Task<RunicPathChange> NextChangeAsync(TimeSpan? timeout = null, CancellationToken cancellationToken = default)

Returns the next change not returned yet, after its callback ran in the model context. While none is reported, advances RunicPathWatchTester.Time by one debounce interval at a time, so file-system events that arrive are delivered.

Parameters

timeout

How long to wait in real time; null waits 10 seconds.

cancellationToken

Stops waiting.

Exceptions

TimeoutException

No change was reported in time.

OperationCanceledException

cancellationToken was cancelled.

TriggerAsync

public Task<RunicPathChange> TriggerAsync(string path, TimeSpan? timeout = null, CancellationToken cancellationToken = default)

Reports a change of path to every active watcher that watches it, as if the platform had reported an event, and returns RunicPathWatchTester.NextChangeAsync: the triggered change, unless an earlier one was not returned yet. The targets need not have changed.

Parameters

path

The path a target was created with, compared as a full path.

timeout

How long to wait in real time; null waits 10 seconds.

cancellationToken

Stops waiting for the change.

Exceptions

InvalidOperationException

No active watcher has a target with this path.

TimeoutException

The change was not reported in time.

OperationCanceledException

cancellationToken was cancelled.