TimeAssertions 0.9.0
Prefix Reserveddotnet add package TimeAssertions --version 0.9.0
NuGet\Install-Package TimeAssertions -Version 0.9.0
<PackageReference Include="TimeAssertions" Version="0.9.0" />
<PackageVersion Include="TimeAssertions" Version="0.9.0" />
<PackageReference Include="TimeAssertions" />
paket add TimeAssertions --version 0.9.0
#r "nuget: TimeAssertions, 0.9.0"
#:package TimeAssertions@0.9.0
#addin nuget:?package=TimeAssertions&version=0.9.0
#tool nuget:?package=TimeAssertions&version=0.9.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) and counts their callback fires (TimerFireCount, cumulative and surviving disposal) so adapter packages can assert on timer-disposal, leak, pending-due-time, and fire-count behavior without advancing the clock. Reflection-free, AOT-compatible, thread-safe.ActiveTimerInfo: a readonly record struct describing a tracked timer's schedule (DueTime,Period) and its fire count (TimesFired), 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.9.0
Minor release. Adds fire observation to `ObservableTimeProvider`: a count of how many times timer callbacks ran, next to the existing leak and pending-due assertions. Purely additive. Also corrects stale guidance in the docs.
### Added
- **`Assert.That(time).HasTimerFiredCount(int expected)`**, **`HasNoTimerFired()`**, and **`HasTimerFiredAtLeast(int count)`** assert how many times timer callbacks fired across every timer the provider created. `ObservableTimeProvider` now wraps each timer callback to count its fires. The count is cumulative and is not reset on disposal. With a `FakeTimeProvider`, a fire is counted each time test code advances fake time past a due or period boundary, which keeps the count deterministic. `ObservableTimeProvider.TimerFireCount` (cumulative) and `ActiveTimerInfo.TimesFired` (per timer) expose the same data on the framework-agnostic core.
- `ObservableTimeProvider.CreateTimer` now validates that the callback is non-null up front (`ArgumentNullException`), matching the rest of the surface, instead of deferring to the inner provider.
### Fixed
- Once a periodic timer fires, `NextTimerDueTime` (and the `HasNextTimerDueApproximately` / `HasPendingTimerDueWithin` assertions) now report the timer's period, since that is when the next callback is due. A fired one-shot timer is disabled and drops out of the pending-due calculation. Previously the due time stayed frozen at its creation value until an explicit `Change`.
- Corrected stale documentation that claimed the package "deliberately does not ship its own polling assertion": it has shipped `HasNoActiveTimersEventually` and its count-targeted siblings since `0.7.0`/`0.8.0`. The README and the `ActiveTimerAssertions` XML docs now point to those overloads for the asynchronous disposal race, reserving generic `Eventually` for arbitrary conditions.
### Changed
- Bumped `PackageValidationBaselineVersion` from `0.7.0` to `0.8.1` on both packages so ApiCompat strict-mode validates `0.9.0` against the most recently published baseline. The new members are recorded as additive differences in `CompatibilitySuppressions.xml`.