Table of Contents

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
HasAtLeastActiveTimerCountEventuallyAssertion
Implements
IAssertion
Inherited Members
Assertion<ObservableTimeProvider>.AssertAsync()
Assertion<ObservableTimeProvider>.GetAwaiter()
Assertion<ObservableTimeProvider>.And
Assertion<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

context AssertionContext<ObservableTimeProvider>

The assertion context supplied by TUnit.

count int

The minimum active-timer count to poll for. Must be non-negative.

timeout TimeSpan

The maximum wall-clock time to poll for the active-timer count to reach at least count. Must be non-negative.

pollingInterval TimeSpan?

The delay between polls. When null a default of TimeAssertions.TUnit.PollingDefaults.PollingInterval is used. Must be positive when supplied.

cancellationToken CancellationToken

A token that cancels the poll loop.

Exceptions

ArgumentOutOfRangeException

count is negative, timeout is negative, or pollingInterval is 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

metadata EvaluationMetadata<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()

Returns

string