Is there any built-in way in NSubstitute for mocking a class with its instance except for few methods?
In example I want to preserve the whole functionality of the instance, but check if a method gets called with particular parameters.
To do that actually I do
public class Wrapper: IInterface
{
public IInterface real;
public IInterface sub;
public void Wrapper(IIterface realInstance, IIterface nsubstitute)
{
real = realInstance;
sub = nsubstitute;
}
public void MethodThatShouldWorkAsAlways()
{
real.MethodThatShouldWorkAsAlways();
}
public intMethodToBeTested(int a)
{
return sub.MethodToBeTested();
}
}
The reason for that is that I'm testing stuff complex enough that I can't simply create wrappers manually, that's time consuming and error-prone. It would be nice if Nsubstitute allows for something like:
IIterface realMock = NSubstitute.Mock< IIterface>( new RealClass());
realMock.MethodThatShouldWorkAsAlways(); // regular logic
realMock.MethodToBeTested(4).Returns( 3); // overrides the method to always returns 3
but I did not find any documentation for doing that so far.