Search code examples
c#rhino-mocks

How can I call a callback in a Rhino Mock'd object?


I know there has to be a way to do this...I'm just new to RhinoMocking.

Essentially, I have the following class:

class B
{
     private object _dependency;

     public B(object dependency)
     {
          _dependency = dependency;
     }

     public void Method()
     {
         dependency.DependencyMethod(delegate(){ Method2(); });
     }

     private void Method2()
     {
         // do stuff
     }
}

I'm passing a rhino mocked, interface as a dependency in my test. I want to test Method2 in my test...but its private, so the only way to get at it is by looking at the argument to DependencyMethod. How do I do that? :P

Thanks!


Solution

  • So after digging around, I think the best way to do this is to use GetArgumentsForCallsMadeOn on my mock, to grab the delegate that way and then call it.