我们有许多DLL文件,可以访问我们的数据库和其他应用程序和服务。
我们使用薄的WCF服务层来封装这些DLL,并由客户端进行消费。
我不太确定如何编写仅测试WCF服务层的单元测试。我是否应该只为DLL编写单元测试,为WCF服务编写集成测试?如果我的单元测试实际上要连接到数据库,则它们将不会是真正的单元测试。我也知道在单元测试中不必测试WCF服务主机。
因此,我对要测试的内容及方式感到困惑。
我们有许多DLL文件,可以访问我们的数据库和其他应用程序和服务。
我们使用薄的WCF服务层来封装这些DLL,并由客户端进行消费。
我不太确定如何编写仅测试WCF服务层的单元测试。我是否应该只为DLL编写单元测试,为WCF服务编写集成测试?如果我的单元测试实际上要连接到数据库,则它们将不会是真正的单元测试。我也知道在单元测试中不必测试WCF服务主机。
因此,我对要测试的内容及方式感到困惑。
Public Class ProductService
Implements IProductService
Private mRepository As IProductRepository
Public Sub New()
mRepository = New ProductRepository()
End Sub
Public Sub New(ByVal repository As IProductRepository)
mRepository = repository
End Sub
Public Function GetProducts() As System.Collections.Generic.List(Of Product) Implements IProductService.GetProducts
Return mRepository.GetProducts()
End Function
End Class
<TestMethod()> _
Public Sub ShouldPopulateProductsListOnViewLoadWhenPostBackIsFalse()
mMockery = New MockRepository()
mView = DirectCast(mMockery.Stub(Of IProductView)(), IProductView)
mProductService = DirectCast(mMockery.DynamicMock(Of IProductService)(), IProductService)
mPresenter = New ProductPresenter(mView, mProductService)
Dim ProductList As New List(Of Product)()
ProductList.Add(New Product)
Using mMockery.Record()
SetupResult.For(mView.PageIsPostBack).Return(False).Repeat.Once()
Expect.Call(mProductService.GetProducts()).Return(ProductList).Repeat.Once()
End Using
Using mMockery.Playback()
mPresenter.OnViewLoad()
End Using
'Verify that we hit the service dependency during the method when postback is false
Assert.AreEqual(1, mView.Products.Count)
mMockery.VerifyAll()
End Sub