关于[Tips & tricks for unit testing in .NET Core 3: Using and mocking ISystemClock instead of using DateTime]的摘要:
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. This interface is found in the Microsoft.Extensions.Internal assembly of the Microsoft.Extensions.Caching.Abstractions package. It also exists in Microsoft.AspNetCore.Authentication package. It also exists in Microsoft.AspNetCore.Authentication assembly. The Nuget package has the same name. It’s up to you to choose which package you want to use. We will see in this article, from a scenario, how to make a service testable using DateTime.