Is there a way to wrap an existing object with a mock/stub?

253 views
Skip to first unread message

Алик Ким

unread,
Oct 9, 2012, 8:14:44 AM10/9/12
to rhino...@googlegroups.com
Hi!

I got an object of IDataReader. Need to make some changes to the result of its GetSchemaTable method. And want the object to act like it acts usual in all other cases. Can I somehow wrap that existing object using rhino mocks?


Details:
in out unit tests we create DataTable programmatically, then provide a code to be tested with result of its "CreateDataReader()" method, which returns IDataReader.
I didn't find way to set precision and scale for a decimal column of DataTable. As far as I see the only way to emulate them is to create a wrapper around the IDataReader object which wil delegate all actions , but will allow to make changes to schema info table inside GetSchemaTable


I can achive such wrapping manually: make a StubDataReader class, which will delegate all calls to an existing instance of IDataReader. But I think a new class with about 20 stub methods is not a good way :(

Luis Ferreira

unread,
Mar 1, 2013, 5:26:25 AM3/1/13
to rhino...@googlegroups.com, qim....@gmail.com
I've got pretty much the same problem.

I have Castle Windsor inverison of control library returning me a proxy (for a home-grown lazy-loading persistence thing we built). Now I need a mock around that proxy. So I need a proxy-proxy. Not that easy, apparently. I'm still working on it.

Luis Ferreira

unread,
Mar 1, 2013, 6:17:07 AM3/1/13
to rhino...@googlegroups.com, qim....@gmail.com
Actually, in your specific case, doesn't

    MockRepository.GeneratePartialMock(typeof(SqlDataReader), new Type[0], arguments)

do the trick?

I'm assuming your IDataReader is an SqlDataReader, but could be your specific IDataReader implementation.



On Tuesday, October 9, 2012 1:14:44 PM UTC+1, Алик Ким wrote:
Reply all
Reply to author
Forward
0 new messages