如何使用模拟接口为此方法编写 NUnit 测试?
这是我拥有的 WCF 接口和类的精确表示。
我想知道如何为此编写 NUnit 测试...使用接口进行模拟。
最主要的是我不想为 WCF 服务集成测试添加服务引用。但有些事情更集中于单元测试部分。专门测试ProcessStuff方法。
namespace CompanyName.Services.ProcessStuff {
public class ProcessStuffService : IProcessStuff
{
public string ProcessStuff(string input)
{
ISomeOtherInterface ProcessManager = new ProcessManager();
return ProcessManager.ProcessStuff(input);
}
}
}
namespace CompanyName.Common.FacadeInterfaces
{
[ServiceContract(Namespace = "com.companyname.services", Name = "Process Stuff Service")]
public interface IProcessStuff
{
[OperationContract(Name = "ProcessStuff")]
string ProcessStuff(string input);
}
}
This is the exact representation of a WCF interface and class that I have.
I would like to know how to write a NUnit test for this... using the interface for mocking.
The main thing is I am NOT looking to add a service reference for the WCF service integration test. But some thing more concentrated for the unit testing part. Specifically to test the ProcessStuff method.
namespace CompanyName.Services.ProcessStuff {
public class ProcessStuffService : IProcessStuff
{
public string ProcessStuff(string input)
{
ISomeOtherInterface ProcessManager = new ProcessManager();
return ProcessManager.ProcessStuff(input);
}
}
}
namespace CompanyName.Common.FacadeInterfaces
{
[ServiceContract(Namespace = "com.companyname.services", Name = "Process Stuff Service")]
public interface IProcessStuff
{
[OperationContract(Name = "ProcessStuff")]
string ProcessStuff(string input);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我可能误解了这个问题,所以请随时澄清。
如果被测试的方法是:
IProcessStuff 接口不相关。您将创建一个新的流程管理器并调用此方法。
所以在这种情况下,我看不到你想要模拟什么接口。
Okay, I might have mis-read the question, so feel free to clarify.
If the method under test is:
The IProcessStuff interface is irrelevant. You would create a new Process Manager and call this method.
So in this case, I cannot see what Interface you want to mock.