Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rhino Mocks. How to add expectation that event handler was subscribed

I have an interface like that:

interface IView
{
     event EventHandler<MyEventArgs> SomeEvent;
}

and a class

class Presenter
{
     private IView _view;
     public Presenter(IView view)
     {
         view.SomeEvent += MyEventHandler;
     }

     private MyEventHandler(...)
}

I'm trying to test this stuff using RhinoMocks and MockRepository.VerifyAll() throws the following exception

Rhino.Mocks.Exceptions.ExpectationViolationException: IView.add_SomeEvent(System.EventHandler`1[MyEventArgs]); Expected #1, Actual #0.

So the question:

How to add the expectation that event is subscribed?

like image 763
Eugene Avatar asked Oct 08 '22 15:10

Eugene


1 Answers

Sorry guys, I have found what I was doing wrong:

_viewMock.Expect(x => x.SomeEvent+= Arg<EventHandler<MyEventArgs>>.Is.Anything); 

Presenter p = new Presenter(_viewMock);

_mockRepository.ReplayAll();

...

_mockRepository.VerifyAll();

I had to ReplayAll before I created new instance of Presenter.

Thanks.

like image 51
Eugene Avatar answered Oct 13 '22 00:10

Eugene