Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stubbing a read only property with Rhino Mocks

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 } 
like image 675
JChristian Avatar asked Jan 19 '10 00:01

JChristian


1 Answers

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); 
like image 75
Pete Avatar answered Sep 21 '22 05:09

Pete