1

Can I set a return value of a setter-less property of a stub that is created by Rhino.Mocks?

For example:

public interface IMyMachine { string myProperty { get; } }

...

IMyMachine m = MockRepository.GenerateMock<IMyMachine>();

// implement in a way so that m.myProperty will return "Ahoj!"
if (m.myProperty == "Ahoj!")
 //do something
pencilCake
  • 51,323
  • 85
  • 226
  • 363

1 Answers1

5
m.Expect(x => x.myProperty).Return("abc");

or if you use a stub:

var m = MockRepository.GenerateStub<IMyMachine>();
m.Stub(x => x.myProperty).Return("abc");
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • Is it different than this one: http://stackoverflow.com/questions/78389/rhinomocks-correct-way-to-mock-property-getter – pencilCake Oct 03 '11 at 15:15