WCF 数据服务:模拟 OperationContext
我们想模拟 OperationContext
类以进行测试。我们正在使用“模拟”。但 OperationContext
是一个密封类,不能被模拟。因此,我们尝试创建一个虚拟 OperationContext
对象。但是 OperationContext
构造函数采用 IContextChannel
作为参数。我们想知道一种获取 IContextChannel
的方法,以便将其传递给 OperationContext
构造函数。
We would like to mock the OperationContext
class for testing purposes. We are using 'Mock'. But OperationContext
is a sealed class and cannot be mocked. Therefore we are trying to create a dummy OperationContext
object. But OperationContext
constructor takes IContextChannel
as parameter. We would like to know of a way to get hold of a IContextChannel
so that it can be passed to the OperationContext
constructor.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一般建议是 不引用wcf实现wcf服务。
如何执行此操作的示例位于 http://marcin。 floryan.pl/blog/2012/01/do-we-really-need-wcfmock
以及在 http://blogs.msdn.com/b/ ploeh/archive/2006/12/04/integrationtestingwcfservices.aspx
如果您仍然需要模拟,请遵循 http://blogs.msdn.com/b/ploeh/archive/2008/06/28/unit-testing-duplex-wcf-services.aspx
或者,作为最后的手段,您可以使用WCFmock
来自 http://blog.gfader.com/2010/08/how-to-unit-test-wcf-service.html
The general recommendation is to implement wcf services without referencing wcf.
Examples how to do it are in http://marcin.floryan.pl/blog/2012/01/do-we-really-need-wcfmock
And in http://blogs.msdn.com/b/ploeh/archive/2006/12/04/integrationtestingwcfservices.aspx
If you still need mock follow a recommendation from http://blogs.msdn.com/b/ploeh/archive/2008/06/28/unit-testing-duplex-wcf-services.aspx
Alternatively as a last recourse you can use WCFmock
From http://blog.gfader.com/2010/08/how-to-unit-test-wcf-service.html
NetFX 项目 包含许多包装类和接口,以实现此类操作。
The NetFX project contains a number of wrapper classes and interfaces to allow just this sort of thing.