Tips & tricks for unit testing in .NET Core 3: Using and mocking ISystemClock instead of using DateTime

added by DotNetKicks
2/4/2020 3:23:40 PM


I discovered not long ago that a way to inject DateTime by dependency in my classes. Result, I was able to get rid of DateTime used directly in my services and I could greatly facilitate the testing unit of these services. The interface allowing me to do this is ISystemClock and I can mock it.