开发者

Rhino Mocks 3.5 Test that property setter was not called

Is it possible to test that a property setter 开发者_如何学运维has not been called using Rhino Mocks 3.5?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜