Class HasTimerScheduledEventuallyAssertion
- Namespace
- TimeAssertions.TUnit
- Assembly
- TimeAssertions.TUnit.dll
TUnit assertion that waits until enough active timers on an ObservableTimeProvider carry a due
time: by default one, or at least atLeast. Generates the HasTimerScheduledEventually chain
extensions via TUnit's TUnit.Assertions.Attributes.AssertionExtensionAttribute source generator.
[AssertionExtension("HasTimerScheduledEventually")]
public sealed class HasTimerScheduledEventuallyAssertion : Assertion<ObservableTimeProvider>, IAssertion
- Inheritance
-
Assertion<ObservableTimeProvider>HasTimerScheduledEventuallyAssertion
- Implements
-
IAssertion
- Inherited Members
-
Assertion<ObservableTimeProvider>.AssertAsync()Assertion<ObservableTimeProvider>.GetAwaiter()Assertion<ObservableTimeProvider>.AndAssertion<ObservableTimeProvider>.Or
Remarks
Which timers count. A timer counts while it carries the due time exactly, as the code under test passed it, so the assertion tells several loops apart: "both ping loops armed their 30 s delay" while a start-up gate and an hourly refresh are pending too. See HasTimerScheduled(ObservableTimeProvider, TimeSpan, int).
Event-driven. The condition is checked once, then again each time a timer is created, re-scheduled, fired, or disposed through the provider (WaitUntilAsync(Func<ObservableTimeProvider, bool>, CancellationToken)), never on a polling loop.
Bounds. The timeout forms fail when timeout of real time passes first; the timeout is
a bound, not a poll interval. The token-only forms are bounded by the token only, typically the test's own.
When the token is canceled the wait throws OperationCanceledException.
_ = service.StartAsync(ct);
await Assert.That(time).HasTimerScheduledEventually(TimeSpan.FromSeconds(30), atLeast: 2, ct);
Constructors
HasTimerScheduledEventuallyAssertion(AssertionContext<ObservableTimeProvider>, TimeSpan, int, CancellationToken)
Initializes the assertion for at least atLeast timers, bounded by
cancellationToken only. Called by the TUnit source generator.
public HasTimerScheduledEventuallyAssertion(AssertionContext<ObservableTimeProvider> context, TimeSpan dueTime, int atLeast, CancellationToken cancellationToken)
Parameters
contextAssertionContext<ObservableTimeProvider>The assertion context supplied by TUnit.
dueTimeTimeSpanThe due time to wait for, compared exactly. Must be non-negative.
atLeastintThe minimum number of active timers carrying
dueTime. Must be positive.cancellationTokenCancellationTokenThe only bound of the wait, typically the test's token.
Exceptions
- ArgumentOutOfRangeException
dueTimeis negative, oratLeastis not positive.
HasTimerScheduledEventuallyAssertion(AssertionContext<ObservableTimeProvider>, TimeSpan, int, TimeSpan, CancellationToken)
Initializes the assertion for at least atLeast timers, with a real-time bound
and a cancellation token. Called by the TUnit source generator.
public HasTimerScheduledEventuallyAssertion(AssertionContext<ObservableTimeProvider> context, TimeSpan dueTime, int atLeast, TimeSpan timeout, CancellationToken cancellationToken = default)
Parameters
contextAssertionContext<ObservableTimeProvider>The assertion context supplied by TUnit.
dueTimeTimeSpanThe due time to wait for, compared exactly. Must be non-negative.
atLeastintThe minimum number of active timers carrying
dueTime. Must be positive.timeoutTimeSpanThe longest real time to wait. Must be non-negative and at most about 49.7 days (
uint.MaxValue - 1milliseconds).cancellationTokenCancellationTokenA token that cancels the wait.
Exceptions
- ArgumentOutOfRangeException
dueTimeortimeoutis negative,timeoutis longer than about 49.7 days, oratLeastis not positive.
HasTimerScheduledEventuallyAssertion(AssertionContext<ObservableTimeProvider>, TimeSpan, CancellationToken)
Initializes the assertion for one timer, bounded by cancellationToken only.
Called by the TUnit source generator.
public HasTimerScheduledEventuallyAssertion(AssertionContext<ObservableTimeProvider> context, TimeSpan dueTime, CancellationToken cancellationToken)
Parameters
contextAssertionContext<ObservableTimeProvider>The assertion context supplied by TUnit.
dueTimeTimeSpanThe due time to wait for, compared exactly. Must be non-negative.
cancellationTokenCancellationTokenThe only bound of the wait, typically the test's token.
Exceptions
- ArgumentOutOfRangeException
dueTimeis negative.
HasTimerScheduledEventuallyAssertion(AssertionContext<ObservableTimeProvider>, TimeSpan, TimeSpan, CancellationToken)
Initializes the assertion for one timer, with a real-time bound and a cancellation token. Called by the TUnit source generator.
public HasTimerScheduledEventuallyAssertion(AssertionContext<ObservableTimeProvider> context, TimeSpan dueTime, TimeSpan timeout, CancellationToken cancellationToken = default)
Parameters
contextAssertionContext<ObservableTimeProvider>The assertion context supplied by TUnit.
dueTimeTimeSpanThe due time to wait for, compared exactly. Must be non-negative.
timeoutTimeSpanThe longest real time to wait. Must be non-negative and at most about 49.7 days (
uint.MaxValue - 1milliseconds).cancellationTokenCancellationTokenA token that cancels the wait.
Exceptions
- ArgumentOutOfRangeException
dueTimeortimeoutis negative, ortimeoutis longer than about 49.7 days.
Methods
CheckAsync(EvaluationMetadata<ObservableTimeProvider>)
Implements the specific check logic for this assertion. Called after the context has been evaluated. Override this method if your assertion uses the default AssertAsync() flow. If you override AssertAsync() with custom logic (like AndAssertion/OrAssertion), you don't need to implement this.
protected override Task<AssertionResult> CheckAsync(EvaluationMetadata<ObservableTimeProvider> metadata)
Parameters
metadataEvaluationMetadata<ObservableTimeProvider>Metadata about the evaluation including value, exception, and timing information
Returns
- Task<AssertionResult>
The result of the assertion check
GetExpectation()
Gets a human-readable description of what this assertion expects. Used in error messages.
protected override string GetExpectation()