Hi Guillaume,
It confused us a bit. While Isolator cannot fake objects within mscorlib, like List, it can definitely return them. So according to your code, you can replace the real ListOfClass1, with another real one, but initialized differently.
So a test will look like this:
[TestMethod]
public void ReturnListFromLoad()
{
// Set up a real ListOfClass1, containing fake Class1 objects
var firstFake = Isolate.Fake.Instance<Class1>();
var secondFake = Isolate.Fake.Instance<Class1>();
ListOfClass1 otherList = new ListOfClass1() {firstFake, secondFake};
// Replace the returned list , the actual Load method doesn't get called.
Isolate.WhenCalled(() => ListOfClass1.Load()).WillReturn(otherList);
// Now run the under test code.
var returnedlist = ListOfClass1.Load();
var didItWork = false;
foreach (var class1 in returnedlist)
{
didItWork = true;
}
Assert.IsTrue(didItWork);
}
Does this help?
Gil