如何使用Rhino Mocks在VB.NET中为模拟对象引发事件

时间:2013-05-22 21:42:25

标签: vb.net events mocking rhino-mocks

我知道如何在C#中执行此操作:(来自docs

view.Raise(x => x.Load += null, this, EventArgs.Empty);

我尝试了以下内容:

Me.MockObject.Raise(Sub(x) x.SomeEvent(), someArgs)

'Compiler Error: 
'SomeEvent is an event, and cannot be called directly.
'Use a RaiseEvent statement to raise an event.

我尝试用Sub(x)替换Function(x) ...也没有运气。所以尝试了:

Me.MockObject.Raise(Sub(x) x.SomeEvent(), someArgs)

'Compiler Error
'x is not an event of MyTestFixtureClass

糟糕...

我似乎无法在VB.NET中弄明白......任何提示?

1 个答案:

答案 0 :(得分:3)

我几乎就在那里......这是有效的:

Me.MockObject.Raise(Sub(x) AddHandler x.SomeEvent, Nothing, someArgs)

我不确定为什么我要添加Nothing作为事件的事件处理程序,所有这些的内部机制都超出了我的范围。