1 回答

TA貢獻(xiàn)1836條經(jīng)驗(yàn) 獲得超3個(gè)贊
AddSingleton是 上的擴(kuò)展方法IServiceCollection。這使得模擬或驗(yàn)證變得更加困難。
考慮使用接口的實(shí)際實(shí)現(xiàn),然后在執(zhí)行被測(cè)方法后驗(yàn)證預(yù)期行為。
例如
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 關(guān)注
- 118 瀏覽
添加回答
舉報(bào)