我可以设置由Rhino.Mocks创建的存根的无setter属性的返回值吗?
例如:
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
答案 0 :(得分:5)
m.Expect(x => x.myProperty).Return("abc");
或者如果你使用存根:
var m = MockRepository.GenerateStub<IMyMachine>();
m.Stub(x => x.myProperty).Return("abc");