如何使用RhinoMocks模擬以下行爲?如何在RhinoMocks中通過指定的條件返回方法的值?
被測試的方法在接口上調用ReceivePayment方法。
public void TestedMethod(){
bool result = interface.ReceivePayment();
}
接口有CashAccepted事件。 如果此事件已被多次調用(或通過條件),ReceivePayment shoud將返回true。
如何完成這樣的任務?
更新。
現在我做到以下幾點:因爲裏面有一個任務發佈
UpayError error;
paymentSysProvider.Stub(i => i.ReceivePayment(ticketPrice,
App.Config.SellingMode.MaxOverpayment, uint.MaxValue, out error))
.Do(new ReceivePaymentDel(ReceivePayment));
paymentSysProvider.Stub(x => x.GetPayedSum()).Return(ticketPrice);
session.StartCashReceiving(ticketPrice);
paymentSysProvider.Raise(x => x.CashInEvent += null, cashInEventArgs);
public delegate bool ReceivePaymentDel(uint quantityToReceive, uint maxChange, uint maxTimeout, out UpayError error);
public bool ReceivePayment(uint quantityToReceive, uint maxChange, uint maxTimeout, out UpayError error) {
Thread.Sleep(5000);
error = null;
return true;
}
StartCashReceiving立即返回。 但是下一行:paymentSysProvider.Raise(...)正在等待ReceivePayment存根的完成!
非常感謝。恩......好吧,我試圖測試這個類的複雜行爲。如果指定的條件得到滿足,ReceivePayment必須返回true。爲了滿足條件,我必須提高CashAccepted事件。 – EngineerSpock