Hi,
I'll put my answer at the end, and you can look at the C# version in the movie on mocking database calls here:
https://www.typemock.com/Multimedia.html#identifier3
However, apart from technically doing so, which is obviously possible, I would think first about what you are trying to accomplish.
If you resort to mocking database objects and interfaces, you should probably refactor your code. Encapsulate your data access code in a single method, then mock that method and return what you want. Like I said, it is technically possible, but will make your unit tests very dependent on the database scheme, and thus brittle.
If you want, you can post your code here, (your database access code), and we can comment on it. Or you can just email me a solution, and we'll take it offline.
Look at this test code in VB.Net:
<TestMethod()> Public Sub TestMethod1()
Using rec As RecordExpectations = RecorderManager.StartRecording
Using connection As New SqlConnection
Dim command As New SqlCommand(Nothing, Nothing)
connection.Open()
Dim fakeReader As SqlDataReader = RecorderManager.CreateMockedObject(GetType(SqlDataReader))
rec.ExpectAndReturn(command.ExecuteReader, fakeReader)
rec.ExpectAndReturn(fakeReader.Read(), False)
rec.ExpectAndReturn(fakeReader.HasRows, True)
rec.ExpectAndReturn(fakeReader.Item("LastName"), "Gil")
fakeReader.Close()
End Using
End Using
End Sub
As you can see there's a lot of code to write just to return "Gil" for the indexer LastName. (And it's not shorter using Reflective mocks). These are things that you need to mock just to get to the data reader.
Instead, if you method GetLastName does all the data access, you can easily mock it and return your value in a single line.
Let me know if this helps you.