我写起订量使用单元测试。 我创建了一个模拟对象。 现在,当我尝试嘲笑其属性我得到错误“的表达式树不能包含索引属性”
这里是我的代码。
public Node GetNode(IMyInterface interface, string itemName)
{
return interface.Items[itemName];
}
这里是单元测试
var expected = new Node();
var itemName = "TestName";
var mock = new Mock<IMyInterface>();
mock.Setup(f => f.Items[itemName]).Returns(expected);
var target = new MyClass();
var actual = target.GetNode(mock.Object, itemName);
Assert.AreEqual(expected, actual);
此行是给我的错误。
mock.Setup(f => f.Items[itemName]).Returns(expected);
我怎样才能MOQ此功能。