我有一个模拟对象,它作为构造函数参数传递给另一个对象。
如何测试已调用模拟对象的属性?这是我目前使用的代码:
INewContactAttributes newContact = MockRepository.GenerateMock<INewContactAttributes>();
newContact.Stub(x => x.Forenames).Return("One Two Three");
someobject.ConsumeContact(newContact);
newContact.AssertWasCalled(x => { var dummy = x.Forenames; });
这有效,除非在“someobject”内多次使用 Forenames 属性的 getter。那是我得到“Rhino.Mocks.Exceptions.ExpectationViolationException: INewContactAttributes.get_Forenames(); 预期 #1,实际 #2 ..”的时候
只需使用
newContact.AssertWasCalled(x => { var dummy = x.Forenames; }, options => options.Repeat.Any());
不起作用并给出以下错误:
“期望已从等待期望列表中删除,您是否调用了 Repeat.Any() ? AssertWasCalled() 不支持此操作。”
那么如何满足多个呼叫的需求呢?