Production code
public class ClassToTest
{
private void PrivateMethod()
{
ClassToMock.Parse(new byte[] {});
}
}
public class ClassToMock
{
public static string Parse(byte[] data)
{
return "hello";
}
}
Test code:
[Isolated]
[TestMethod]
public void PrivateMethodThrowingTest()
{
Isolate.Fake.StaticMethods<ClassToMock>(Members.CallOriginal);
Isolate.WhenCalled(() => ClassToMock.Parse(null)).WillThrow(new ArgumentException());
ClassToTest target = new ClassToTest();
try
{
Isolate.Invoke.Method(target, "PrivateMethod");
}
catch (ArgumentException)
{
Debug.WriteLine("OK");
}
}
This test should pass but it fails due to the ArgumentException thrown by the mocked Parse static method:
Test method TestProject1.ClassToTestTest.PrivateMethodThrowingTest threw exception: System.ArgumentException: Value does not fall within the expected range..
When debugging the test, the execution ends when stepping over
Isolate.Invoke.Method(target, "PrivateMethod");. The breakpoint on
Debug.WriteLine("OK"); is not hit!