Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 529
Ilya Kogan Avatar asked Mar 15 '11 10:03

Ilya Kogan


1 Answers

use this:

unitOfWorkStub.Stub(x => x.DoInTransaction(Arg<Action>.Is.Anything))
              .WhenCalled(x => ((Action)x.Arguments[0])());
like image 57
Daniel Hilgarth Avatar answered Sep 22 '22 13:09

Daniel Hilgarth