I am attempting to use TypeMock to mock-out a data access layer generated by .nettiers. I have hit a problem when dealing with empty .nettiers TList objects.
The code below shows the problem. Classes ProductRelationship and ProductRelationshipService were generated by .nettiers from the database. These classes perform database table access. A TList is a .nettiers list structure.
Could it be that TypeMock affects a .nettiers TList class at runtime in such a way that the Predicate overload of the FindAll method does not work on an empty list (i.e. Count = 0)? If FindAll is called on an empty TList a corrupted TList seems to be returned. (I have confirmed that if TypeMock is not used to generate the TList then there is no problem in calling FindAll on an empty TList.)
Are there any know TypeMock bugs that might explain what I have seen? Any assistance would be much appreciated.
TList<ProductRelationship> TestProductRelationshipList =
new TList<ProductRelationship>();
var FakeProductRelationshipService =
Isolate.Fake.Instance<ProductRelationshipService>();
Isolate.Swap.AllInstances<ProductRelationshipService>()
.With(FakeProductRelationshipService);
Isolate.WhenCalled(() =>
FakeProductRelationshipService.GetAll())
.WillReturn(TestProductRelationshipList);
TList<ProductRelationship> MyList =
FakeProductRelationshipService.GetAll();
int count = MyList.Count; //this line works fine returning 0 as expected
TList<ProductRelationship> MyFilteredList = MyList.FindAll(
delegate(ProductRelationship pr) { return pr.ProductId == 1; });
count = MyFilteredList.Count; //null-reference exception thrown