Table of Contents

Class HasActiveTimersEventuallyAssertion

Namespace
TimeAssertions.TUnit
Assembly
TimeAssertions.TUnit.dll

TUnit assertion that polls an ObservableTimeProvider in real time until at least one timer is active, or a timeout elapses. Generates the HasActiveTimersEventually(TimeSpan, ...) chain extension via TUnit's TUnit.Assertions.Attributes.AssertionExtensionAttribute source generator.

[AssertionExtension("HasActiveTimersEventually")]
public sealed class HasActiveTimersEventuallyAssertion : Assertion<ObservableTimeProvider>, IAssertion
Inheritance
HasActiveTimersEventuallyAssertion
Implements
IAssertion
Inherited Members
Assertion<ObservableTimeProvider>.AssertAsync()
Assertion<ObservableTimeProvider>.GetAwaiter()
Assertion<ObservableTimeProvider>.And
Assertion<ObservableTimeProvider>.Or

Remarks

The asynchronous counterpart of the synchronous HasActiveTimers() and a named shorthand for HasAtLeastActiveTimerCountEventually(1, ...): the natural shape for an asynchronous registration wait that only needs "a timer eventually started" without pinning the exact count. Use it when a loop registers its timer on a real continuation, so a synchronous HasActiveTimers() would race the not-yet-registered timer.

The condition is checked once before the first delay, so a provider that already has a timer 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

HasActiveTimersEventuallyAssertion(AssertionContext<ObservableTimeProvider>, TimeSpan, TimeSpan?, CancellationToken)

Initializes the assertion with a polling timeout, poll interval, and cancellation token. Called by the TUnit source generator.

public HasActiveTimersEventuallyAssertion(AssertionContext<ObservableTimeProvider> context, TimeSpan timeout, TimeSpan? pollingInterval = null, CancellationToken cancellationToken = default)

Parameters

context AssertionContext<ObservableTimeProvider>

The assertion context supplied by TUnit.

timeout TimeSpan

The maximum wall-clock time to poll for at least one timer to become active. 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

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