c# - 使用 Nsubstitute 注册或配置 IOC 容器

标签 c# .net unit-testing dependency-injection nsubstitute

我有一个自定义 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/

相关文章:

c# - 如何动态添加CSS类?

c# - 在 LabelFor() 控件中格式化文本

c# - 上传文件到数据库

c# - 在 Visual Studio 中查看哪些方法/函数返回特定对象

c# - 为什么 Encoding.Default.GetBytes() 在 VB.NET 和 C# 中返回不同的结果?

java - 当 SoapAction 丢失时,.NET 2.0 Web 服务可以处理来自客户端的调用吗?

c# - TPL数据流处理N条最新消息

node.js - 使用 mocha+sinon 测试 ExpressJS 路由时,如何 "stub"路由本地函数?

c# - 为什么我的单元测试在不运行测试的情况下成功完成?

ruby-on-rails - 我可以用 Spock 做这个吗?