Jeff B
Jeff B

Reputation: 8982

How to raise event on a mocked object in VB.NET with Rhino Mocks

I know how to do it in C#: (from the docs)

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

I tried the following:

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.

I tried replacing Sub(x) with Function(x)... no luck either. So tried:

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

'Compiler Error
'x is not an event of MyTestFixtureClass

Oops...

I can't seem to figure it out in VB.NET... any tips?

Upvotes: 1

Views: 319

Answers (1)

Jeff B
Jeff B

Reputation: 8982

I was almost there... here's what works:

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

Not sure why I'm adding Nothing as the eventhandler for the event, the internal mechanics of all this is beyond me.

Upvotes: 3

Related Questions