Class HasActiveTimerCountEventuallyAssertion
- Namespace
- TimeAssertions.TUnit
- Assembly
- TimeAssertions.TUnit.dll
TUnit assertion that polls an ObservableTimeProvider in real time until its active
timer count equals an expected value, or a timeout elapses. Generates the
HasActiveTimerCountEventually(int, TimeSpan, ...) chain extension via TUnit's
TUnit.Assertions.Attributes.AssertionExtensionAttribute source generator.
[AssertionExtension("HasActiveTimerCountEventually")]
public sealed class HasActiveTimerCountEventuallyAssertion : Assertion<ObservableTimeProvider>, IAssertion
- Inheritance
-
Assertion<ObservableTimeProvider>HasActiveTimerCountEventuallyAssertion
- Implements
-
IAssertion
- Inherited Members
-
Assertion<ObservableTimeProvider>.AssertAsync()Assertion<ObservableTimeProvider>.GetAwaiter()Assertion<ObservableTimeProvider>.AndAssertion<ObservableTimeProvider>.Or
Remarks
The count-targeted sibling of HasNoActiveTimersEventuallyAssertion. Use it when a
timer is expected to be created (or disposed down to a steady-state count) on a real asynchronous
continuation rather than synchronously: the active set settles to count shortly after the
observed call returns. Polls the live ActiveTimerCount
against a wall-clock deadline; the condition is checked once before the first delay.
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
HasActiveTimerCountEventuallyAssertion(AssertionContext<ObservableTimeProvider>, int, TimeSpan, TimeSpan?, CancellationToken)
Initializes the assertion with the expected count, a polling timeout, poll interval, and cancellation token. Called by the TUnit source generator.
public HasActiveTimerCountEventuallyAssertion(AssertionContext<ObservableTimeProvider> context, int count, TimeSpan timeout, TimeSpan? pollingInterval = null, CancellationToken cancellationToken = default)
Parameters
contextAssertionContext<ObservableTimeProvider>The assertion context supplied by TUnit.
countintThe active-timer count to poll for. Must be non-negative.
timeoutTimeSpanThe maximum wall-clock time to poll for the active-timer count to reach
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()