chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes
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!
asked by patrick.gill@verint. (2.6k points)

2 Answers

0 votes
Hi,

It seems like a bug we had in an earlier version and was fixed in the latest version (6.0). What version of Isolator are you using?

Regards,
Elisha,
Typemock Support
answered by Elisha (12k points)
0 votes
I installed version 6.0, it solved my problem.
Thanks
answered by patrick.gill@verint. (2.6k points)
...