当前位置 : 主页 > 编程语言 > c语言 >

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

来源:互联网 收集:自由互联 发布时间:2021-06-25
是否可以测试使用Rhino Mocks 3.5未调用属性设置器? 这完全有可能: public class OneProperty{ virtual public int MyInt { get; set; }}[Test]public void IntWasSet(){ var prop = Rhino.Mocks.MockRepository.GenerateMockOnePr
是否可以测试使用Rhino Mocks 3.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();
}

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

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.

我发现了Arg< T>语法from this part of the Rhino documentation.

网友评论