I have a utility method to create a populated SPList:
private SPList MakeFakeList(int itemCount)
{
SPList fakeList = Isolate.Fake.Instance<SPList>();
for (int i = 1; i <= itemCount; i++)
{
Isolate.WhenCalled(() => fakeList.Items[i])
.WillReturn(MakeFakeTaskItem(i, "This is task number " + i.ToString()));
Isolate.WhenCalled(() => fakeList.GetItemById(i))
.WithExactArguments()
.WillReturn(MakeFakeTaskItem(i, "This is task number " + i.ToString()));
}
return fakeList;
}
I can return a specific item using either .Items[n] or .GetItemByID(n), and it works fine. But I can't get the .ListCount value. Here's my test:
[Test]
public void FakeList_ItemCount()
{
SPList spList = MakeFakeList(10);
Assert.That(spList.ItemCount, Is.EqualTo(10));
}
It fails with:
LSMSTests.Tests.FakeList_ItemCount:
Expected: 10
But was: 0
As a sanity check, I tried this simpler test, which doesn't use my utility method at all:
[Test]
public void MakeFakeList_AddItem_ItemCount()
{
var fakeList = Isolate.Fake.Instance<SPList>(Members.ReturnRecursiveFakes);
SPListItem spListItem = fakeList.AddItem();
Assert.That(fakeList.ItemCount, Is.EqualTo(1));
}
But it fails also:
LSMSTests.Tests.MakeFakeList_AddItem_ItemCount:
Expected: 1
But was: 0
I'm trying to fake a SharePoint list that can have items added to it -- not just have it return a fake list item, but also behave like a real SharePoint list that has had an item added -- i.e. report an accurate .ListCount, and actually contain the newly added item. Am I going beyond what TypeMock is designed to do?