本文介绍了犀牛制品AssertWasCalled(多次)使用AAA属性的getter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个构造函数参数到另一个对象通过的嘲笑对象。



如何测试一个嘲笑对象的属性已叫什么名字?这是我目前使用的代码:

  INewContactAttributes newContact = MockRepository.GenerateMock< INewContactAttributes>(); 
newContact.Stub(X => x.Forenames).Return(一二三);
someobject.ConsumeContact(newContact);
newContact.AssertWasCalled(X => {VAR哑= x.Forenames;});

这工作的时候,someobject关于Forenames属性的getter内多次使用情况除外。这时候,我得到的Rhino.Mocks.Exceptions.ExpectationViolationException:INewContactAttributes.get_Forenames();预计#1,#实际.. 2



只需用



  newContact.AssertWasCalled(X => {VAR哑= x.Forenames;},选择= GT; options.Repeat.Any()) ; 



不工作,并给出以下错误:

的预期从等待名单的预期)去掉,你叫Repeat.Any(?这不是在AssertWasCalled()的支持。

那么,如何?我应付多次调用


解决方案

newContact.AssertWasCalled(X => {VAR假= x.Forenames;},选择= GT; options.Repeat.AtLeastOnce());



重复。任何 AssertWasCalled 工作,因为0计数任何...因此,如果它不叫,在 AsserWasCalled 将返回TRUE即使它不叫。


I have a mocked object that is passed as a constructor argument to another object.

How can I test that a mocked object's property has been called? This is code I am using currently:

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

This works except when within the "someobject" the getter on Forenames property is used multiple times. That's when I get "Rhino.Mocks.Exceptions.ExpectationViolationException: INewContactAttributes.get_Forenames(); Expected #1, Actual #2.."

Simply using

newContact.AssertWasCalled(x => { var dummy = x.Forenames; }, options => options.Repeat.Any());

does not work and gives the error below:

"The expectation was removed from the waiting expectations list, did you call Repeat.Any() ? This is not supported in AssertWasCalled()."

So how do I cater for the multiple calls?

解决方案

newContact.AssertWasCalled(x => { var dummy = x.Forenames; }, options => options.Repeat.AtLeastOnce());

Repeat.Any does not work with AssertWasCalled because 0 counts as any... so if it WASN'T called, the AsserWasCalled would return TRUE even if it wasn't called.

这篇关于犀牛制品AssertWasCalled(多次)使用AAA属性的getter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 17:48