Hello. I have the following SharePoint code, that i want to fake.
SPList list = web.Lists[listId];
SPListItem item = list.Items.Add();
item["Title"] = listItemTitle;
item.Update();
item["Title"] is an indexer:
// Microsoft.SharePoint.SPListItem
public override object this[string fieldName]
{
get
{
return this.GetValue(fieldName);
}
set
{
this.SetValue(fieldName, value, !this.HasExternalDataSource);
}
}
Question: How can i fake/ intercept the call to SetValue to verify that this method was called with the correct parameter?
I will do interactions testing.
Here is my Isolator code
SPWeb fakeWeb = Isolate.Fake.Instance<SPWeb>(Members.ReturnRecursiveFakes);
Isolate.Swap.NextInstance<SPWeb>().With(fakeWeb);
SPListItem fakeSpListItem = fakeWeb.Lists[Guid.Empty].Items.Add();
Isolate.WhenCalled(() => fakeSpListItem["Title"]).WillReturn("test");
//Assert
Isolate.Verify.NonPublic.WasCalled(fakeSpListItem, "SetValue");
But get an error message:
ypeMock.VerifyException:
TypeMock Verification: Method Microsoft.SharePoint.SPListItem.SetValue() was expected but was not called
Result StackTrace: