在 RhinoMocks 中创建存根方法时如何使用实参? [英] How to use the real parameters when creating a stub method in RhinoMocks?

查看:53
本文介绍了在 RhinoMocks 中创建存根方法时如何使用实参?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建以下接口的存根:

I want to create a stub of the following interface:

interface IUnitOfWork
{
   void DoInTransaction(Action method);
}

在存根对象中,我想让 DoInTransaction 做的就是运行 method().

In the stub object, all I want DoInTransaction to do is run method().

类似于:

// pseudo-code
unitOfWorkStub.Stub(x => x.DoInTransaction(method)).Do(method()) 

是否可以使用 RhinoMocks 创建这种存根?这怎么办?

Is it possible to create this kind of a stub with RhinoMocks? How can this be done?

推荐答案

使用这个:

unitOfWorkStub.Stub(x => x.DoInTransaction(Arg<Action>.Is.Anything))
              .WhenCalled(x => ((Action)x.Arguments[0])());

这篇关于在 RhinoMocks 中创建存根方法时如何使用实参?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆