我有一个自定义 IOC 容器,它接受接口(interface)和具体类型作为要注册的参数。在我的项目中,我已经注册了下面代码中提到的配置。你能帮我一个人如何使用 NSubstitute 在单元测试项目中注册吗?
IOC-Conatincer.cs
Register<Intf, Impl>();
应用程序-Configuration.cs
Register<ICustomer,Customer>();
单元测试应用程序 - CustomerTest.cs
Register<ICustomer,StubCustomer>(); -I want something like this
var substitute = Substitute.For<ICustomer>(); but It provides something like this
最佳答案
我不认为您可以让 Unity 解析具体实例,然后在其上使用 NSubstitute 属性/方法。
由于您的目的是进行单元测试,因此您需要使用 NSubstitue 解析实例,因为只有使用该实例,您才能配置属性/方法以返回对象或检查是否收到调用。
关于c# - 使用 Nsubstitute 注册或配置 IOC 容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36760824/