Table of Contents

Class HasAtMostActiveTimerCountEventuallyAssertion

Namespace
TimeAssertions.TUnit
Assembly
TimeAssertions.TUnit.dll

TUnit assertion that polls an ObservableTimeProvider in real time until its active timer count is at most an expected upper bound, or a timeout elapses. Generates the HasAtMostActiveTimerCountEventually(int, TimeSpan, ...) chain extension via TUnit's TUnit.Assertions.Attributes.AssertionExtensionAttribute source generator.

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

Remarks

The asynchronous upper-bound sibling of HasAtLeastActiveTimerCountEventuallyAssertion. Use it when timers dispose on real continuations and the expectation is that the active set settles to no more than count shortly after the observed call returns, without pinning the exact survivor count. HasAtMostActiveTimerCountEventually(0) is equivalent to HasNoActiveTimersEventually.

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

HasAtMostActiveTimerCountEventuallyAssertion(AssertionContext<ObservableTimeProvider>, int, TimeSpan, TimeSpan?, CancellationToken)

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

public HasAtMostActiveTimerCountEventuallyAssertion(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 maximum 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 fall to at most 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