开发者

Remove dependancies on wcf services so I can unit test the class

I want to remove dependencies from my classes for WCF Services. I want to inject them into the constructor as an interface and then mock the interface when I am testing that class.

What is the best practice and the fastest way for doing this?

my class:

class Test
{
public IMyWCFInterface _wcf;
 p开发者_如何学Pythonublic Test(IMyWCFInterface wcf)
{
_wcf=wcf;
}
}


When you generate a WCF client proxy, an interface for the proxy should be generated for you. In addition, the generated client class that derives from ClientBase<TChannel> should implement that interface. Rather than depending on the class, depend on the interface, and inject an instance of the client class. That should resolve your problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜