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

There is a broken case in Typemock 5.3.1 relating to how WasNotCalled is used in conjunction with DateTime.Now as an argument.

Here's the production code:

    public class SmallBridge
    {
        public void RunInsert(DateTime dt)
        {
            
        }

        public void AStringInsert(string str)
        {
            
        }
    }


And here's the test code:

   [TestFixture, ClearMocks]
    public class TypemockTest
    {

        public TypemockTest()
        {
            
        }



        [Test, Isolated]
        public void MeanCase1()
        {
            SmallBridge aBridge = Isolate.Fake.Instance<SmallBridge>(Members.CallOriginal);
            Isolate.Verify.WasNotCalled(()=>aBridge.RunInsert(DateTime.Now));
        }

        [Test, Isolated]
        public void MeanCase2()
        {
            SmallBridge aBridge = Isolate.Fake.Instance<SmallBridge>(Members.CallOriginal);
            Isolate.Verify.WasNotCalled(() => aBridge.AStringInsert(string.Empty));
        }
    }


MeanCase2 passes but MeanCase1 fails with the below message:

TestCase 'MeanCase1'
failed: TypeMock.TypeMockException : 
*** Cannot use Isolate.Verify on a static method without first setting static method behavior using Isolate.Fake.StaticMethods()
   at dz.a()
   at cy.a(Delegate A_0)
   at cy.c(Delegate A_0)
   at cy.a(Action A_0)
   C:developmentEsteem7 .Net2PostProtect2UnitTestTypemockTest.cs(39,0): at PostProtect2UnitTest.TypemockTest.MeanCase1()
   at TypeMock.MockManager.a(String A_0, String A_1, Object A_2, Object A_3, Boolean A_4, Object[] A_5)
   at TypeMock.InternalMockManager.getReturn(Object that, String typeName, String methodName, Object methodParameters, Boolean isInjected)
   C:developmentEsteem7 .Net2PostProtect2UnitTestTypemockTest.cs(0,0): at PostProtect2UnitTest.TypemockTest.MeanCase1()


Typemock 5.3.0 doesn't have this problem.
 

asked by nsoonhui (59.1k points)
edited by Bar

2 Answers

0 votes
Hi Soon Hui,

The root cause for this is the nested call in Verify, for instance:
Isolate.Verify.WasNotCalled(()=>aBridge.RunInsert(DateTime.Now));


Until this version, Isolator did not handle calls to DateTime.Now, and this situation did not cause a nested call in Verify. Now that we properly handle DateTime.Now, this causes a nested call, which is unsupported. The way to resolve this is to extract the call to DateTime.Now to a variable and verify against that:
var date = DateTime.Now;
Isolate.Verify.WasNotCalled(()=>aBridge.RunInsert(date));


I hope this clarifies matters and helps work around this issue.
Thanks,
Doron
Typemock Support
answered by doron (17.2k points)
0 votes
Hi Soon Hui,

The root cause for this is the nested call in Verify, for instance:
Isolate.Verify.WasNotCalled(()=>aBridge.RunInsert(DateTime.Now));


Until this version, Isolator did not handle calls to DateTime.Now, and this situation did not cause a nested call in Verify. Now that we properly handle DateTime.Now, this causes a nested call, which is unsupported. The way to resolve this is to extract the call to DateTime.Now to a variable and verify against that:
var date = DateTime.Now;
Isolate.Verify.WasNotCalled(()=>aBridge.RunInsert(date));


I hope this clarifies matters and helps work around this issue.
Thanks,
Doron
Typemock Support


Thanks,

Do let me know when the problem gets fixed
 

answered by nsoonhui (59.1k points)
edited by Bar
...