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,
When I use WithExactArguments in my mocking of a method having an out parameter, the mocking is not done.

Why do you validate out parameter?

Example:

            var myDict = Isolate.Fake.Instance<DummyDict>();
            int i = 9;
            Isolate.WhenCalled(() => myDict.TryGetValue("salut", out i)).WithExactArguments().WillReturn(true);

            int j;
            Assert.IsTrue(myDict.TryGetValue("salut", out j));
            Assert.AreEqual(9, j);


The Assert.IsTrue(myDict.TryGetValue("salut", out j)); will throw because the function TryGetValue is called and not mocked.

Thanks

Pierre-Luc
asked by pierre-luc (3.3k points)

7 Answers

0 votes
Hi Pierre-Luc,

This seems to be a bug with out parameters in conjunction with WithExact. Can you tell us what are you trying to test? I may be able to help you find a workaround to this issue while we schedule it to be fixed.

Thanks,
Doron
Typemock Support
answered by doron (17.2k points)
0 votes
Basically, I want to fake the function TryGetValue of my SpecialDictionary.
I also want to be sure that the good value is returned for the right Key.

I want to avoid filling the Dictionary, because I can't do it.

I didn't try it, but will Isolate.Verify.WasCalledWithExactArguments have the same problem with out parameter?
answered by pierre-luc (3.3k points)
0 votes
Pierre-Luc,

Is it necessary for you to use WithExact() in your test? Are you setting up a complete set of data in your dictionary, or only checking it with one data point? In that case you can work around the problem by leaving out the WithExact() statement.

Can you post the custom collection code (or send it to our support mailbox) so I can have a better grasp of the problem at hand?

Thanks,
Doron
Typemock Support
answered by doron (17.2k points)
0 votes
Yes I must use the WithExact.

My DummyDict is a class that will decorate a Dictionary. So the class is implementing IDictionary<string> and create an instance of Dictionary<string>. when a function is DummyDict is called, it calls the same function on the real Dictionary. (Decorator design pattern).
For your test, you can only implement the TryGetValue function.

For the workaround, I use the DoInstead with an if inside to validate the first parameter. It's uggly, but it works.
            Isolate.WhenCalled(() => myDict.TryGetValue(streamId, out fakeOldStream))
                .DoInstead(context =>
                               {
                                   var streamIdParam = (StreamId) context.Parameters[0];
                                   if (streamIdParam == streamId)
                                   {
                                       context.Parameters[1] = fakeOldStream;
                                       return true;
                                   }
                                   else
                                   {
                                       context.Parameters[1] = null;
                                       return false;
                                   }
                               });
answered by pierre-luc (3.3k points)
0 votes
Hi Pierre-Luc,

We are working on solving this issue, and you will find a fix in one of the future releases.

Feel free to post here or contact our support mail if the DoInstead "ugly" workaround doesn't work...

Regards,
Yonatan
Typemock Support
answered by yonatan (1.6k points)
0 votes
Hi,

A fix to this problem can be found in our next release, or until then in this patch: https://www.typemock.com/patches/Typemoc ... .9.526.msi

Regards,
Yonatan
Typemock Support
answered by yonatan (1.6k points)
0 votes
Thanks.
answered by pierre-luc (3.3k points)
...