0

我有一个看起来像这样的界面:

ISomeInterface(Of ClassA, ClassB)

我可以使用 VB.NET 和 Rhino Mocks 模拟这个界面吗?如果是这样,怎么做?如果没有,我有哪些选择?

4

1 回答 1

0

我找到了以下解决方案:

        <TestInitialize()>
    Public Sub TestInitialize()
        _myStub= MockRepository.GenerateStub(Of ISomeInterface(Of ClassA, ClassB))()
        _controller = New MyController(_myStub)
    End Sub

    <TestMethod()>
    Public Sub SomeMethodCallsMyStubOtherMethod()
        Dim someObject As New SomeObject() With {.Title = "TEST"}
        _myStub.Stub(Of SomeObject)(Function(x) x.GetSomeObject()).Return(someObject)
        Dim result As JsonResult = _controller.SomeMethod()
        Dim someResult As SomeObject = result.Data

        Assert.IsNotNull(someResult)
        Assert.AreEqual(someResult.Title, someObject.Title)
    End Sub
于 2013-03-29T08:42:37.657 回答