繁体   English   中英

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

[英]Rhino Mocks 3.5 Test that property setter was not called

是否可以测试使用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上运行此测试会导致以下错误:

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

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

将属性设置为测试中的某个已知值。 调用不会更改属性的代码,然后断言该属性与它相同。 不应该为此使用Rhino Mocks。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM