As a follow-up to this, there seems to be a bug in the DoInstead behavior as you've described it above: it appears that, in the case where the DoInstead calls the same method on the same object (which should not be mocked since it's occurring inside the DoInstead block), the DoInstead handler is called a second time.
Code to reproduce:
[TestClass]
public class TestDoInstead
{
[TestMethod, Isolated]
public void Test()
{
// ARRANGE
int numCalls = 0;
Isolate.WhenCalled(() => this.GetBool()).DoInstead(
x =>
{
numCalls++;
return this.GetBool();
});
// ACT
this.GetBool();
// ASSERT
Assert.AreEqual(1, numCalls);
}
private bool GetBool()
{
return true;
}
}
We'd expect numCalls to only be 1, but it's actually 2.