如何使用Rhino Mocks在vb.net中模拟通用接口

时间:2013-03-29 08:15:17

标签: vb.net unit-testing rhino-mocks

我的界面看起来像这样:

ISomeInterface(Of ClassA, ClassB)

我可以使用VB.NET和Rhino Mocks来模拟这个界面吗?如果是这样,怎么样?如果没有,我有哪些替代方案?

1 个答案:

答案 0 :(得分: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