I have a class similar to the following:
public class MyProxy : ClientBase<IService>, IService
{
public MyProxy(String endpointConfiguration) :
base(endpointConfiguration) { }
public int DoSomething(int x)
{
int result = DoSomethingToX(x); //This passes unit testing
int result2 = ((IService)this).DoWork(x)
//do I have to extract this part into a separate method just
//to test it even though it's only a couple of lines?
//Do something on result2
int result3 = result2 ...
return result3;
}
int IService.DoWork(int x)
{
return base.Channel.DoWork(x);
}
}
The problem lies in the fact that when testing I don’t know how to mock the result2 item without extracting the part that gets result3 using result2 into a separate method. And, because it is unit testing I don’t want to go that deep as to test what result2 comes back as… I’d rather mock the data somehow… like, be able to call the function and replace just that one call.
Do the following:
Set up an IService property such as:
public IService MyService { get; set; }Then you can do:
int result2 = MyService.DoWork(x)as long as somewhere in the constructor or whatever you setMyService = this;If you don’t want to expose the property you can make it private or whatever and test it using accessors.