2011-04-27 3 views
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 

답변

2

것은 2.0.0 이상 FakeItEasy 버전 나이가 사용하는 경우, 이벤트는 이벤트 핸들러 위임의 형식이어야합니다 이것이 변경되면 이제 이벤트 발생 구문을 사용할 수 있습니다.

AddHandler _view.LocationChanged, Raise.With(New LocationChangedEventArgs With { .IsHomeLocation = True }) 

FakeItEasy 2.0.0 현재이 제한 사항은 더 이상 적용되지 않습니다. 설명서에서 자세한 내용을 볼 수 있지만, 트릭은 Raise.With에 대한 타이핑 유형으로 대리인 유형을 제공하는 것입니다.

관련 문제