开发者

Stubbing a read only property with Rhino Mocks

开发者 https://www.devze.com 2022-12-16 16:14 出处:网络
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

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 somet开发者_开发问答hing 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);


You can just do:

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

精彩评论

暂无评论...
验证码 换一张
取 消