Controlling time in an integration test makes results reproducible: a retry delay, a cache expiry and a business cut-off all move together, instead of depending on how fast the CI agent is. Register TimeProvider.System in Program.cs, then in the test call factory.WithWebHostBuilder(b => b.ConfigureTestServices(s => s.AddSingleton<TimeProvider>(fake))) with a FakeTimeProvider. Polly v8 pipelines from Microsoft.Extensions.Resilience, HybridCache and the ASP.NET Core rate limiters resolve TimeProvider from DI, so fake.Advance(...) fires retry delays, expires cache entries and moves your own rules at once. Without it, a retry test waits for real backoff delays (slow), and a cache test either sleeps or never sees an expiry. Code that uses new Timer or DateTime.UtcNow directly won't follow the fake, so ban those APIs with BannedApiAnalyzers: add the Microsoft.CodeAnalysis.BannedApiAnalyzers package and a BannedSymbols.txt (an AdditionalFiles item) listing P:System.DateTime.Now, P:System.DateTime.UtcNow and P:System.DateTimeOffset.UtcNow, which raises RS0030 at build time.
Checks they understand which framework components resolve TimeProvider from DI and how to override it in WebApplicationFactory.
Last updated 23 Nov 2026.