Hi and Welcome to our forums!
Faking list behavior is a bit more complex than faking straightforward methods - lists (collections in general) mix state and behavior that would take a bit of work to fake explicitly. In Isolator we provide a mechanism to replace your collection with any test data collection - this way you can control the collection the code under test will access, and you can be assured that the collection's complete behavior refers to the test data. This is done using the WhenCalled().WillReturnCollectionValuesOf() method:
var fakeListItem1 = Isolate.Fake.Instance<SPListItem>();
var fakeListItem2 = Isolate.Fake.Instance<SPListItem>();
var testData = new SPListItem[] { fakeListItem1, fakeListItem2 };
Isolate.WhenCalled(() => web.Lists["List"]).WillReturnCollectionValuesOf(testData);
Another way to control the behavior of collections, is to go ahead and set the behavior of the list items. A backing list will be automatically populated for your use:
Isolate.WhenCalled(() => web.Lists["List"][0].Name).WillReturn("Name1");
Isolate.WhenCalled(() => web.Lists["List"][2].Name).WillReturn("Name3");
:!: The backing list created in this technique will always be large enough to iterate through - in this case list items 0 and 2 will have specific behavior set on their Name property, and item 1 is automatically created as a recursive fake.
:!: You can find examples to similar scenarios in SharePoint in our SharePoint example solution - check it out under the program files shortcut group that was installed with Isolator.
:!: Final quick tip - you can drop the Members.ReturnRecursiveFakes when creating a fake instance - ReturnRecursiveFakes is the default behavior for Fake.Instance.
I hope this helps - please follow up and let me know if my description above answered all your questions. Welcome again to Isolator - let us know if you need anything else.
Doron
Typemock Support