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

How to set up a recursive call on a faked object?

0 votes

I have a case where the code under test, product1, calls into a mocked object, mock1.Entry, where mock1 calls back to product1 which calls back into mock1.Entry.  The second call to mock1.Entry does not get mocked.  Is there some way to continue to mock this second call?

A simplified example:

    public class UnitTest1
        public class C1
            public void Foo(int val) { }
        public class C2
            private C1 _c1;
            public C2(C1 c1) { _c1 = c1; }
            public void FooCaller(int val)
                if (val < 1) { _c1.Foo(val); }
        public void TestMethod1()
            C1 c1Fake = Isolate.Fake.Instance<C1>();
            C2 target = new C2(c1Fake);
            Isolate.WhenCalled(() => c1Fake.Foo(0)).DoInstead(
                context =>
                    int passedVal = (int)context.Parameters[0];
                    target.FooCaller(passedVal + 1);


I expected:


instead, I got:

target.FooCaller->c1Fake.FooCaller(DoInstead)->target.FooCaller->c1Fake.FooCaller(ACTUAL METHOD)

This behavior used to work as expected in 6.0.8 and has changed in the version that I'm now using.



asked Apr 11, 2016 by kevinms99 (4,410 points)
I'm hoping to get a response to this issue.  It's now been 10 days without any response.

3 Answers

0 votes

Hi Kevin!

We reproduced this issue on our machines, so i can confirm that this is bug. 

I'll update here on the status.

answered Apr 25, 2016 by eva (1,580 points)
0 votes
Hi, Kevin.

Faking inside DoInstead() block was limited. We changed it, by adding a special flag for indicate recursion.

You'll see it in our release very soon.
answered Jun 7, 2016 by eva (1,580 points)
0 votes

This issue is fixed in version 8.4.0 using the new API 



answered Jun 14, 2016 by eva (1,580 points)