2011-10-03 50 views
1

我可以设置由Rhino.Mocks创建的存根的setter-less属性的返回值吗?如何在存根上设置一个没有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 

回答

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

,或者如果您使用的是存根:

var m = MockRepository.GenerateStub<IMyMachine>(); 
m.Stub(x => x.myProperty).Return("abc"); 
+0

它是不同的不止这一个:http://stackoverflow.com/questions/78389/rhinomocks -correct路到模拟属性的getter – pencilCake

相关问题