tags:

views:

153

answers:

0

I'm looking for a little jump start with mock objects.

I have a class called ProjectDAO that has a method called 'GetById' that will load and return a 'Project' object after tripping to the database. GetById takes a single string argument.

Public Interface IEntityDAO
    Function GetByID(ByVal projectNumber As String) As Project
End Interface

    Public Class ProjectDAO
    Inherits DAOBase
    Implements IEntityDAO

    Public Function GetByID(ByVal projectNumber As String) As Project Implements IEntityDAO.GetByID
        Dim Proj As New Project
        Dim parms As SqlParameter() = {New SqlParameter("ProjectNumber", projectNumber)}

        Using dt As DataTable = GetTable("Project_GetByID", parms)
            If (dt Is Nothing) OrElse dt.Rows.Count = 0 Then
                Throw New ArgumentException("Invalid Project Number!")
            Else
                MapData(Proj, dt)
            End If
        End Using
        Return Proj
    End Function

    Public Function MapData(ByRef proj As Business.Project, ByVal dt As DataTable) As Boolean
        proj.ProjectNumber = CType(dt.Rows(0)("ProjectNumber"), String)
        proj.ProjectName = CType(dt.Rows(0)("ProjectName"), String)
    End Function


End Class



Public Class Project
    Inherits EntityBase

    Private _projectNumber As String
    Public Property ProjectNumber() As String
        Get
            Return _projectNumber
        End Get
        Set(ByVal Value As String)
            _projectNumber = Value
        End Set
    End Property

    Private _projectName As String
    Public Property ProjectName() As String
        Get
            Return _projectName
        End Get
        Set(ByVal Value As String)
            _projectName = Value
        End Set
    End Property

End Class

So far, I've gotten this far with NMock2:

<Test()> _
Public Sub testProjectDAO()
    Dim mocks As New Mockery()
    Dim DAO = mocks.NewMock(GetType(IEntityDAO))
' tried a bunch of stuff here that didn't work

End Sub

How do I setup an NMock2 mock of the IEntityDAO interface so that I can return a Project object to test with?

Thanks!

Chris