1
인터페이스와 컨트롤러 사이의 이벤트 처리기가 올바르게 연결되었는지 테스트하려고합니다. 이 시스템은 아래의 예처럼 설정 : 나는 이벤트 핸들러에 포함 된 코드 경로의 각을 테스트 할 수 있도록VB.Net에서 이벤트 핸들러가 올바르게 연결되어 있는지 확인하기 위해 FakeItEasy로 이벤트 올리기
'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
이
내가 지금까지 무엇을 가지고 :Event LocationChanged As EventHandler(Of LocationChangedEventArgs)
Public Class LocationChangedEventArgs
Inherits EventArgs
Public Property IsHomeLocation As Boolean
End Class
:
<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