var contextChannel = this.MockRepository.Stub<IContextChannel>();
var context = this.MockRepository.Stub<IOperationContext>();
context.Stub(x => x.Channel).Return(contextChannel);
context.Replay();
What is Replay for?
I understand that in the case of recording and then playing back an action, the Replay() call is necessary. But it is unclear to me why I am forced to write one more line of code in the case where I do not record anything. All I need is a property which returns my object.
Update:
You are not using the AAA syntax properly. You don’t need an instance to the MockRepository anymore (this had been used for Rhino before 3.5). Just call the static methods on MockRepository:
Here is some documentation:
Original Answer
You don’t. There is not need to call
Replayin a situations like yours anymore.In previous versions, there was a “record-replay” paradigm, where you recorded expectations and replayed them during the test. It had been replaced by the AAA syntax, where you can much easier and more flexible set up mocks.
Behind the scenes, there is still a record and replay state of the mock. Methods like
Stubare putting the mock into record state, configure it, and put them back to record. You don’t need to callRecordexplicitly in these cases.If you want to do some more advanced operations, you can set the mock to replay state yourself, do something with it, eg. in order to reset expectations: