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
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
When I use Members.ReturnRecursiveFakes, it seems that all the mock object's method call can't be detected by WasCalledWithAnyArguments that takes in parameter.

Here's the production code
    public class AnObject
    {
        public void DoNothing(AnObject anObj)
        {

        }
    }

    public class AnWrapperObject
    {
        public AnObject objAn
        {
            get;
            private set;
        }
        public void CallDoNothing()
        {
            objAn.DoNothing(objAn);
        }
    }


Here's the test code
        public void Test1()
        {
            AnWrapperObject wrappObj = Isolate.Fake.Instance<AnWrapperObject>(Members.ReturnRecursiveFakes);
            Isolate.WhenCalled(() => wrappObj.CallDoNothing()).CallOriginal();
            wrappObj.CallDoNothing();
            Isolate.Verify.WasCalledWithAnyArguments(() => wrappObj.objAn.DoNothing(wrappObj.objAn));
        }


And here's the exception trace:
failed: 
TypeMock Verification: Method objAn.objAn.DoNothing() was expected but was not called
   TypeMock.VerifyException: 
   TypeMock Verification: Method objAn.objAn.DoNothing() was expected but was not called
   at bz.b(dk A_0, i A_1)
   at bz.a(Action A_0)


If the method is AnObject.DoNothing() ( note that there is no method parameter), then the test can pass without problem.
________
Dodge Journey history
asked by nsoonhui (59.1k points)

4 Answers

0 votes
Hi,

This is indeed a bug :(
What's throwing us off is the call to the wrappObj.objAn property as a parameter to the DoNothing() call in Verify. You can work around this easily by extracting that call into a variable and use that instead for the same effect:


            
AnWrapperObject wrappObj = Isolate.Fake.Instance<AnWrapperObject>(Members.ReturnRecursiveFakes);
Isolate.WhenCalled(() => wrappObj.CallDoNothing()).CallOriginal();
wrappObj.CallDoNothing();
            
AnObject o =  wrappObj.objAn;
Isolate.Verify.WasCalledWithAnyArguments(() => wrappObj.objAn.DoNothing(o));


We will of course work to resolve this in an upcoming version.

Thanks,
Doron
Typemock Development
answered by doron (17.2k points)
0 votes
Actually in this test you don't care about the arguments, so you can just use null:

Isolate.Verify.
  WasCalledWithAnyArguments(() => wrappObj.objAn.DoNothing(null));
answered by eli (5.7k points)
0 votes
Hi,

I think the WasCalledWithExactArguments has got the same problem and that was I discovered this bug.
________
wiki vaporizer
answered by nsoonhui (59.1k points)
0 votes
The limitation I mentioned applies to verifying exact arguments as well as any arguments. Thanks for the added info.

You can make a test with verify exact arguments pass by extracting the parameter outside the Verify.WasCalled statement and passing in the value you extracted instead of the call itself - see the example in my last post.

Doron
answered by doron (17.2k points)
...