Class HasAtLeastActiveTimerCountEventuallyAssertion
- Namespace
- TimeAssertions.TUnit
- Assembly
- TimeAssertions.TUnit.dll
TUnit assertion that polls an ObservableTimeProvider in real time until its active
timer count is at least an expected lower bound, or a timeout elapses. Generates the
HasAtLeastActiveTimerCountEventually(int, TimeSpan, ...) chain extension via TUnit's
TUnit.Assertions.Attributes.AssertionExtensionAttribute source generator.
[AssertionExtension("HasAtLeastActiveTimerCountEventually")]
public sealed class HasAtLeastActiveTimerCountEventuallyAssertion : Assertion<ObservableTimeProvider>, IAssertion
- Inheritance
-
Assertion<ObservableTimeProvider>HasAtLeastActiveTimerCountEventuallyAssertion
- Implements
-
IAssertion
- Inherited Members
-
Assertion<ObservableTimeProvider>.AssertAsync()Assertion<ObservableTimeProvider>.GetAwaiter()Assertion<ObservableTimeProvider>.AndAssertion<ObservableTimeProvider>.Or
Remarks
The asynchronous lower-bound sibling of the synchronous HasAtLeastActiveTimerCount(int) and
the exact-count HasActiveTimerCountEventuallyAssertion. Use it for an asynchronous
registration wait where more than one timer may register: a process that starts count or
more timers on real continuations passes as soon as the lower bound is reached, where the
exact-count form would flake once an additional timer registers and the synchronous
HasAtLeastActiveTimerCount would race a not-yet-registered timer.
The condition is checked once before the first delay, so an already-satisfied provider passes without waiting.
Cancellation. When the supplied CancellationToken is canceled the poll loop throws OperationCanceledException (a TaskCanceledException from the underlying Delay(TimeSpan, CancellationToken)); the test is recorded as canceled rather than failed.
Constructors
HasAtLeastActiveTimerCountEventuallyAssertion(AssertionContext<ObservableTimeProvider>, int, TimeSpan, TimeSpan?, CancellationToken)
Initializes the assertion with the minimum count, a polling timeout, poll interval, and cancellation token. Called by the TUnit source generator.
public HasAtLeastActiveTimerCountEventuallyAssertion(AssertionContext<ObservableTimeProvider> context, int count, TimeSpan timeout, TimeSpan? pollingInterval = null, CancellationToken cancellationToken = default)
Parameters
contextAssertionContext<ObservableTimeProvider>The assertion context supplied by TUnit.
countintThe minimum active-timer count to poll for. Must be non-negative.
timeoutTimeSpanThe maximum wall-clock time to poll for the active-timer count to reach at least
count. Must be non-negative.pollingIntervalTimeSpan?The delay between polls. When null a default of TimeAssertions.TUnit.PollingDefaults.PollingInterval is used. Must be positive when supplied.
cancellationTokenCancellationTokenA token that cancels the poll loop.
Exceptions
- ArgumentOutOfRangeException
countis negative,timeoutis negative, orpollingIntervalis supplied and not positive.
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()