Here's the code that worked fine for months. It was broken by newest Isolator version (5.4.5):
public class BaseClass
{
protected bool m_Enabled;
public virtual bool Enabled1 { get { return m_Enabled; } set { m_Enabled = value; } }
public virtual bool Enabled2 { get; set; }
public virtual bool GetEnabled() { return false; }
}
public class SubClass : BaseClass
{
}
[TestFixture]
[Isolated]
public class TestClass2
{
[Test]
public void Enabled1_BaseClass()
{
var fake = Isolate.Fake.Instance<BaseClass>();
Isolate.Swap.NextInstance<BaseClass>().With(fake);
BaseClass bc = new BaseClass();
bc.Enabled1 = false;
Assert.IsFalse(bc.Enabled1);
}
[Test]
public void Enabled1_SubClass()
{
var fake = Isolate.Fake.Instance<SubClass>();
Isolate.Swap.NextInstance<SubClass>().With(fake);
SubClass sc = new SubClass();
sc.Enabled1 = false;
Assert.IsFalse(sc.Enabled1);
}
[Test]
public void Enabled2_BaseClass()
{
var fake = Isolate.Fake.Instance<BaseClass>();
Isolate.Swap.NextInstance<BaseClass>().With(fake);
BaseClass bc = new BaseClass();
bc.Enabled2 = false;
Assert.IsFalse(bc.Enabled2);
}
[Test]
public void Enabled2_SubClass()
{
var fake = Isolate.Fake.Instance<SubClass>();
Isolate.Swap.NextInstance<SubClass>().With(fake);
SubClass sc = new SubClass();
sc.Enabled2 = false;
Assert.IsFalse(sc.Enabled2);
}
[Test]
public void GetEnabled_BaseClass()
{
var fake = Isolate.Fake.Instance<BaseClass>();
Isolate.Swap.NextInstance<BaseClass>().With(fake);
BaseClass bc = new BaseClass();
Assert.IsFalse(bc.GetEnabled());
}
[Test]
public void GetEnabled_SubClass()
{
var fake = Isolate.Fake.Instance<SubClass>();
Isolate.Swap.NextInstance<SubClass>().With(fake);
SubClass sc = new SubClass();
Assert.IsFalse(sc.GetEnabled());
}
}
All tests should pass. However, two of them fail with "null reference" exception:
TestCase 'TypeMockTest.TestClass2.Enabled1_SubClass'
failed: System.NullReferenceException : Object reference not set to an instance of an object.
at e1.a(MethodBase A_0, Object[] A_1)
at f8.a(MethodBase A_0, Object[] A_1, TypeParams A_2)
at ce.a(String A_0, Object[] A_1, Object A_2, Object A_3, String A_4, Type A_5)
at c8.a(String A_0, Object A_1, MethodBase A_2, Object[] A_3, Object A_4, String A_5, ce A_6)
at c8.b(Object A_0, String A_1, String A_2, MethodBase A_3, Object[] A_4, Object A_5)
C:ProjectsNETTypeMockTestMyClass2.cs(15,0): at TypeMockTest.BaseClass.set_Enabled1(Boolean value)
C:ProjectsNETTypeMockTestMyClass2.cs(46,0): at TypeMockTest.TestClass2.Enabled1_SubClass()
at TypeMock.MockManager.a(String A_0, String A_1, Object A_2, Object A_3, Boolean A_4, Object[] A_5)
at TypeMock.InternalMockManager.getReturn(Object that, String typeName, String methodName, Object methodParameters, Boolean isInjected)
C:ProjectsNETTypeMockTestMyClass2.cs(41,0): at TypeMockTest.TestClass2.Enabled1_SubClass()
TestCase 'TypeMockTest.TestClass2.Enabled2_SubClass'
failed: System.NullReferenceException : Object reference not set to an instance of an object.
at e1.a(MethodBase A_0, Object[] A_1)
at f8.a(MethodBase A_0, Object[] A_1, TypeParams A_2)
at ce.a(String A_0, Object[] A_1, Object A_2, Object A_3, String A_4, Type A_5)
at c8.a(String A_0, Object A_1, MethodBase A_2, Object[] A_3, Object A_4, String A_5, ce A_6)
at c8.b(Object A_0, String A_1, String A_2, MethodBase A_3, Object[] A_4, Object A_5)
at TypeMockTest.BaseClass.set_Enabled2(Boolean value)
C:ProjectsNETTypeMockTestMyClass2.cs(68,0): at TypeMockTest.TestClass2.Enabled2_SubClass()
at TypeMock.MockManager.a(String A_0, String A_1, Object A_2, Object A_3, Boolean A_4, Object[] A_5)
at TypeMock.InternalMockManager.getReturn(Object that, String typeName, String methodName, Object methodParameters, Boolean isInjected)
C:ProjectsNETTypeMockTestMyClass2.cs(63,0): at TypeMockTest.TestClass2.Enabled2_SubClass()
4 passed, 2 failed, 0 skipped, took 1,42 seconds (NUnit 2.5).