7

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

interface IUnitOfWork
{
   void DoInTransaction(Action method);
}

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

就像是:

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

是否可以使用 RhinoMocks 创建这种存根?如何才能做到这一点?

4

1 回答 1

16

用这个:

unitOfWorkStub.Stub(x => x.DoInTransaction(Arg<Action>.Is.Anything))
              .WhenCalled(x => ((Action)x.Arguments[0])());
于 2011-03-15T10:44:42.287 回答