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

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:

    [TestClass]
    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); }
            }
        }
        [TestMethod]
        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);

                });
            target.FooCaller(-1);
        }
}

I expected:

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

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 8.1.1.11 version that I'm now using.

Thanks,

-Kevin

asked by kevinms99 (4.4k points)
I'm hoping to get a response to this issue.  It's now been 10 days without any response.

Please log in or register to answer this question.

...