.NET 8 Testing Times
Coding Tutorials Coding Tutorials
14.4K subscribers
1,113 views
34

 Published On Dec 22, 2023

It's always been difficult to test anything that depends on time, because time is out of control. But with the .NET 8 TimeProvider, we can take control of time itself.

Source code available at: https://github.com/JasperKent/Timer-T...

There were a couple of imperfections in the final version on the video, which I've fixed in the latest revision on GitHub. The mocking of GetUtcNow() in TickFiresEvent() was unnecessary, and the events in the Blazor component needed to be unsubscribed before the clock was switched.

Related videos:
- C# 12 Primary Constructors    • C# 12 Primary Constructors  
- .NET 8 Keyed Dependency Injection    • .NET 8 Keyed Dependency Injection  

Topics include:
- The problems of testing time-based applications
- CSS animation in Blazor
- Using the NSubstitute mocking library
- The TimeProvider class
- The DateTimeOffset struct
- The ITimer interface
- The null coalescing assignment operator (??=)
- Keyed dependency injection
- Mocking the current time
- Mocking timers

show more

Share/Embed