Usually I have client code similiar to something like this:
// SomeOtherServiceClient would be injected in actual code.
ISomeOtherService client = new SomeOtherServiceClient();
... so that I can mock the service for testing. But now I have a WCF service that has the context mode set to PerSession
and implements IDisposable
.
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
public class SampleService : ISampleService, IDisposable
{
public void SampleMethod() { ... }
public void Dispose() { ... }
}
If I wish to put the client inside a using
statement, is there still a way for me to mock the client for testing?
// SampleServiceClient would be injected in actual code.
using (var client = new SampleServiceClient())
{
...
}