I highly appreciate anyone can help me in below-mentioned issue:
I've been using RhinoMock in Unit Test.
I define my mock object in such manner, with sessionToken is string-typed:
mockRepository.Stub(repository => repository.FindById(sessionToken)).Return(new DeviceTypeRepository().NewTable(false));
It's ok for the code section when calling FindById() to return the valid new new DeviceTypeRepository().NewTable(false);
However, when include a complex parameter as object, such as a DataTable, into the Stub as below:
mockRepository.Stub(repository => repository.Find(sessionToken, dataTable)).Return(new DeviceTypeRepository().NewTable(false));
Then the code section in which Find() is invoked, it does NOT return expected new DeviceTypeRepository().NewTable(false).
Notice that input value of parameter dataTable is the same in both Stub and in Find() invocation.
Hence, my question is:
How could I implement such parameter (DataTable typed and more generally) into Stub initialization using RhinoMock ? I'd be grateful to any advice and approach.
Thanks
Best Answer
I believe the problem is not in a complex datatype but rather in the expectations you've set.
As a first attempt to fix it, add
IgnoreArguments()
before theReturn
. It could be thatDataTable
you've specified in expectation differs from the actually-passed-inDataTable
instance so expectations won't pass:If not helped you can debug it manually using WhenCalled():
If that doesn't help, try to add
Repeat().Any()
after theReturn()
and see whether it works. I am supposing that if the method was called a few times, you may have missed the first return value, but I may be wrong.