I am attempting to test that the event handlers between an interface and controller are wired properly. The system is set up like the example below:
'Interface for Display
Public Interface IClientLocationView
Event LocationChanged(ishomelocation as Boolean)
Sub DisplayChangesWhenHome(arg1 as Object, arg2 as Object)
Sub DisplayChangesWhenNotHome(arg1 as Object, arg2 as Object, arg3 as Object)
End Interface
'Controller
Public Class ClientLocationController
Public Sub Start(_view as IClientLocationView)
AddHandler _view.LocationChanged, AddressOf LocationChangedHandler
End Sub
Public Sub LocationChangedHandler(ishomelocation as Boolean)
If ishomelocation Then
_view.DisplayChangesWhenHome(arg1, arg2)
Else
_view.DisplayChangesWhenNotHome(arg2, arg1, arg3)
End If
End Sub
End Class
How do I raise the event with the boolean parameter so that I can test each of the code paths contained within the event handler. I'm not having any luck with the syntax shown on the Google Code homepage.
AddHandler foo.SomethingHappened, AddressOf Raise.With(EventArgs.Empty).Now
'If the event is an EventHandler(Of T) you can use the shorter syntax:'
AddHandler foo.SomethingHappened, Raise.With(EventArgs.Empty).Go
This is what I have so far:
<TestMethod()>
Public Sub VerifyThat_LocationChangedHandler_IsWired()
Dim _view As IClientLocationView= A.Fake(Of IClientLocationView)()
Dim pres As ClientLocationController = A.Fake(Of ClientLocationController)(Function() New ClientLocationController(_view))
pres.Start()
'?????? Need to raise the event
'AddHandler _view.LocationChanged, AddressOf Raise.With(EventArgs.Empty).Now
End Sub