I'm having trouble raising an event in a unit test using VB.NET and NSubstitute. The interface being mocked defines an event:
Event BlockOfVehiclesProcessed(source As Object, stats As ProcessingStats)
The class under test registers a handler for the event. In the unit test, I want to raise the event so the handler in the class under test gets invoked. Based on the NSubstitute documentation (all C#, unfortunately) and various answers on Stackoverflow, etc., I tried various permutations of this:
AddHandler mock.BlockOfVehiclesProcessed, Raise.EventWith(New ProcessingStats(50))
But I haven't found anything that compiles. One error message:
Value of type 'EventHandlerWrapper(...)' cannot be converted to '...BlockOfVehiclesProcessedEventHandler'
I tried passing 0 args and 2 args to EventWith(), I tried specifying the type arg explicitly for EventWith(), and I tried Raise.Event(), but I can't find the magic sequence to make the compiler happy. Does anyone have an example of a working VB unit test that raises an event?