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.
精彩评论