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 TypeMock

I am trying to make a mocked version of ExampleClass, that when calling a mocked version of A() will call the mocked version of B():

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TypeMock.ArrangeActAssert;

namespace TestProject1
{
    public class ExampleClass
    {
        public void A()
        {
            throw new Exception("A Original");
        }

        public void B()
        {
            throw new Exception("B Original");
        }
    }
    
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        [Isolated]
        public void TestMethod1()
        {
            var e = Isolate.Fake.Instance<ExampleClass>();

            Isolate.WhenCalled(() => e.B()).WillThrow(new Exception("B Mocked"));
            Isolate.WhenCalled(() => e.A()).
                DoInstead(context =>
                              {
                                  e.B();
                              });

            e.A();
        }
    }
}


The test throws "B Original", but i would excpect it to throw "B Mocked"? Are my expectations wrong? or is it a bug? I am using the latest version of TypeMock Isolator (5.3.1) on the .NET 3.5 platform.
asked by ahvam (1.7k points)

1 Answer

0 votes
Hi,

What you see is a known bug of DoInstead.
Currently if you are using a faked instance inside the DoInstead delegate the faked method or property will not be faked.

We'll update you once this issue is fixed.
answered by ohad (35.4k points)
...