0
当我运行下面的测试:获取异常
[TestMethod]
public void MyTest()
{
var wizardCatalog = MockRepository.GenerateStub<IWizardCatalog>();
var firstQuestion = MockRepository.GenerateStub<IWizardQuestion>();
wizardCatalog.Stub(i => i.GetFirstQuestion()).Return(firstQuestion);
var choices = new List<IWizardChoice>();
firstQuestion.Stub(i => i.Choices).Return(choices);
}
我得到这个异常:
您正在尝试设置被定义为 使用上的属性的期望PropertyBehavior。而不是像这样编写代码: mockObject.Stub(x => x.SomeProperty).Return(42);您可以直接使用 属性来实现相同的结果:mockObject.SomeProperty = 42;
一切我读告诉我,这个短线操作是有效的:
var choices = new List<IWizardChoice>();
firstQuestion.Stub(i => i.Choices).Return(choices);
这是怎么回事?
我不能使用该语法,因为'Choices'是只读的。 – Jordan
这对我有效。我希望在Rhino Mocks上有一个很好的播放或者什么的。文档相当稀少。 – Jordan