简体   繁体   English

犀牛嘲笑。 如何添加订阅事件处理程序的期望

[英]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 我正在尝试使用RhinoMocks和MockRepository.VerifyAll()测试这些东西抛出以下异常

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

So the question: 所以问题是:

How to add the expectation that event is subscribed? 如何添加订阅事件的期望?

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. 在创建Presenter的新实例之前,我不得不重播。

Thanks. 谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM