Is it possible to test that a property setter has not been called using Rhino Mocks 3.5?
+1
A:
Set the property to some known value in the test. Call the code that won't change the property, then assert that the property is the same as it was. Shouldn't need to use Rhino Mocks for that.
RichK
2010-05-25 10:46:23
+3
A:
This is entirely possible:
public class OneProperty
{
virtual public int MyInt
{
get;
set;
}
}
[Test]
public void IntWasSet()
{
var prop = Rhino.Mocks.MockRepository.GenerateMock<OneProperty>();
prop.MyInt = 5;
prop.AssertWasNotCalled(x => x.MyInt = Arg<int>.Is.Anything);
prop.VerifyAllExpectations();
}
Running this test on Rhino Mocks 3.5 results in the following error:
Errors and Failures: 1) Test Error : InterfacerTests.TestMatchesInterface.IntWasSet Rhino.Mocks.Exceptions.ExpectationViolationException : Expected that OneProperty.set_MyInt(anything); would not be called, but it was found on the actual calls made on the mocked object.
I discovered the Arg<T>
syntax from this part of the Rhino documentation.
Mark Rushakoff
2010-05-25 11:24:50