2

C# で行った方法と同様の単体テストを作成しようとしていますが、vb のラムダに苦労しています。

基本的に、クラスをモックしてからスタブを作成して返そうとしています。C#では、次のようなことをしたでしょう。

MockedPersonRepository
     .Stub(x => x.Find(id))
     .Return(person)

しかし、ビジュアルベーシックでは同様のことをやろうとしていますが、構文を解決できません

   MockedPersonRepository.Stub(Function... argh!!!

上記を再現する方法についてのアドバイスは大歓迎です!

よろしく、ドム

4

2 に答える 2

3

私が通常示す簡単な例の 1 つ (私も VB 開発者であるため) は次のとおりです。

  <TestMethod()> _
  Public Sub Should_Call_Into_Repository_For_GetAllUsers()
    Dim Repository As IUserRepository = MockRepository.GenerateStub(Of IUserRepository)()
    Dim Service As IUserService = New UserService(Repository)

    Service.GetAllUserCollection()

    Repository.AssertWasCalled(Function(x) Wrap_GetAllUserCollection(x))
  End Sub

Function Wrap_GetAllUserCollection(ByVal Repository As IUserRepository) As Object
    Repository.GetAllUserCollection()

    Return Nothing
  End Function

上記は相互作用ベースのテスト用です。以下は、現在の例で探しているものに近いかもしれません

Dim StubUserObject As New User(1, "9999", "jdoe", "John", "Doe", 1)

    UserService.Stub(Function(x) x.GetUserByID(1)).[Return](StubUserObject)
于 2009-05-12T14:31:29.373 に答える
0

このようなものは機能しますか?

MockedPersonRepository_
    .Stub(Function(x) x.Find(id))_
    .[Return](person)
于 2009-05-12T14:32:27.047 に答える