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?
Verifies that all verifiable expectations have been met.
Unit testing is a powerful way to ensure that your code works as intended. It's a great way to combat the common “works on my machine” problem. Using Moq, you can mock out dependencies and make sure that you are testing the code in isolation.
Use the following code instead:
mock.VerifySet(x => x.Property = It.IsAny<int>(), Times.Never());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With