NSubstitute says this in its docs:
methods that return an interface [...] will automatically return substitutes themselves.
That is enough usually. However, when I do this:
TestMethod:
IUnityContainer unity = Substitute.For<IUnityContainer>();
MyMethod(unity);
Actual Method:
public void MyMethod(IUnityContainer container)
{
this.container = container;
myObject = container.Resolve<ISomeObject>();
myObject.CallSomeMethod();
}
The Resolve Method returns a class. So it is not mocked. That means I get null in myObject and a null reference exception when I call CallSomeMethod
;
It would be nice if I could just get a class returned that is a mock (that is unless I have overridden that interface specifically).
Is there any way to get this using NSubstitute?