Use the following code instead:
mock.VerifySet(x => x.Property = It.IsAny<int>(), Times.Never());
Question
Possible Duplicate:
Moq - How to verify that a property value is set via the setter
I would expect the following test to fail:
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());
}
However, this test passes, even though Property
is clearly accessed on the line before the Verify
.
So it seems that Verify
actually means VerifyGet
.
How should I verify that a property is never set?
Solution
Use the following code instead:
mock.VerifySet(x => x.Property = It.IsAny<int>(), Times.Never());