Hi
I see here two options:
1. The cleaner option is use Isolator
Arrange Act Assert API
than you can do this:
// Notice how the delegate got shorter!
ListEntryCreatorDelegate myListEntryCreator = delegate(int returnValue)
{
OrderLine fake = Isolate.Fake.Instance<OrderLine>();
Isolate.WhenCalled(()=> fake.OrderLineNumber).WillReturn(returnValu
return fake;
};
// ...
// here is the list that you built in the delegate
List<OrderLine> mockedOrderLine = SomeClass.SomeMethod();
// call to OrderLineNumber from some index in the mockedOrderLine
//..
//Here you verify only for OrderLine that is in index 1 OrderLineNumber was called
Isolate.Verify.WasCalledWithAnyArguments(()=> mockedOrderLine[1].OrderLineNumber);
2. If for some reason you can't use the new API you can use the following
solution:
The MockObject class has its own Verify method method which will do verification only on the instance it controls.
The problem here is the MockObjects are created inside the delegate and are not saved.
If you will save the MockObjects in a different list you can use it to verify
that only specific index index was called:
List<MockObject> mockList = new List<MockObject>();
//...
ListEntryCreatorDelegate myListEntryCreator = delegate(int returnValue)
{
MockObject mockedOL =
MockManager.MockObject(typeof(OrderLine));
mockedOL.ExpectGet("OrderLineNumber", returnValue);
OrderLine myOrderLine = (OrderLine)mockedOL.Object;
//save the MockObject
mockList.Add(mockedOL);
return myOrderLine;
};
// ...
// here is the list that you built in the delegate
List<OrderLine> mockedOrderLine = SomeClass.SomeMethod();
// call to OrderLineNumber from some index in the mockedOrderLine
//..
//Use the MockObject list to Verify only on index 1 that OrderLineNumber was called
mockList[1].Verify();
:idea: you can save only the MockObject that you want to make the verification on if you know what index it will be when the delegate is called.