Time system
Describes the possible expectations for the timers of a MockTimeSystem.
| Expectation | Negated | Summary |
|---|---|---|
Executed | .Never() | the timer callback was executed |
The samples on this page use the following timer:
using aweXpect.Chronology; // from the aweXpect.Chronology package
using static aweXpect.Expect;
MockTimeSystem timeSystem = new();
ITimerMock timer = (ITimerMock)timeSystem.Timer.New(_ => { }, null, TimeSpan.Zero, 10.Milliseconds());
Timer
A MockTimeSystem creates timers as ITimerMock. You can verify how often the timer callback was executed without
blocking the test thread:
await That(timer).Executed().AtLeast(3.Times()).Within(5.Seconds());
Executed() accepts a quantifier (AtLeast, AtMost, Exactly, Between, Never, Once; at least once by default). Without .Within(timeout), it checks ITimerMock.ExecutionCount once and does not wait. With .Within(timeout), it checks the count again until the quantifier is decided or the timeout expires, so an upper bound like .Never() or .AtMost(…) waits for the full timeout. Like for a condition, the count is checked every DefaultCheckInterval, or in the interval of .CheckEvery(interval):
await That(timer).Executed().AtLeast(3.Times()).Within(5.Seconds()).CheckEvery(10.Milliseconds());
A timeout of the evaluation (e.g. .WithTimeout(…)) that is not shorter than .Within(timeout) lets the last check decide; a cancellation before that leaves the expectation inconclusive.
For example, for a timer that never fires, That(timer).Executed().AtLeast(3.Times()).Within(100.Milliseconds())
fails with:
Expected that timer
has executed at least 3 times within 0:00.100,
but it was not executed