Rhino Mocks 3.5测试没有调用属性setter

MTE*_*TEd 3 c# rhino-mocks

是否可以测试使用Rhino Mocks 3.5未调用属性设置器?

Mar*_*off 5

这完全有可能:

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();
}
Run Code Online (Sandbox Code Playgroud)

在Rhino Mocks 3.5上运行此测试会导致以下错误:

错误和失败:1)测试错误:InterfacerTests.TestMatchesInterface.IntWasSet Rhino.Mocks.Exceptions.ExpectationViolationException:期望OneProperty.set_MyInt(任何东西); 不会被调用,但它是在模拟对象上进行的实际调用中找到的.

从Rhino文档的这一部分中发现了Arg<T>语法.