【发布时间】:2014-03-06 16:43:35
【问题描述】:
我正在从 TypeMock 迁移到 MS Fakes。在 TypeMock 中,我可以做这样的事情:
var fakeItem = Isolate.Fake.Instance<SPListItem>();
//some testing foo that uses the fake item Eg.
MethodUnderTest(fakeItem);
Assert.AreEqual(fakeItem["someField"], expected, "Field value was not set correctly");
在我的断言中,我可以检索由我的测试 foo 设置的字段值,并将其与我的预期进行比较。
使用 MS Fakes 时,我会这样做:
var fakeItem = new ShimSPListItem()
{
//delegates in here
};
//some testing foo that uses the shim. Eg.
MethodUnderTest(fakeItem);
这一次我尝试检查我的值是否已设置为:
Assert.AreEqual(fakeItem["someField"], expected, "Field value was not set correctly");
我最终得到一个编译错误:
Cannot apply indexing with [] to an expression of type 'Microsoft.SharePoint.Fakes.ShimSPListItem'
在 SharePoint 世界中,这样的索引几乎是标准做法,我的测试代码确实可以做到,并且似乎可以正常工作,没有任何问题。我的问题是为什么我不能在我的测试中做到这一点?我已经尝试将 shim 投射到 SPListItem 但这是不允许的 - 我想我在这里遗漏了一些东西。有什么想法吗?
【问题讨论】:
标签: sharepoint microsoft-fakes typemock