加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 01:36:13 所属栏目:百科 来源:网络整理
导读:是否可以测试使用Rhino Mocks 3.5未调用属性设置器? 解决方法 这完全有可能: public class OneProperty{ virtual public int MyInt { get; set; }}[Test]public void IntWasSet(){ var prop = Rhino.Mocks.MockRepository.GenerateMockOneProperty(); prop
是否可以测试使用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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读