Table of Contents

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

context AssertionContext<ObservableTimeProvider>

The assertion context supplied by TUnit.

dueTime TimeSpan

The due time to wait for, compared exactly. Must be non-negative.

atLeast int

The minimum number of active timers carrying dueTime. Must be positive.

cancellationToken CancellationToken

The only bound of the wait, typically the test's token.

Exceptions

ArgumentOutOfRangeException

dueTime is negative, or atLeast is 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

context AssertionContext<ObservableTimeProvider>

The assertion context supplied by TUnit.

dueTime TimeSpan

The due time to wait for, compared exactly. Must be non-negative.

atLeast int

The minimum number of active timers carrying dueTime. Must be positive.

timeout TimeSpan

The longest real time to wait. Must be non-negative and at most about 49.7 days (uint.MaxValue - 1 milliseconds).

cancellationToken CancellationToken

A token that cancels the wait.

Exceptions

ArgumentOutOfRangeException

dueTime or timeout is negative, timeout is longer than about 49.7 days, or atLeast is 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

context AssertionContext<ObservableTimeProvider>

The assertion context supplied by TUnit.

dueTime TimeSpan

The due time to wait for, compared exactly. Must be non-negative.

cancellationToken CancellationToken

The only bound of the wait, typically the test's token.

Exceptions

ArgumentOutOfRangeException

dueTime is 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

context AssertionContext<ObservableTimeProvider>

The assertion context supplied by TUnit.

dueTime TimeSpan

The due time to wait for, compared exactly. Must be non-negative.

timeout TimeSpan

The longest real time to wait. Must be non-negative and at most about 49.7 days (uint.MaxValue - 1 milliseconds).

cancellationToken CancellationToken

A token that cancels the wait.

Exceptions

ArgumentOutOfRangeException

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

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