It depends on the case, but on legacy systems in which I do not want to stub the database, I often present an interface, say IFooDBManager, which has methods that return ADO.Net objects, such as data tables or data sets. Of course, this should not be an interface, but it can be a virtual method, for example. Then in my tests I use a small API with a smooth interface that I created a long time ago, I use it to create datasets and tables and populate them with test values so that I can return them from my fakes.
The free interface looks something like this:
return DataTableBuilder.Create() .DefineColumns("a, b") .AddRow().SetValue("a", 1).SetValue("b", 2).DoneWithRow() .AddRow().SetValue("a", 10).SetValue("b", 20).DoneWithRow() .Table
As I said, this is only one of the approaches that I use, and this is mainly for legacy systems, where I do not want to introduce new dependencies on the operation of frames, etc. This, however, is a technique that I have not seen many other people, so I thought it was worth mentioning.
EDIT: I forgot to make it clear that this is to create a database, so the interaction with the database is not checked in this case. The actual interaction will occur in a particular implementation of IFooDBManager to verify that something else is required.
In addition, not all methods on such an interface, of course, return things, there are also ways to write to the database, and they are usually checked by testing the interaction in RhinoMocks, where I set expectations for these methods.
Patrik Hägne Dec 24 '08 at 11:13 2008-12-24 11:13
source share