【发布时间】:2009-07-24 19:40:03
【问题描述】:
试图了解 verifySet 等的使用......但除非我采取解决方法,否则我无法让它工作。
public interface IProduct
{
int Id { get; set; }
string Name { get; set; }
}
public void Can_do_something()
{
var newProduct = new Mock<IProduct>();
newProduct.SetupGet(p => p.Id).Returns(1);
newProduct.SetupGet(p => p.Name).Returns("Jo");
//This fails!! why is it because I have not invoked it
newProduct.VerifySet(p => p.Name, Times.AtLeastOnce());
//if I do this it works
newProduct.Object.Name = "Jo";
newProduct.VerifySet(p => p.Name, Times.AtLeastOnce());
}
有人可以澄清我应该如何在属性上使用 VerifySet 和 Verify 和 VerifyGet 吗? 我越来越糊涂了。
【问题讨论】:
标签: unit-testing mocking moq