【发布时间】:2020-09-27 08:32:14
【问题描述】:
我在集成测试中使用了一个 ContainerFixture 类,如下所示:
services.AddSingleton(Mock.Of<IWebHostEnvironment>(w =>
w.EnvironmentName == "Development" &&
w.ApplicationName == "Application.WebUI"));
在上面的示例中,我使用的是 Moq,但我想使用 NSubstitute。
当我用 Substitute.For 替换 Mock.of 时,我收到以下错误:
services.AddSingleton(Substitute.For<IWebHostEnvironment>(w =>
w.EnvironmentName == "Development" &&
w.ApplicationName == "Application.WebUI"));
错误:无法将 lambda 表达式转换为类型“对象”,因为它不是委托类型。
我们应该如何使用 Substitute 来代替上面的例子?
【问题讨论】:
-
我没有投反对票,但问题标题有点含糊。也许可以改进。
标签: c# xunit nsubstitute