什么是模拟录制和回放?
我有一个模拟如下:
MockRepository mocks = new MockRepository();
ILoanRepository loanRepo = mocks.StrictMock<ILoanRepository>();
SetupResult.For(loanRepo.GetLoanExtended("sdfsdf")).Return(list.AsEnumerable<Loan>());
mocks.ReplayAll();
我的问题是我已经看到上面的内容被用于 using 语句,例如
using (mocks.Record()) { // code here }
using (mocks.Playback()) { // code here }
这样做的目的是什么以及与我所做的有何不同?
I have a mock as 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 have seen the above being used in using statements e.g
using (mocks.Record()) { // code here }
using (mocks.Playback()) { // code here }
What is the purpose of this and difference to what I've done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这些只是做同样事情的另一种语法。以下是等效的:
和:
为了使事情变得更加复杂,有一种新的第三种语法,您不需要明确的记录和播放阶段,称为排列、动作、断言语法,请参见例如 http://ayende.com/blog/archive/2008/ 05/16/rhino-mocks--arrange-act-assert-syntax.aspx
These are just another syntax to do the same thing. The following are equivalent:
and:
To make things even more complicated there is a new, third syntax where you don't have explicit record and playback phases called Arrange, Act, Assert Syntax, see e.g. http://ayende.com/blog/archive/2008/05/16/rhino-mocks--arrange-act-assert-syntax.aspx
Record 块用于记录期望,因此 ReplayAll 之前的内容。
Playback 块实际上是在调用测试,所以 ReplayAll 之后会发生什么。
您可以在这里阅读更多相关信息:链接文本
The Record block is used to record expectations, so what comes before the ReplayAll.
The Playback block is actually calling the test, so what comes after the ReplayAll.
You can read more about it here: link text