1 回答

TA贡献1836条经验 获得超3个赞
AddSingleton是 上的扩展方法IServiceCollection。这使得模拟或验证变得更加困难。
考虑使用接口的实际实现,然后在执行被测方法后验证预期行为。
例如
public void checkIfServicesAddedTo_DI() {
//Arrange
var services = new ServiceCollection();// Substitute.For<IServiceCollection>();
var configuration = Substitute.For<IConfiguration>();
MatchServicesManager servicesManager = new MatchServicesManager();
//Act
servicesManager.AddServices(services, configuration);
//Assert (using FluentAssertions)
services.Count.Should().Be(1);
services[0].ServiceType.Should().Be(typeof(IMatchManager));
services[0].ImplementationType.Should().Be(typeof(MatchManager));
}
- 1 回答
- 0 关注
- 136 浏览
添加回答
举报