1

インターフェイスとコントローラー間のイベント ハンドラーが適切に配線されていることをテストしようとしています。システムは以下の例のようにセットアップされます。

'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
4

1 に答える 1

2

2.0.0 より古いバージョンの FakeItEasy を使用する場合、イベントは EventHandler デリゲートの形式にする必要があります。

Event LocationChanged As EventHandler(Of LocationChangedEventArgs)

Public Class LocationChangedEventArgs
    Inherits EventArgs

    Public Property IsHomeLocation As Boolean
End Class

これが変更されると、イベント発生構文を使用できるようになります。

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

FakeItEasy 2.0.0以降、この制限は適用されなくなりました。Raising Eventsのドキュメントで詳細を確認できますが、秘訣はデリゲート型を typeparam として に提供することRaise.Withです。

于 2011-04-28T11:15:57.653 に答える