Datatable as parameter in function call

146 views
Skip to first unread message

govin...@gmail.com

unread,
Jun 2, 2008, 6:38:27 AM6/2/08
to MoQ Discussions
Hi,

I am new to this group and not sure whether this question has already
been asked, so please bear with me.

I have a function to be mocked which accepts a Datatable as one of the
parameters, lets say
public function Foo(data as datatable) as datatable

Now in the method to be tested as well as the test method(where I
create the mock object) , I create this datatable with two columns and
a row of data, lets say,

Public Function UseFoo () as integer
Dim data as new datatable("Test")
data.columns.add("col1",gettype(string))
data.columns.add("col2",gettype(string))
data.rows.add("value1", "value2")

dim result as datatable = Foo (data)
if result isnot nothing then return
data.rows.count
return -1
End function

<testMethod()> _
Public Sub UseFooTest()
Dim data as new datatable("Test")
data.columns.add("col1",gettype(string))
data.columns.add("col2",gettype(string))
data.rows.add("value1", "value2")

Dim ExpectedTable as new datatable
ExpectedTable.columns.add("col")
ExpectedTable.rows.add("Expected")

Dim mock as new Mock(of IFooBelongsTo)
mock.Expect(Function(a)
a.Foo(data)).Returns(ExpectedTable)

Dim target as new ClassUseFooBelongsTo
Assert.AreEqual(1, target.UseFoo())
End Sub

The problem is that when I run this test it fails because the mocking
doesn't happen. The function call for the
mocking is similar, the only difference is that the two datatables
'data' are two different instances. That is how.net interprets them.
Is there any way I could make it work without changing the function
definitions?

If I pass 'nothing' in both the places where 'data' is passed, the
test would pass.

I haven't tried whether this problem exists with other reference types
also.

Thanks,
Govind.

Daniel Cazzulino

unread,
Jun 2, 2008, 11:04:45 AM6/2/08
to moq...@googlegroups.com
have you tried setting the expectation using It.IsAny<DataTable>() instead?
Reply all
Reply to author
Forward
0 new messages