gpt4 book ai didi

c# - 验证属性从未使用 Moq 设置

转载 作者:行者123 更新时间:2023-11-30 13:17:12 24 4
gpt4 key购买 nike

<分区>

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,此测试也通过了。

所以看起来Verify实际上意味着VerifyGet

我应该如何验证一个属性从未被设置?

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com