Hi
Here's my suggestion:
Refactor the code that returns DataRow into a separate method:
Public Function GetDataRow(ByVal artistId As Long, ByVal recDataSet As RecordingDataSet) As DataRow()
Me.command.Parameters("@id").Value = artistId
Me.adapter.Fill(recDataSet, recDataSet.Artists.TableName)
Dim rows() As DataRow = recDataSet.Artists.Select(String.Format("id={0}", artistId))
Return rows
End Function
This will let you fake easily just what you need which is the DataSet object.
Than your test will look something like this:
<TestMethod> Public Sub FindById_Test()
Dim mockDataRow As RecorderManager.CreateObject(Of DataRow)
Dim ret() As DataRow = {mockDataRow.Object}
Using recorder As New RecordExpectations
Dim mock As New ClassUnderTest()
recorder.ExpectAndReturn(mock.GetDataRow, ret)
End Using
Dim classUnderTest As New ClassUnderTest()
classUnderTest.FindById(1, New RecordingDataSet())
End Sub
And just to taste the future - The next version of Typemock Isolator that will be out next week
will include special API for VB. Here's how the test will look like in the next version:
<TestMethod> Public Sub FindById_Test2()
'Create our return value
Dim fake As DataRow = FakeInstance(Of DataRow)()
Dim ret() As DataRow = {fake}
Dim classUnderTest As New SomeNameSpace.ClassUnderTest()
' Stubbing the GetDataRow method. When called the method will return the array we created
Using TheseCalls.WillReturn(ret)
classUnderTest.GetDataRow()
End Using
Dim artist As RecordingDataSet.Artist = classUnderTest.FindById(1, New SomeNameSpace.RecordingDataSet())
'Asserting that FindById works as expected
Assert.IsNotNull(artist)
End Sub
Hope it helps :)