Hi all,
I found a possible bug in TypeMock when mocking base generic class. Look at the following code:
internal class BaseGeneric<T>
{
internal List<T> _collection = null;
internal BaseGeneric()
{
_collection = new List<T>();
}
internal bool Apply()
{
foreach (T elem in _collection)
{
}
return false;
}
}
internal class Derived : BaseGeneric<int>
{
}
[TestFixture]
[ClearMocks]
public class TestDerived
{
[Test]
[VerifyMocks]
public void TestBoo()
{
Mock<Derived> mock = MockManager.Mock<Derived>();
mock.AlwaysReturn("Apply", true);
Derived rules = new Derived();
Assert.IsTrue(rules.Apply());
}
}
When running this test (pattern extracted from our code), I always receive the following stack:
System.NullReferenceException: Object reference not set to an instance of an object.
at BaseGeneric`1.Apply() in BaseGeneric.cs: line 19
at TestDerived.TestBoo() in BaseGeneric.cs: line 46
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)
at TestDerived.TestBoo() in BaseGeneric.cs: line 41
Enviroment:
* TypeMock Isolator 5.3.0
* Visual Studio 2005
Please note that with TypeMock 5.0.0 all is working fine.
Please let me know if there is any workaround or planned fix for this problem.
Thanks