How to emulate the following behaviour using RhinoMocks?
The tested method invokes ReceivePayment method on an interface.
public void TestedMethod(){
bool result = interface.ReceivePayment();
}
Interface has the CashAccepted event. ReceivePayment shoud return true if this event has been invoked several times (or by a condition).
How to accomplish such a task?
update.
Now I do the following:
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 returns immediately since there is a task launch inside. But the next line: paymentSysProvider.Raise(...) is waiting for the completion of the ReceivePayment stub!