Enhanced.Testing.Component.Time 1.4.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Enhanced.Testing.Component.Time --version 1.4.0
                    
NuGet\Install-Package Enhanced.Testing.Component.Time -Version 1.4.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Enhanced.Testing.Component.Time" Version="1.4.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Enhanced.Testing.Component.Time" Version="1.4.0" />
                    
Directory.Packages.props
<PackageReference Include="Enhanced.Testing.Component.Time" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Enhanced.Testing.Component.Time --version 1.4.0
                    
#r "nuget: Enhanced.Testing.Component.Time, 1.4.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Enhanced.Testing.Component.Time@1.4.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Enhanced.Testing.Component.Time&version=1.4.0
                    
Install as a Cake Addin
#tool nuget:?package=Enhanced.Testing.Component.Time&version=1.4.0
                    
Install as a Cake Tool

Enhanced.Testing.Component.Time

NuGet

A time harness for Enhanced.Testing.Component: replaces the application's TimeProvider with a FakeTimeProvider the test controls, so delays, timeouts, retries and timers complete as soon as the test moves the clock instead of waiting for real time. No Docker needed.

dotnet add package Enhanced.Testing.Component.Time

Usage

var time = new TimeProviderHarness(new DateTimeOffset(2030, 1, 1, 0, 0, 0, TimeSpan.Zero));

var component = ComponentBuilder.Create<Program>()
                                .AddHarness(time)
                                .AddHarness(http)
                                .Build();

In a test, move the clock instead of waiting:

await client.PostAsJsonAsync("/subscriptions", new { Plan = "trial" });

time.Advance(TimeSpan.FromDays(15));

var subscription = await client.GetFromJsonAsync<Subscription>("/subscriptions/current");
Assert.True(subscription!.Expired);

When code is already waiting on the fake clock (for example, a Task.Delay(..., timeProvider) in a request that is still running), Advance completes the wait immediately. Advance only after the code has started waiting, or keep advancing until the request finishes.

  • Advance(TimeSpan) and SetUtcNow(DateTimeOffset) move the clock forward; UtcNow reads it.
  • TimeProvider is the FakeTimeProvider itself, for anything else it supports (for example, AutoAdvanceAmount).
  • new TimeProviderHarness() starts at the FakeTimeProvider default of 2000-01-01 UTC. Pass a start time if the application checks dates such as certificate or token expiry.

What it affects

The harness replaces every TimeProvider registration in the application's service provider. It affects only code that resolves TimeProvider from there, including framework and library services that do so (for example, resilience handlers): their timeouts and retry delays no longer elapse on their own, only when the test moves the clock. DateTime.UtcNow, TimeProvider.System and the containers keep the real clock.

Register TimeProvider in the application and inject it where you need time:

builder.Services.AddSingleton(TimeProvider.System);
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  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.  net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.6.0 61 11/22/2026
1.5.0 78 11/20/2026
1.4.0 107 11/13/2026