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 am working with TypeMock 5.3.1. If I create a group of classes like this:

   public class A<T>
   {
      virtual public int GetOne()
      {
         return 1;
      }
   }

   public class B<T> : A<T>
   {
      public override int GetOne()
      {
         return GetTwo();
      }

      private int GetTwo()
      {
         return 2;
      }
   }

   public class C : B<int>
   {

   }


And run the code in a test like this:

   [TestMethod]
   public void TestMethod()
   {
      C c = new C();

      Isolate.NonPublic.WhenCalled(c, "GetTwo").DoInstead(callContext =>
      {
         return 20;
      });

      Assert.AreEqual(20, c.GetOne());
   }


I get a NullReferenceException. Is this a bug, or am I doing something wrong?

The example is nonsense, but it mimics facets of some real code that I'm attempting to test. Any help that you can offer would be appreciated.

Thanks!
asked by Samuel (1.1k points)

1 Answer

0 votes
Hi Samuel,

You're correct, we do have a bug there. It happens when faked behavior is defined on a subclass with non-public method which is defined in generic base class.

The code you wrote is correct. We will fix the bug in the future, thanks for letting us know.

Best Regards,
Elisha
Typemock Support Team
answered by Elisha (12k points)
...