你的位置: 码友网首页 / 资讯源列表 / Tips & tricks for unit testing in .NET Core 3: Using and mocking ISystemClock instead of using DateTime

关于[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.

原文地址: http://anthonygiretti.com/2020/02/04/tips-tricks-for-unit-testing-in-net-core-3-using-and-mocking-isystemclock-instead-of-using-datetime/

收录时间: 2020-02-05 浏览量: 1824 分类: .NET Core

| 0 收藏 | 0