TimeAssertions 0.5.0
Prefix Reserveddotnet add package TimeAssertions --version 0.5.0
NuGet\Install-Package TimeAssertions -Version 0.5.0
<PackageReference Include="TimeAssertions" Version="0.5.0" />
<PackageVersion Include="TimeAssertions" Version="0.5.0" />
<PackageReference Include="TimeAssertions" />
paket add TimeAssertions --version 0.5.0
#r "nuget: TimeAssertions, 0.5.0"
#:package TimeAssertions@0.5.0
#addin nuget:?package=TimeAssertions&version=0.5.0
#tool nuget:?package=TimeAssertions&version=0.5.0
TimeAssertions
Scope: Test projects only. Not intended for production code.
Framework-agnostic rendering helpers 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.
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.5.0
Minor release that adds the first rate-limit assertion (`WasInvokedAtMostOncePer`) to the package, fixes a latent cancellation-handling behaviour in `WithinTimeBudget` / `WithinTimeBudgetCapturing` (external `OperationCanceledException` was wrapped as an assertion failure rather than propagated), and bumps the TUnit dependency to 1.45.8.
### Added
- **`RateLimitAssertions.WasInvokedAtMostOncePer(this IReadOnlyList<DateTimeOffset>, TimeSpan)`** asserts that consecutive timestamps in a recorded invocation log maintain at least the specified minimum interval. The first violating pair fails the assertion with a message naming the violating index, the observed gap, and the required minimum. Empty and single-element sequences pass trivially; the boundary case `gap == interval` passes. Source-generated via `[GenerateAssertion]` so the chain surface is `Assert.That(timestamps).WasInvokedAtMostOncePer(TimeSpan.FromSeconds(30))`.
- **`TimeAssertions.TimeRenderingHelpers.FormatRateLimitViolation(IReadOnlyList<DateTimeOffset>, int, TimeSpan, TimeSpan)`** renders the multi-line failure message for `WasInvokedAtMostOncePer` violations, with a grep-friendly fixed-unit parenthetical `(gap=Xms, minimum=Yms)` analogous to `FormatBudgetOverrun`'s `(elapsed=, budget=, overrun=)` trailer.
### Changed
- **BREAKING:** **`WithinTimeBudgetAssertion<T>` and `WithinTimeBudgetCapturingAssertion<T>`** now propagate external `OperationCanceledException` instead of wrapping it as an assertion failure. When a parent `[Timeout]` fires or the test runner cancels, the wrapped operation's `OperationCanceledException` flows through the assertion via `ExceptionDispatchInfo.Capture(...).Throw()` so the test is recorded as cancelled, not failed. The capturing variant additionally skips invoking the capture callback on cancellation: a partial elapsed from a cancelled operation would mislead consumers about the operation's real cost. Non-`OperationCanceledException` source exceptions continue to surface as `AssertionResult.Failed` exactly as before. Consumer tests that asserted `Throws<AssertionException>` against a cancelled `WithinTimeBudget` chain must update to expect `Throws<OperationCanceledException>` (or rely on the test runner's native cancellation reporting).
- **TUnit dependency bumped `1.44.0` -> `1.45.8`** (and the external-consumer smoke-test pin). The 1.45 line adds `CancellationToken` overloads to upstream `Eventually` / `WaitsFor`; the cookbook section "Waiting for an asynchronous effect after `Advance(...)`" documents the CT-bearing variant. The packed `README.md` requirement line bumps to "TUnit 1.45.8 or later" accordingly.
- `README.md`: added a fourth Entry-points subgroup "Rate-limit assertions on invocation timestamps" (with matching TOC anchor), plus updates to Package layout, Namespaces, and Install/Requirements that reference `WasInvokedAtMostOncePer()`.
- `README.md`: added the cookbook section "Verifying a periodic-probe suppression window", pairing recorded log timestamps with `WasInvokedAtMostOncePer` for the ping-escalation pattern.
- `README.md`: reframed the "Deferred items" entry for `HasActiveTimers` as "tracked upstream", explicit about the no-reflection rule and the consumer-side `ObservableTimeProvider` bridge workaround.
- `README.md`: expanded the family roster to six packages, adding `JsonAssertions.TUnit` and `SseAssertions.TUnit` to the "Family compatibility" section, the "Pair with" section, and the "shared across" line in Contributing.
- `SECURITY.md`: updated the supported-versions table to reflect 0.5.x as the current line and 0.4.x as the previous-stable line.
- `SECURITY.md`: updated the supply-chain attestation table to name the actual action versions in use today (`actions/attest-build-provenance@v4.1.0` and `actions/attest@v4.1.0`).