What is Mocks recording and playback?

I have a layout as shown below:

MockRepository mocks = new MockRepository();
ILoanRepository loanRepo = mocks.StrictMock<ILoanRepository>();
SetupResult.For(loanRepo.GetLoanExtended("sdfsdf")).Return(list.AsEnumerable<Loan>());
mocks.ReplayAll();

My question is: I saw that the above is used when using statements like

using (mocks.Record()) { // code here }
using (mocks.Playback()) { // code here }

What is the purpose of this and the difference in what I have done?

+3
source share
2 answers

This is just another syntax to do the same. The following equivalents:

MockRepository mocks = new MockRepository();
ILoanRepository loanRepo = mocks.StrictMock<ILoanRepository>();
SetupResult.For(loanRepo.GetLoanExtended("sdfsdf")).Return(list.AsEnumerable<Loan>());
mocks.ReplayAll();
//test execution

and

MockRepository mocks = new MockRepository();
using (mocks.Record()) {
    ILoanRepository loanRepo = mocks.StrictMock<ILoanRepository>();
    SetupResult.For(loanRepo.GetLoanExtended("sdfsdf")).Return(list.AsEnumerable<Loan>());
}
using (mocks.Playback()) {
    //test execution
}

To make things even more complex, there is a new third syntax in which you do not have explicit recording and playback phases called Arrange, Act, Assert Syntax, see for example http://ayende.com/blog/archive/2008/ 05/16 / rhino-mocks - arrange-act-assert-syntax.aspx

+1
source

Record , ReplayAll.

, ReplayAll.

:

+1

Source: https://habr.com/ru/post/1753668/


All Articles