验证属性从未使用Moq设置 [英] Verify property is never set using Moq
本文介绍了验证属性从未使用Moq设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
Moq-如何验证通过设置器设置属性值
Possible Duplicate:
Moq - How to verify that a property value is set via the setter
我希望以下测试失败:
public interface IObjectWithProperty
{
int Property { get; set; }
}
[TestMethod]
public void Property_ShouldNotBeCalled()
{
var mock = new Mock<IObjectWithProperty>();
mock.Object.Property = 10;
mock.Verify(x => x.Property, Times.Never());
}
但是,即使在Verify
之前的行中清楚地访问了Property
,该测试仍通过.
However, this test passes, even though Property
is clearly accessed on the line before the Verify
.
所以看来Verify
实际上是指VerifyGet
.
我应该如何验证从未设置过属性?
How should I verify that a property is never set?
推荐答案
请改用以下代码:
mock.VerifySet(x => x.Property = It.IsAny<int>(), Times.Never());
这篇关于验证属性从未使用Moq设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文