我正在尝试测试接口和控制器之间的事件处理程序是否正确连接。该系统的设置如下例所示:
'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 代码主页上显示的语法没有任何运气。
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