相关疑难解决方法(0)

使用AAA的Rhino Mocks AssertWasCalled(多次)在属性getter上

我有一个模拟对象作为构造函数参数传递给另一个对象.

如何测试已调用模拟对象的属性?这是我目前使用的代码:

INewContactAttributes newContact = MockRepository.GenerateMock<INewContactAttributes>();
newContact.Stub(x => x.Forenames).Return("One Two Three");
someobject.ConsumeContact(newContact);
newContact.AssertWasCalled(x => { var dummy = x.Forenames; });
Run Code Online (Sandbox Code Playgroud)

这有效,除非在"someobject"中,Forenames属性的getter被多次使用.那时我得到"Rhino.Mocks.Exceptions.ExpectationViolationException:INewContactAttributes.get_Forenames();期望#1,实际#2 .."

简单地使用

newContact.AssertWasCalled(x => { var dummy = x.Forenames; }, options => options.Repeat.Any());
Run Code Online (Sandbox Code Playgroud)

不起作用,并给出以下错误:

"期望已从等待期望列表中删除,您是否调用了Repeat.Any()?AssertWasCalled()不支持这种情况."

那么我该如何迎合多次通话呢?

c# getter unit-testing rhino-mocks properties

51
推荐指数
2
解决办法
2万
查看次数

标签 统计

c# ×1

getter ×1

properties ×1

rhino-mocks ×1

unit-testing ×1