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
In Isolator 5.4.5, this code throws an unexpected TypeMockException:

[ img ]

[TestClass, Isolated]
public class Tests
{
   public class A
   {
      public B B { get; private set; }

      public A()
      {
         B = new B();
         B.BMethod();
      }
   }

   public class B
   {
      public void BMethod()
      {
      }
   }

   [TestMethod]
   public void Test()
   {
      B bToSwap = Isolate.Fake.Instance<B>();
      Isolate.Swap.AllInstances<B>().With(bToSwap);
      //
      A a = Isolate.Fake.Instance<A>(Members.CallOriginal);
      //
      Isolate.Verify.WasCalledWithExactArguments(() => bToSwap.BMethod());
   }
}
asked by Neil (27.7k points)

2 Answers

0 votes
Hi Neil,

Thank you for the great report.
I appears we have a bug in Swap.AllInstances that causes this exception, a simple workaround for this problem is using Swap.NextInstance instead.

I will add this bug to our future development plan and update this thread whn it will be solved.
answered by dhelper (11.9k points)
0 votes
Thanks Dror.
answered by Neil (27.7k points)
...