Can NSubstitute create what are called shims in Microsoft terminology?
For example, consider:
// Code under test
class MyClass
{
public string str1;
public string MyMethod()
{
AnotherClass thatThing = new AnotherClass();
string str2 = thatThing.DoSomething(str1);
// more code, which is what I am really trying to test
return result;
}
}
// Unit test code
MyClass myThing = new MyClass();
myThing.str1 = "TestInput"
// When thatThing.DoSomething is called with input "SampleInput"
// it should just return "SampleOutput" instead of calling the
// real AnotherClass:DoSomething(string)
//
// Apparently Microsoft Fakes can do this by (I think)
// ShimAnotherClass.AllInstances.DoSomething = ("SampleInput) => "SampleOutput";
string actualResult = myThing.MyMethod();
Assert.AreEqual("ExpectedResult", actualResult);