"Swapping" instead of "Injecting" calls between classes
Eli Lopian, Typemock CEO and awesome Coder, just created a nice little API wrapper around Typemock Isolator that would allow a very simple and readable "Swapping" effect between classes. It would allow you to write code like this:
[Test]
public void SwapStatic_CallsFake()
{
Swap.StaticCalls<TypeA, TypeB>();
Assert.AreEqual(2, TypeA.StaticReturnOne());
Swap.Rollback();
}
[TestMethod]
public void SwapInstance_CallsFake()
{
Swap.NextNew<OriginalClass, FakeClass>();
OriginalClass swappedInstance = new OriginalClass();
Assert.AreEqual(2, swappedInstance.ReturnOne());
}
The first test uses the "Swap" class to replace static calls and redirect them to your own class with static methods. The second one is more advanced and will mock all instance calls made on the next instance that will be created of that type. so the last line on the second test will actually call a method against the FakeClass type.
pretty cool and very readable. download the code and binaries from his post.