Getting feet wet with NMock 2

View: New views
13 Messages — Rating Filter:   Alert me  

Getting feet wet with NMock 2

by chris Burgess-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm looking for a little jump start with mock objects using NMock2.
I'm trying to mock an IEntityDAO interface so that I can return a
Project object to test.

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:

<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

I'm not sure what goes next.

Thanks!

Chris

RE: Getting feet wet with NMock 2

by Donaldson, John (GEO) :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Chris,

I can't really help with NMock2 (except to say that usually "N" things come with some simple examples).
I'm currently still using NMock (lightweight mocker that comes with NUnit).
I can give you some ideas how I'm using that if you need.

John D.

-----Original Message-----
From: testdrivendevelopment@... [mailto:testdrivendevelopment@...] On Behalf Of chris Burgess
Sent: 27 October 2009 14:14
To: testdrivendevelopment@...
Subject: [TDD] Getting feet wet with NMock 2

I'm looking for a little jump start with mock objects using NMock2.
I'm trying to mock an IEntityDAO interface so that I can return a Project object to test.

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:

<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

I'm not sure what goes next.

Thanks!

Chris


------------------------------------

Yahoo! Groups Links




Re: Getting feet wet with NMock 2

by chris Burgess-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

That would be great, John!  Anything you can send to help me with my example
would be very much appreciated.

Chris

On Tue, Oct 27, 2009 at 11:14 AM, Donaldson, John (GEO) <
john.m.donaldson@...> wrote:

>
>
> Chris,
>
> I can't really help with NMock2 (except to say that usually "N" things come
> with some simple examples).
> I'm currently still using NMock (lightweight mocker that comes with NUnit).
>
> I can give you some ideas how I'm using that if you need.
>
> John D.
>
>
> -----Original Message-----
> From: testdrivendevelopment@...<testdrivendevelopment%40yahoogroups.com>[mailto:
> testdrivendevelopment@...<testdrivendevelopment%40yahoogroups.com>]
> On Behalf Of chris Burgess
> Sent: 27 October 2009 14:14
> To: testdrivendevelopment@...<testdrivendevelopment%40yahoogroups.com>
> Subject: [TDD] Getting feet wet with NMock 2
>
> I'm looking for a little jump start with mock objects using NMock2.
> I'm trying to mock an IEntityDAO interface so that I can return a Project
> object to test.
>
> 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:
>
> <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
>
> I'm not sure what goes next.
>
> Thanks!
>
> Chris
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>  
>


[Non-text portions of this message have been removed]


RE: Getting feet wet with NMock 2

by Charlie Poole-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi John,

NMock is the name of the .NET mock objects framework that
was the ancestor of NMock2. The thing I wrote for NUnit
doesn't really have a name except maybe "NUnit Mocks."

Charlie

> -----Original Message-----
> From: testdrivendevelopment@...
> [mailto:testdrivendevelopment@...] On Behalf Of
> Donaldson, John (GEO)
> Sent: Tuesday, October 27, 2009 8:14 AM
> To: testdrivendevelopment@...
> Subject: RE: [TDD] Getting feet wet with NMock 2
>
> Chris,
>
> I can't really help with NMock2 (except to say that usually
> "N" things come with some simple examples).
> I'm currently still using NMock (lightweight mocker that
> comes with NUnit).
> I can give you some ideas how I'm using that if you need.
>
> John D.
>
> -----Original Message-----
> From: testdrivendevelopment@...
> [mailto:testdrivendevelopment@...] On Behalf Of
> chris Burgess
> Sent: 27 October 2009 14:14
> To: testdrivendevelopment@...
> Subject: [TDD] Getting feet wet with NMock 2
>
> I'm looking for a little jump start with mock objects using NMock2.
> I'm trying to mock an IEntityDAO interface so that I can
> return a Project object to test.
>
> 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:
>
> <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
>
> I'm not sure what goes next.
>
> Thanks!
>
> Chris
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>
>



Re: Getting feet wet with NMock 2

by chris Burgess-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Charlie:

Can you show me how to setup this up using 'Nunit Mocks' for my example
earlier in the thread?

Chris

On Tue, Oct 27, 2009 at 11:52 AM, Charlie Poole
<cpoole@...>wrote:

>
>
> Hi John,
>
> NMock is the name of the .NET mock objects framework that
> was the ancestor of NMock2. The thing I wrote for NUnit
> doesn't really have a name except maybe "NUnit Mocks."
>
> Charlie
>
> > -----Original Message-----
> > From: testdrivendevelopment@...<testdrivendevelopment%40yahoogroups.com>
> > [mailto:testdrivendevelopment@...<testdrivendevelopment%40yahoogroups.com>]
> On Behalf Of
> > Donaldson, John (GEO)
> > Sent: Tuesday, October 27, 2009 8:14 AM
> > To: testdrivendevelopment@...<testdrivendevelopment%40yahoogroups.com>
>  > Subject: RE: [TDD] Getting feet wet with NMock 2
> >
> > Chris,
> >
> > I can't really help with NMock2 (except to say that usually
> > "N" things come with some simple examples).
> > I'm currently still using NMock (lightweight mocker that
> > comes with NUnit).
> > I can give you some ideas how I'm using that if you need.
> >
> > John D.
> >
> > -----Original Message-----
> > From: testdrivendevelopment@...<testdrivendevelopment%40yahoogroups.com>
> > [mailto:testdrivendevelopment@...<testdrivendevelopment%40yahoogroups.com>]
> On Behalf Of
> > chris Burgess
> > Sent: 27 October 2009 14:14
> > To: testdrivendevelopment@...<testdrivendevelopment%40yahoogroups.com>
> > Subject: [TDD] Getting feet wet with NMock 2
> >
> > I'm looking for a little jump start with mock objects using NMock2.
> > I'm trying to mock an IEntityDAO interface so that I can
> > return a Project object to test.
> >
> > 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:
> >
> > <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
> >
> > I'm not sure what goes next.
> >
> > Thanks!
> >
> > Chris
> >
> >
> > ------------------------------------
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
> >
> > ------------------------------------
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
>
>  
>


[Non-text portions of this message have been removed]


RE: Getting feet wet with NMock 2

by Donaldson, John (GEO) :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm currently using NUnit.NMock in my tests.
I did play around with NMock2 (with the mockery syntax) but it was held to be an early version so I reverted to the pre-NMock2 style.
It works well enough, and it's simple.

John D.

-----Original Message-----
From: testdrivendevelopment@... [mailto:testdrivendevelopment@...] On Behalf Of Charlie Poole
Sent: 27 October 2009 16:53
To: testdrivendevelopment@...
Subject: RE: [TDD] Getting feet wet with NMock 2

Hi John,

NMock is the name of the .NET mock objects framework that
was the ancestor of NMock2. The thing I wrote for NUnit
doesn't really have a name except maybe "NUnit Mocks."

Charlie

> -----Original Message-----
> From: testdrivendevelopment@...
> [mailto:testdrivendevelopment@...] On Behalf Of
> Donaldson, John (GEO)
> Sent: Tuesday, October 27, 2009 8:14 AM
> To: testdrivendevelopment@...
> Subject: RE: [TDD] Getting feet wet with NMock 2
>
> Chris,
>
> I can't really help with NMock2 (except to say that usually
> "N" things come with some simple examples).
> I'm currently still using NMock (lightweight mocker that
> comes with NUnit).
> I can give you some ideas how I'm using that if you need.
>
> John D.
>
> -----Original Message-----
> From: testdrivendevelopment@...
> [mailto:testdrivendevelopment@...] On Behalf Of
> chris Burgess
> Sent: 27 October 2009 14:14
> To: testdrivendevelopment@...
> Subject: [TDD] Getting feet wet with NMock 2
>
> I'm looking for a little jump start with mock objects using NMock2.
> I'm trying to mock an IEntityDAO interface so that I can
> return a Project object to test.
>
> 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:
>
> <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
>
> I'm not sure what goes next.
>
> Thanks!
>
> Chris
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>
>




------------------------------------

Yahoo! Groups Links




RE: Getting feet wet with NMock 2

by Donaldson, John (GEO) :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Chris,

I guess this is not going to give you complete satisfaction, but anyway, just ask more questions for things that are not clear.
(Apologies in advance for using C# instead of VB - I've just used this in C#). Also, I'm using NUnit.Mocks (which comes with NUnit 2.5).

- First you need an interface. Your example is IEntityDAO, which defines the function GetByID:
            Project GetByID(string projectNumber);

- You create a Dynamic mock, like this:
            DynamicMock dm = new DynamicMock(typeof(IEntityDAO));

- I usually explicitly set it to be strict
            dm.Strict = true;

- I need a Project instance to return:
            Project project = new Project(); // probably have to set some useful project stuff...

- Now I can set up my expectation (I pretty well always use the array of object for the args):
            dm.ExpectAndReturn("GetByID", project, new object[] { "project number 123" });

- Grab myself an instance to work with, to inject into another object for example:
            IEntityDAO ied = (IEntityDAO)dm.MockInstance;

- That was the "arrange" part - now do the "act" and "assert"

- Then check if the mock was used as you expected:
            dm.Verify();

John D.

-----Original Message-----
From: testdrivendevelopment@... [mailto:testdrivendevelopment@...] On Behalf Of chris Burgess
Sent: 27 October 2009 16:21
To: testdrivendevelopment@...
Subject: Re: [TDD] Getting feet wet with NMock 2

That would be great, John!  Anything you can send to help me with my example
would be very much appreciated.

Chris

On Tue, Oct 27, 2009 at 11:14 AM, Donaldson, John (GEO) <
john.m.donaldson@...> wrote:

>

RE: Getting feet wet with NMock 2

by Charlie Poole-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi John,

My point was only that the name "NMock" is already taken
by someone else, so we shouldn't call NUnitMocks by that
name. Fortunately, they're a nice bunch of guys and will
probably not sue you. :-)

Charlie

> -----Original Message-----
> From: testdrivendevelopment@...
> [mailto:testdrivendevelopment@...] On Behalf Of
> Donaldson, John (GEO)
> Sent: Tuesday, October 27, 2009 11:35 AM
> To: testdrivendevelopment@...
> Subject: RE: [TDD] Getting feet wet with NMock 2
>
> I'm currently using NUnit.NMock in my tests.
> I did play around with NMock2 (with the mockery syntax) but
> it was held to be an early version so I reverted to the
> pre-NMock2 style.
> It works well enough, and it's simple.
>
> John D.
>
> -----Original Message-----
> From: testdrivendevelopment@...
> [mailto:testdrivendevelopment@...] On Behalf Of
> Charlie Poole
> Sent: 27 October 2009 16:53
> To: testdrivendevelopment@...
> Subject: RE: [TDD] Getting feet wet with NMock 2
>
> Hi John,
>
> NMock is the name of the .NET mock objects framework that was
> the ancestor of NMock2. The thing I wrote for NUnit doesn't
> really have a name except maybe "NUnit Mocks."
>
> Charlie
>
> > -----Original Message-----
> > From: testdrivendevelopment@...
> > [mailto:testdrivendevelopment@...] On Behalf Of
> Donaldson,
> > John (GEO)
> > Sent: Tuesday, October 27, 2009 8:14 AM
> > To: testdrivendevelopment@...
> > Subject: RE: [TDD] Getting feet wet with NMock 2
> >
> > Chris,
> >
> > I can't really help with NMock2 (except to say that usually
> "N" things
> > come with some simple examples).
> > I'm currently still using NMock (lightweight mocker that comes with
> > NUnit).
> > I can give you some ideas how I'm using that if you need.
> >
> > John D.
> >
> > -----Original Message-----
> > From: testdrivendevelopment@...
> > [mailto:testdrivendevelopment@...] On Behalf Of chris
> > Burgess
> > Sent: 27 October 2009 14:14
> > To: testdrivendevelopment@...
> > Subject: [TDD] Getting feet wet with NMock 2
> >
> > I'm looking for a little jump start with mock objects using NMock2.
> > I'm trying to mock an IEntityDAO interface so that I can return a
> > Project object to test.
> >
> > 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:
> >
> > <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
> >
> > I'm not sure what goes next.
> >
> > Thanks!
> >
> > Chris
> >
> >
> > ------------------------------------
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
> >
> > ------------------------------------
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
>
>
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>
>



Re: Getting feet wet with NMock 2

by Roy Osherove :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I wouldn't recommend using NUnit mocks, since it was never designed to be in
public use (charlie can help explain that more).
it also has some drawbacks such as having to use strings for method names
(refactoring unfriendly) and other things that do exist in other frameworks.
there is a more recent list of frameworks(with pros and cons of each) you
might want to choose from at:
http://www.artofunittesting.com/Chapters/Tools_and_frameworks
 <http://www.artofunittesting.com/Chapters/Tools_and_frameworks>

On Tue, Oct 27, 2009 at 9:01 PM, Charlie Poole
<cpoole@...>wrote:

>
>
> Hi John,
>
> My point was only that the name "NMock" is already taken
> by someone else, so we shouldn't call NUnitMocks by that
> name. Fortunately, they're a nice bunch of guys and will
> probably not sue you. :-)
>
>
> Charlie
>
> > -----Original Message-----
> > From: testdrivendevelopment@...<testdrivendevelopment%40yahoogroups.com>
> > [mailto:testdrivendevelopment@...<testdrivendevelopment%40yahoogroups.com>]
> On Behalf Of
> > Donaldson, John (GEO)
> > Sent: Tuesday, October 27, 2009 11:35 AM
> > To: testdrivendevelopment@...<testdrivendevelopment%40yahoogroups.com>
> > Subject: RE: [TDD] Getting feet wet with NMock 2
> >
> > I'm currently using NUnit.NMock in my tests.
> > I did play around with NMock2 (with the mockery syntax) but
> > it was held to be an early version so I reverted to the
> > pre-NMock2 style.
> > It works well enough, and it's simple.
> >
> > John D.
> >
> > -----Original Message-----
> > From: testdrivendevelopment@...<testdrivendevelopment%40yahoogroups.com>
> > [mailto:testdrivendevelopment@...<testdrivendevelopment%40yahoogroups.com>]
> On Behalf Of
> > Charlie Poole
> > Sent: 27 October 2009 16:53
> > To: testdrivendevelopment@...<testdrivendevelopment%40yahoogroups.com>
> > Subject: RE: [TDD] Getting feet wet with NMock 2
> >
> > Hi John,
> >
> > NMock is the name of the .NET mock objects framework that was
> > the ancestor of NMock2. The thing I wrote for NUnit doesn't
> > really have a name except maybe "NUnit Mocks."
> >
> > Charlie
> >
> > > -----Original Message-----
> > > From: testdrivendevelopment@...<testdrivendevelopment%40yahoogroups.com>
> > > [mailto:testdrivendevelopment@...<testdrivendevelopment%40yahoogroups.com>]
> On Behalf Of
> > Donaldson,
> > > John (GEO)
> > > Sent: Tuesday, October 27, 2009 8:14 AM
> > > To: testdrivendevelopment@...<testdrivendevelopment%40yahoogroups.com>
> > > Subject: RE: [TDD] Getting feet wet with NMock 2
> > >
> > > Chris,
> > >
> > > I can't really help with NMock2 (except to say that usually
> > "N" things
> > > come with some simple examples).
> > > I'm currently still using NMock (lightweight mocker that comes with
> > > NUnit).
> > > I can give you some ideas how I'm using that if you need.
> > >
> > > John D.
> > >
> > > -----Original Message-----
> > > From: testdrivendevelopment@...<testdrivendevelopment%40yahoogroups.com>
> > > [mailto:testdrivendevelopment@...<testdrivendevelopment%40yahoogroups.com>]
> On Behalf Of chris
> > > Burgess
> > > Sent: 27 October 2009 14:14
> > > To: testdrivendevelopment@...<testdrivendevelopment%40yahoogroups.com>
> > > Subject: [TDD] Getting feet wet with NMock 2
> > >
> > > I'm looking for a little jump start with mock objects using NMock2.
> > > I'm trying to mock an IEntityDAO interface so that I can return a
> > > Project object to test.
> > >
> > > 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:
> > >
> > > <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
> > >
> > > I'm not sure what goes next.
> > >
> > > Thanks!
> > >
> > > Chris
> > >
> > >
> > > ------------------------------------
> > >
> > > Yahoo! Groups Links
> > >
> > >
> > >
> > >
> > >
> > > ------------------------------------
> > >
> > > Yahoo! Groups Links
> > >
> > >
> > >
> > >
> >
> >
> >
> >
> > ------------------------------------
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
> >
> > ------------------------------------
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
>
>  
>



--
Thanks,

Roy Osherove
www.TypeMock.com - Unit Testing, Plain Smart

Author of "The Art Of Unit Testing" (http://ArtOfUnitTesting.com )
A blog for team leaders: http://5Whys.com
my .NET blog: http://www.ISerializable.com
Twitter: http://twitter.com/RoyOsherove
+972-524-655388 (GMT+2)


[Non-text portions of this message have been removed]


Re: Getting feet wet with NMock 2

by chris Burgess-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi John:

Thanks John. This was helpful. I think I need to re-evaluate my design.

Chris

On Tue, Oct 27, 2009 at 2:53 PM, Donaldson, John (GEO) <
john.m.donaldson@...> wrote:

>
>
> Chris,
>
> I guess this is not going to give you complete satisfaction, but anyway,
> just ask more questions for things that are not clear.
> (Apologies in advance for using C# instead of VB - I've just used this in
> C#). Also, I'm using NUnit.Mocks (which comes with NUnit 2.5).
>
> - First you need an interface. Your example is IEntityDAO, which defines
> the function GetByID:
> Project GetByID(string projectNumber);
>
> - You create a Dynamic mock, like this:
> DynamicMock dm = new DynamicMock(typeof(IEntityDAO));
>
> - I usually explicitly set it to be strict
> dm.Strict = true;
>
> - I need a Project instance to return:
> Project project = new Project(); // probably have to set some useful
> project stuff...
>
> - Now I can set up my expectation (I pretty well always use the array of
> object for the args):
> dm.ExpectAndReturn("GetByID", project, new object[] { "project number 123"
> });
>
> - Grab myself an instance to work with, to inject into another object for
> example:
> IEntityDAO ied = (IEntityDAO)dm.MockInstance;
>
> - That was the "arrange" part - now do the "act" and "assert"
>
> - Then check if the mock was used as you expected:
> dm.Verify();
>
>
> John D.
>
> -----Original Message-----
> From: testdrivendevelopment@...<testdrivendevelopment%40yahoogroups.com>[mailto:
> testdrivendevelopment@...<testdrivendevelopment%40yahoogroups.com>]
> On Behalf Of chris Burgess
> Sent: 27 October 2009 16:21
> To: testdrivendevelopment@...<testdrivendevelopment%40yahoogroups.com>
> Subject: Re: [TDD] Getting feet wet with NMock 2
>
> That would be great, John! Anything you can send to help me with my example
> would be very much appreciated.
>
> Chris
>
> On Tue, Oct 27, 2009 at 11:14 AM, Donaldson, John (GEO) <
> john.m.donaldson@... <john.m.donaldson%40hp.com>> wrote:
>
> >
>
>
>


[Non-text portions of this message have been removed]


RE: Getting feet wet with NMock 2

by Donaldson, John (GEO) :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ah! Ok - I didn't know that - sorry for the misunderstanding.
John D.

-----Original Message-----
From: testdrivendevelopment@... [mailto:testdrivendevelopment@...] On Behalf Of Charlie Poole
Sent: 27 October 2009 20:01
To: testdrivendevelopment@...
Subject: RE: [TDD] Getting feet wet with NMock 2

Hi John,

My point was only that the name "NMock" is already taken
by someone else, so we shouldn't call NUnitMocks by that
name. Fortunately, they're a nice bunch of guys and will
probably not sue you. :-)

Charlie

> -----Original Message-----
> From: testdrivendevelopment@...
> [mailto:testdrivendevelopment@...] On Behalf Of
> Donaldson, John (GEO)
> Sent: Tuesday, October 27, 2009 11:35 AM
> To: testdrivendevelopment@...
> Subject: RE: [TDD] Getting feet wet with NMock 2
>
> I'm currently using NUnit.NMock in my tests.
> I did play around with NMock2 (with the mockery syntax) but
> it was held to be an early version so I reverted to the
> pre-NMock2 style.
> It works well enough, and it's simple.
>
> John D.
>
> -----Original Message-----
> From: testdrivendevelopment@...
> [mailto:testdrivendevelopment@...] On Behalf Of
> Charlie Poole
> Sent: 27 October 2009 16:53
> To: testdrivendevelopment@...
> Subject: RE: [TDD] Getting feet wet with NMock 2
>
> Hi John,
>
> NMock is the name of the .NET mock objects framework that was
> the ancestor of NMock2. The thing I wrote for NUnit doesn't
> really have a name except maybe "NUnit Mocks."
>
> Charlie
>
> > -----Original Message-----
> > From: testdrivendevelopment@...
> > [mailto:testdrivendevelopment@...] On Behalf Of
> Donaldson,
> > John (GEO)
> > Sent: Tuesday, October 27, 2009 8:14 AM
> > To: testdrivendevelopment@...
> > Subject: RE: [TDD] Getting feet wet with NMock 2
> >
> > Chris,
> >
> > I can't really help with NMock2 (except to say that usually
> "N" things
> > come with some simple examples).
> > I'm currently still using NMock (lightweight mocker that comes with
> > NUnit).
> > I can give you some ideas how I'm using that if you need.
> >
> > John D.
> >
> > -----Original Message-----
> > From: testdrivendevelopment@...
> > [mailto:testdrivendevelopment@...] On Behalf Of chris
> > Burgess
> > Sent: 27 October 2009 14:14
> > To: testdrivendevelopment@...
> > Subject: [TDD] Getting feet wet with NMock 2
> >
> > I'm looking for a little jump start with mock objects using NMock2.
> > I'm trying to mock an IEntityDAO interface so that I can return a
> > Project object to test.
> >
> > 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:
> >
> > <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
> >
> > I'm not sure what goes next.
> >
> > Thanks!
> >
> > Chris
> >
> >
> > ------------------------------------
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
> >
> > ------------------------------------
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
>
>
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>
>




------------------------------------

Yahoo! Groups Links




Re: Getting feet wet with NMock 2

by chris Burgess-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks, Roy.

On Tue, Oct 27, 2009 at 3:25 PM, Roy Osherove <roy@...> wrote:

>
>
> I wouldn't recommend using NUnit mocks, since it was never designed to be
> in
> public use (charlie can help explain that more).
> it also has some drawbacks such as having to use strings for method names
> (refactoring unfriendly) and other things that do exist in other
> frameworks.
> there is a more recent list of frameworks(with pros and cons of each) you
> might want to choose from at:
> http://www.artofunittesting.com/Chapters/Tools_and_frameworks
> <http://www.artofunittesting.com/Chapters/Tools_and_frameworks>
>
> On Tue, Oct 27, 2009 at 9:01 PM, Charlie Poole
> <cpoole@... <cpoole%40pooleconsulting.com>>wrote:
>
> >
> >
>
> > Hi John,
> >
> > My point was only that the name "NMock" is already taken
> > by someone else, so we shouldn't call NUnitMocks by that
> > name. Fortunately, they're a nice bunch of guys and will
> > probably not sue you. :-)
> >
> >
> > Charlie
> >
> > > -----Original Message-----
> > > From: testdrivendevelopment@...<testdrivendevelopment%40yahoogroups.com>
> <testdrivendevelopment%40yahoogroups.com>
> > > [mailto:testdrivendevelopment@...<testdrivendevelopment%40yahoogroups.com>
> <testdrivendevelopment%40yahoogroups.com>]
> > On Behalf Of
> > > Donaldson, John (GEO)
> > > Sent: Tuesday, October 27, 2009 11:35 AM
> > > To: testdrivendevelopment@...<testdrivendevelopment%40yahoogroups.com>
> <testdrivendevelopment%40yahoogroups.com>
> > > Subject: RE: [TDD] Getting feet wet with NMock 2
> > >
> > > I'm currently using NUnit.NMock in my tests.
> > > I did play around with NMock2 (with the mockery syntax) but
> > > it was held to be an early version so I reverted to the
> > > pre-NMock2 style.
> > > It works well enough, and it's simple.
> > >
> > > John D.
> > >
> > > -----Original Message-----
> > > From: testdrivendevelopment@...<testdrivendevelopment%40yahoogroups.com>
> <testdrivendevelopment%40yahoogroups.com>
> > > [mailto:testdrivendevelopment@...<testdrivendevelopment%40yahoogroups.com>
> <testdrivendevelopment%40yahoogroups.com>]
> > On Behalf Of
> > > Charlie Poole
> > > Sent: 27 October 2009 16:53
> > > To: testdrivendevelopment@...<testdrivendevelopment%40yahoogroups.com>
> <testdrivendevelopment%40yahoogroups.com>
> > > Subject: RE: [TDD] Getting feet wet with NMock 2
> > >
> > > Hi John,
> > >
> > > NMock is the name of the .NET mock objects framework that was
> > > the ancestor of NMock2. The thing I wrote for NUnit doesn't
> > > really have a name except maybe "NUnit Mocks."
> > >
> > > Charlie
> > >
> > > > -----Original Message-----
> > > > From: testdrivendevelopment@...<testdrivendevelopment%40yahoogroups.com>
> <testdrivendevelopment%40yahoogroups.com>
> > > > [mailto:testdrivendevelopment@...<testdrivendevelopment%40yahoogroups.com>
> <testdrivendevelopment%40yahoogroups.com>]
> > On Behalf Of
> > > Donaldson,
> > > > John (GEO)
> > > > Sent: Tuesday, October 27, 2009 8:14 AM
> > > > To: testdrivendevelopment@...<testdrivendevelopment%40yahoogroups.com>
> <testdrivendevelopment%40yahoogroups.com>
> > > > Subject: RE: [TDD] Getting feet wet with NMock 2
> > > >
> > > > Chris,
> > > >
> > > > I can't really help with NMock2 (except to say that usually
> > > "N" things
> > > > come with some simple examples).
> > > > I'm currently still using NMock (lightweight mocker that comes with
> > > > NUnit).
> > > > I can give you some ideas how I'm using that if you need.
> > > >
> > > > John D.
> > > >
> > > > -----Original Message-----
> > > > From: testdrivendevelopment@...<testdrivendevelopment%40yahoogroups.com>
> <testdrivendevelopment%40yahoogroups.com>
> > > > [mailto:testdrivendevelopment@...<testdrivendevelopment%40yahoogroups.com>
> <testdrivendevelopment%40yahoogroups.com>]
> > On Behalf Of chris
> > > > Burgess
> > > > Sent: 27 October 2009 14:14
>  > > > To: testdrivendevelopment@...<testdrivendevelopment%40yahoogroups.com>
> <testdrivendevelopment%40yahoogroups.com>
> > > > Subject: [TDD] Getting feet wet with NMock 2
> > > >
> > > > I'm looking for a little jump start with mock objects using NMock2.
> > > > I'm trying to mock an IEntityDAO interface so that I can return a
> > > > Project object to test.
> > > >
> > > > 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:
> > > >
> > > > <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
> > > >
> > > > I'm not sure what goes next.
> > > >
> > > > Thanks!
> > > >
> > > > Chris
> > > >
> > > >
> > > > ------------------------------------
> > > >
> > > > Yahoo! Groups Links
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > ------------------------------------
> > > >
> > > > Yahoo! Groups Links
> > > >
> > > >
> > > >
> > > >
> > >
> > >
> > >
> > >
> > > ------------------------------------
> > >
> > > Yahoo! Groups Links
> > >
> > >
> > >
> > >
> > >
> > > ------------------------------------
> > >
> > > Yahoo! Groups Links
> > >
> > >
> > >
> > >
> >
> >
> >
>
> --
> Thanks,
>
> Roy Osherove
> www.TypeMock.com <http://www.typemock.com/> - Unit Testing, Plain Smart
>
> Author of "The Art Of Unit Testing" (http://ArtOfUnitTesting.com<http://artofunittesting.com/>)
> A blog for team leaders: http://5Whys.com <http://5whys.com/>
> my .NET blog: http://www.ISerializable.com <http://www.iserializable.com/>
> Twitter: http://twitter.com/RoyOsherove
> +972-524-655388 (GMT+2)
>
> [Non-text portions of this message have been removed]
>
>  
>


[Non-text portions of this message have been removed]


RE: Getting feet wet with NMock 2

by Donaldson, John (GEO) :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Roy,

Thanks for the pointers.

I agree that, as a mocking framework, "NUnit mocks" (did I get the name right this time?!) is simple. But that is sometimes a goodness. I keep meaning to go and try a more modern framework - but it's a learning curve cost.

Really, the main irritation with "NUnit mocks" is the use of strings for method names. It leads to some test fragility, and some lack of refactoring ease. Sure, there are other little niggles. But it's simple, it's in the NUnit kit, and I know how to drive it.

John D.

-----Original Message-----
From: testdrivendevelopment@... [mailto:testdrivendevelopment@...] On Behalf Of Roy Osherove
Sent: 27 October 2009 20:25
To: testdrivendevelopment@...
Subject: Re: [TDD] Getting feet wet with NMock 2

I wouldn't recommend using NUnit mocks, since it was never designed to be in
public use (charlie can help explain that more).
it also has some drawbacks such as having to use strings for method names
(refactoring unfriendly) and other things that do exist in other frameworks.
there is a more recent list of frameworks(with pros and cons of each) you
might want to choose from at:
http://www.artofunittesting.com/Chapters/Tools_and_frameworks
 <http://www.artofunittesting.com/Chapters/Tools_and_frameworks>

On Tue, Oct 27, 2009 at 9:01 PM, Charlie Poole
<cpoole@...>wrote:

>
>
> Hi John,
>
> My point was only that the name "NMock" is already taken
> by someone else, so we shouldn't call NUnitMocks by that
> name. Fortunately, they're a nice bunch of guys and will
> probably not sue you. :-)
>
>
> Charlie
>
> > -----Original Message-----
> > From: testdrivendevelopment@...<testdrivendevelopment%40yahoogroups.com>
> > [mailto:testdrivendevelopment@...<testdrivendevelopment%40yahoogroups.com>]
> On Behalf Of
> > Donaldson, John (GEO)
> > Sent: Tuesday, October 27, 2009 11:35 AM
> > To: testdrivendevelopment@...<testdrivendevelopment%40yahoogroups.com>
> > Subject: RE: [TDD] Getting feet wet with NMock 2
> >
> > I'm currently using NUnit.NMock in my tests.
> > I did play around with NMock2 (with the mockery syntax) but
> > it was held to be an early version so I reverted to the
> > pre-NMock2 style.
> > It works well enough, and it's simple.
> >
> > John D.
> >
> > -----Original Message-----
> > From: testdrivendevelopment@...<testdrivendevelopment%40yahoogroups.com>
> > [mailto:testdrivendevelopment@...<testdrivendevelopment%40yahoogroups.com>]
> On Behalf Of
> > Charlie Poole
> > Sent: 27 October 2009 16:53
> > To: testdrivendevelopment@...<testdrivendevelopment%40yahoogroups.com>
> > Subject: RE: [TDD] Getting feet wet with NMock 2
> >
> > Hi John,
> >
> > NMock is the name of the .NET mock objects framework that was
> > the ancestor of NMock2. The thing I wrote for NUnit doesn't
> > really have a name except maybe "NUnit Mocks."
> >
> > Charlie
> >
> > > -----Original Message-----
> > > From: testdrivendevelopment@...<testdrivendevelopment%40yahoogroups.com>
> > > [mailto:testdrivendevelopment@...<testdrivendevelopment%40yahoogroups.com>]
> On Behalf Of
> > Donaldson,
> > > John (GEO)
> > > Sent: Tuesday, October 27, 2009 8:14 AM
> > > To: testdrivendevelopment@...<testdrivendevelopment%40yahoogroups.com>
> > > Subject: RE: [TDD] Getting feet wet with NMock 2
> > >
> > > Chris,
> > >
> > > I can't really help with NMock2 (except to say that usually
> > "N" things
> > > come with some simple examples).
> > > I'm currently still using NMock (lightweight mocker that comes with
> > > NUnit).
> > > I can give you some ideas how I'm using that if you need.
> > >
> > > John D.
> > >
> > > -----Original Message-----
> > > From: testdrivendevelopment@...<testdrivendevelopment%40yahoogroups.com>
> > > [mailto:testdrivendevelopment@...<testdrivendevelopment%40yahoogroups.com>]
> On Behalf Of chris
> > > Burgess
> > > Sent: 27 October 2009 14:14
> > > To: testdrivendevelopment@...<testdrivendevelopment%40yahoogroups.com>
> > > Subject: [TDD] Getting feet wet with NMock 2
> > >
> > > I'm looking for a little jump start with mock objects using NMock2.
> > > I'm trying to mock an IEntityDAO interface so that I can return a
> > > Project object to test.
> > >
> > > 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:
> > >
> > > <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
> > >
> > > I'm not sure what goes next.
> > >
> > > Thanks!
> > >
> > > Chris
> > >
> > >
> > > ------------------------------------
> > >
> > > Yahoo! Groups Links
> > >
> > >
> > >
> > >
> > >
> > > ------------------------------------
> > >
> > > Yahoo! Groups Links
> > >
> > >
> > >
> > >
> >
> >
> >
> >
> > ------------------------------------
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
> >
> > ------------------------------------
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
>
>  
>



--
Thanks,

Roy Osherove
www.TypeMock.com - Unit Testing, Plain Smart

Author of "The Art Of Unit Testing" (http://ArtOfUnitTesting.com )
A blog for team leaders: http://5Whys.com
my .NET blog: http://www.ISerializable.com
Twitter: http://twitter.com/RoyOsherove
+972-524-655388 (GMT+2)


[Non-text portions of this message have been removed]



------------------------------------

Yahoo! Groups Links