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
hi,
I'm having an issue with creation of Mock Object, and getting an ArgumentNullException error.

I'm having a Class called TestBase, which is having a function which takes a func<T> as a parameter.

public TR WebMethodCall<TR>(Func<TR> methodname);

so I create a Fake of it like this,

var testbase = Isolate.Fake.Instance<TestBase>();
Isolate.Swap.NextInstance<TestBase>().With(testbase );

Isolate.WhenCalled((Func<UserViewsResponseType_t> p) =>
testbase.WebMethodCall(p))
.AndArgumentsMatch(p => p != null && p == client.getUserViews)
.WillReturn(new UserViewsResponseType_t());

But I'm getting an error in the WhenCalled function, even though I have tried the same with other methods, and also for other classes they are working fine, so I think that there is a bug in the Typemock where we are trying to mock a function which takes funct<T> as a parameter.

Can you please help me out, as I'm stuck in a complex testing of our core module.

Thanks.
asked by gauravgupta81 (600 points)

1 Answer

0 votes
Hi,

The issue you brought up is a known bug.

You can use the DoInstead as a workaround for now:

For example, in your case:


            var proxy = Isolate.Swap.NextInstance<TestBase>().WithRecursiveFake();
        
            Isolate.WhenCalled(() => proxy.WebMethodCall((Func<int>) null)).DoInstead(

                c =>
                    {
                        if ((Func<int>) c.Parameters[0] == foo && ((Func<int>) c.Parameters[0] != null))
                        {
                            new UserViewsResponseType_t();
                        }
                        else
                        {
                            return 0;

                        }
                    }
                );



You can read more about the DoInstead here.

Please let us know how things worked out.
answered by NofarC (4k points)
...