Я пытаюсь проверить, правильно ли подключены обработчики событий между интерфейсом и контроллером.Система настроена, как показано в примере ниже:
'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
Как вызвать событие с логическим параметром, чтобы я мог проверить каждый из путей кода, содержащихся в обработчике события.Мне не повезло с синтаксисом, показанным на главной странице Google Code.
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
Это то, что у меня есть:
<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