How to use the real parameters when creating a stub method in RhinoMocks?

◇◆丶佛笑我妖孽 提交于 2021-02-06 11:28:03

问题


I want to create a stub of the following interface:

interface IUnitOfWork
{
   void DoInTransaction(Action method);
}

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

Something like:

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

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


回答1:


use this:

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


来源:https://stackoverflow.com/questions/5310486/how-to-use-the-real-parameters-when-creating-a-stub-method-in-rhinomocks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!