public sealed class RunicPathWatchTester : 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
debounceThe 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.
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
quietThe real time to wait; null waits 300 ms.
cancellationTokenStops waiting; the changes reported meanwhile stay queued.
Exceptions
OperationCanceledExceptioncancellationTokenwas 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
timeoutHow long to wait in real time; null waits 10 seconds.
cancellationTokenStops waiting.
Exceptions
TimeoutExceptionNo change was reported in time.
OperationCanceledExceptioncancellationTokenwas 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
pathThe path a target was created with, compared as a full path.
timeoutHow long to wait in real time; null waits 10 seconds.
cancellationTokenStops waiting for the change.
Exceptions
InvalidOperationExceptionNo active watcher has a target with this path.
TimeoutExceptionThe change was not reported in time.
OperationCanceledExceptioncancellationTokenwas cancelled.