I get a NullReferenceException with Isolator 5.1.1 and 5.2.3 when I instantiate a custom generic list after setting an expectation on an object that returns a instance of the custom generic list.
Thee simplest way I could reproduce the bug is with the following code:
[Test]
public void Test()
{
PersonService personService = Isolate.Fake.Instance<PersonService>();
Isolate.WhenCalled(() => personService.ServiceMethod()).WillReturn(null);
// NullReferenceException if generic type != Person
var filterList = new CustomList<Customer>();
}
The ServiceMethod() implementation is as follows:
public CustomList<Person> ServiceMethod()
{
return new CustomList<Person>();
}
public class CustomList<T> : Collection<T> where T : class
{
public CustomList()
: base(new List<T>())
{ }
}
Callstack
System.NullReferenceException: Object reference not set to an instance of an object.
at TypeMock.MockManager.GetMocks(Type type)
at TypeMock.MockManager.c(Object A_0)
at dl.c(Object A_0)
at dl.a(String A_0, Object A_1, Object A_2, ref Type A_3, String A_4)
at TypeMock.MockManager.a(String A_0, String A_1, Object A_2, Object A_3, Boolean A_4)
at TypeMock.InternalMockManager.isMocked(Object that, String typeName, String methodName, Object methodParameters, Boolean isInjected)
at Garaio.Products.RoomsPro.Core.Entities.Helpers.FilterList`1..ctor() in FilterList.cs: line 24
at Garaio.Products.RoomsPro.Web.Controllers.PersonControllerFixture.Test() in PersonControllerFixture.cs: line 73
Am I doing something wrong? Any workarounds?
Studix