Testing Using NMock with Visual Studio 2005

S

swiftanthony

Hi,
I am currently trialing TDD (Test Driven Development) and have had
good results so far.
I recently heard about NMock and decided to give it a try,
unfortunately I seem to be falling at the first hurdle.

I downloaded the latest version of NMock 2.0.0 RC1 from
http://nmock.org/
Copied the NMock.dll to the project directory, and added a direct
reference to it.

This is my basic unit test code for trying out NMock

'***************************************
Imports NUnit.Framework
Imports NMock2
Imports Application.Factory

<TestFixture()> _
Public Class DummyTestFixture

<Test()> _
Public Sub DummyTest()
Dim mocks As New Mockery
Dim MockDataLayerFactory As IDataLayerFactory

MockDataLayerFactory =
CType(mocks.NewMock(GetType(IDataLayerFactory)), IDataLayerFactory)
'/ MockDataLayerFactory = mocks.NewMock(Of iDataLayerFactory)()
** ALSO DOESN'T WORK **


Expect.Once.On(MockDataLayerFactory).Method("CreateCustomerGateway")

Dim CustomerManager As New
Application.Domain.CustomerManager(MockDataLayerFactory)

CustomerManager.AddNewCustomer("Tony Swift")

Assert.AreEqual("", "", "The Customer Name doesn't match")
mocks.VerifyAllExpectationsHaveBeenMet()
End Sub
End Class
'****************************************

Unfortunately I receive the following message on running the code

******** ERROR MESSAGE RECIEVED *********
Application.Domain.Test.DummyTestFixture.DummyTest :
System.ArgumentOutOfRangeException : StartIndex cannot be less than
zero.
Parameter name: startIndex
at System.String.InternalSubStringWithChecks(Int32 startIndex, Int32
length, Boolean fAlwaysCopy)
at System.String.Substring(Int32 startIndex, Int32 length)
at NMock2.Mockery.DefaultNameFor(Type type)
at NMock2.Mockery.NewMock(Type mockedType)
at Application.Domain.Test.DummyTestFixture.DummyTest() in
C:\Documents and Settings\Ron\My Documents\Visual Studio
2005\Projects\ApplicationTest.DataLayer\Application.Domain.Test\TestFixture.Customer.vb:line
14
'****************************************

If anyone could please offer me advice on how to get NMock working, I
would be extremely grateful.

Kind Regards,
Sca_Tone (aka Tony)
 
Top