打桩用犀牛制品只读属性 [英] Stubbing a read only property with Rhino Mocks

查看:180
本文介绍了打桩用犀牛制品只读属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类,我想存根用犀牛制品的私人集财产。当我尝试这样做,但是,它给了我一个编译时错误,说我不能设置只读属性。我是新来使用犀牛制品,所以我必须在这里失去了一些东西......

 公共接口的IFoo
{
    INT数量{获得; }
}

[测试方法]
公共无效SomeTest()
{
    IFoo的富= MockRepository.GenerateStub<的IFoo>();
    foo.Quantity = 5;

    //断言和这样的
}
 

解决方案

使用:

  foo.Stub(F => f.Quantity).Return(5);
 

请参阅<一href="http://ayende.com/Wiki/Rhino+Mocks+3.5.ashx#UsingExpecttosetupproperties">http://ayende.com/Wiki/Rhino+Mocks+3.5.ashx#UsingExpecttosetupproperties

您也可以使用:

  foo.Expect(F =&GT; f.Quantity).Return(5);
 

I have a class with a private set property that I want to stub out with rhino mocks. When I try to do this, though, it gives me a compile time error saying I can't set a read only property. I'm new to using Rhino Mocks so I must be missing something here...

public Interface IFoo
{
    int Quantity { get; }
}

[TestMethod]
public void SomeTest()
{
    IFoo foo = MockRepository.GenerateStub<IFoo>();
    foo.Quantity = 5;

    //Asserts and such
}

解决方案

Use:

foo.Stub (f => f.Quantity).Return (5);

See http://ayende.com/Wiki/Rhino+Mocks+3.5.ashx#UsingExpecttosetupproperties

You can also use:

foo.Expect(f => f.Quantity).Return (5);

这篇关于打桩用犀牛制品只读属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆