TimeAssertions 0.7.0
Prefix ReservedSee the version list below for details.
dotnet add package TimeAssertions --version 0.7.0
NuGet\Install-Package TimeAssertions -Version 0.7.0
<PackageReference Include="TimeAssertions" Version="0.7.0" />
<PackageVersion Include="TimeAssertions" Version="0.7.0" />
<PackageReference Include="TimeAssertions" />
paket add TimeAssertions --version 0.7.0
#r "nuget: TimeAssertions, 0.7.0"
#:package TimeAssertions@0.7.0
#addin nuget:?package=TimeAssertions&version=0.7.0
#tool nuget:?package=TimeAssertions&version=0.7.0
TimeAssertions
Scope: Test projects only. Not intended for production code.
Framework-agnostic rendering helpers and test infrastructure for the TimeAssertions package family. The actual FakeTimeProvider and TimeProvider-aware DateTimeOffset assertion APIs ship in the framework-specific adapter packages (currently TimeAssertions.TUnit).
Most users want
TimeAssertions.TUnit, not this package directly. This package only ships the shared rendering helpers; the adapter package adds the assertion entry points your test framework expects.
What's in this package
TimeRenderingHelpers: formatting utilities for elapsed durations and time budgets in failure-message context. Pure, allocation-conscious.ObservableTimeProvider: aTimeProviderdecorator that tracks the timers created against it (ActiveTimerCount,ActiveTimers,NextTimerDueTime) so adapter packages can assert on timer-disposal, leak, and pending-due-time behaviour without advancing the clock. Reflection-free, AOT-compatible, thread-safe.ActiveTimerInfo: a readonly record struct describing a tracked timer's schedule (DueTime,Period), returned byObservableTimeProvider.ActiveTimers.TimelineRenderer/TimelineEvent: render a sequence of timestamped events as deterministic, snapshot-friendly text.
Test-framework adapters
| Package | Test framework | Status |
|---|---|---|
TimeAssertions.TUnit |
TUnit | Available now |
TimeAssertions.NUnit |
NUnit | Possible if there is demand |
TimeAssertions.xUnit |
xUnit | Possible if there is demand |
TimeAssertions.MSTest |
MSTest | Possible if there is demand |
If you'd find a non-TUnit adapter useful, open a feature request: adapters are not built proactively.
Installation
dotnet add package TimeAssertions.TUnit
TimeAssertions comes transitively. You don't need to install it directly unless you're building your own adapter package.
Stability
The public surfaces above are semver-bound. Breaking changes require a major version bump. The exact text format of TimeRenderingHelpers output is not stable and may gain extra detail or change formatting in any release.
License
MIT. Copyright (c) 2026 John Verheij.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on TimeAssertions:
| Package | Downloads |
|---|---|
|
TimeAssertions.TUnit
TUnit-native fluent time-assertion DSL on FakeTimeProvider plus assertion-level timing budget chain extensions via [AssertionExtension]. Provides Assert.That(fakeTime).HasAdvancedExactly(...) / HasAdvancedApproximately(...) / HasUtcNow(...) / HasUtcNowApproximately(...), Assert.That(timestamp).IsRecent(...) / IsBeforeNow(...) / IsAfterNow(...), and the cross-cutting Assert.That(value).IsX().And.WithinTimeBudget(TimeSpan) / WithinTimeBudgetCapturing(TimeSpan, Action<TimeSpan>) on any TUnit assertion chain. Composes with sibling assertion packages without a binary dependency. AOT-compatible, trimmable, no reflection. |
GitHub repositories
This package is not used by any popular GitHub repositories.
View the rendered release notes: https://github.com/JohnVerheij/TimeAssertions.TUnit/releases/tag/v0.7.0
Minor release. Adds real-time "eventually" active-timer assertions for the asynchronous timer-disposal race a synchronous leak check cannot see, plus synchronous positive-count assertions to express a lower bound on the active set.
### Added
- **`Assert.That(provider).HasNoActiveTimersEventually(TimeSpan timeout, TimeSpan? pollingInterval = null, CancellationToken ct = default)`** (TUnit adapter) polls the live `ActiveTimerCount` on the real wall clock until it reaches zero, or the timeout elapses. A `BackgroundService` / `IHostedService` commonly disposes its timer on a continuation that runs after `StopAsync` returns to the caller, so a synchronous `HasNoActiveTimers()` check just after stop can still see the timer; the poll gives that continuation time to run. The condition is checked once before the first delay, so an already-clean provider passes without waiting. On timeout the failure names each surviving timer by its schedule with a grep-friendly `(count=N)` trailer.
- **`Assert.That(provider).HasActiveTimerCountEventually(int count, TimeSpan timeout, TimeSpan? pollingInterval = null, CancellationToken ct = default)`** (TUnit adapter) is the count-targeted sibling: polls until `ActiveTimerCount` equals `count`, for an active set that settles to a steady state on a background continuation. On timeout it renders the expected and actual counts with an `(expected=N, actual=M)` trailer plus the active timers' schedules.
- **`Assert.That(provider).HasActiveTimers()`** (TUnit adapter) passes when at least one timer is active: the positive-presence counterpart of `HasNoActiveTimers()` for the registration half of a leak test, without pinning the exact count. Source-generated via `[GenerateAssertion]`.
- **`Assert.That(provider).HasAtLeastActiveTimerCount(int count)`** (TUnit adapter) passes when the active count is at least `count`, for when a lower bound rather than an exact count is the natural expectation. On a shortfall it renders the required minimum and the actual count with a `(minimum=N, actual=M)` trailer plus the active timers' schedules. Source-generated via `[GenerateAssertion]`.
- **Positional-`CancellationToken` overloads** of `HasNoActiveTimersEventually` and `HasActiveTimerCountEventually` (TUnit adapter) let a token follow the timeout positionally while keeping the default poll interval, so the common case reads as `(timeout, ct)` / `(count, timeout, ct)` instead of the named `ct:` form. They forward to the canonical chain with `pollingInterval: null`; the token parameter has no default, so a bare `(timeout)` call stays unambiguous, matching TUnit's `WaitsFor` convention.
- **`TimeAssertions.TimeRenderingHelpers.FormatActiveTimerSurvivors(...)` and `FormatActiveTimerAtLeastShortfall(...)`** (framework-agnostic core) render the survivor list for the eventually-timeout messages and the at-least shortfall message, ordering survivors deterministically (by due time, then period) so the messages are snapshot-stable.
The poll uses a real `Task.Delay` loop against a wall-clock deadline rather than a fake-time advance: hosted-service timer disposal happens on a real asynchronous continuation, which a fake clock cannot drive. The default poll interval is 10 ms; supply your own via the optional `pollingInterval`. A canceled `CancellationToken` throws `OperationCanceledException` so the test is recorded as canceled rather than failed.