views:

635

answers:

3

ADO.NET has the notorious DataRow class which you cannot instantiate using new. This is a problem now that I find a need to mock it using Rhino Mocks.

Does anyone have any ideas how I could get around this problem?

A: 

Any time I can't mock something (I prefer MoQ over Rhino, but that's beside the point) I have to code around it.

The way I see it you only have two choices. Pay for a superior framework such as TypeMock that can mock ANY class, or code a wrapper around classes that weren't written to be mocked.

Its a sad state of affairs in the framework. TDD wasn't a big concern back in the 1.1 days.

Will
+5  A: 

I'm curious as to why you need to mock the DataRow. Sometimes you can get caught up doing mocking and forget that it can be just as prudent to use the real thing. If you are passing around data rows then you can simply instantiate one with a helper method and use that as a return value on your mock.

SetupResult.For(someMockClass.GetDataRow(input)).Return(GetReturnRow());

public DataRow GetReturnRow()
{
    DataTable table = new DataTable("FakeTable");
    DataRow row = table.NewRow();
    row.value1 = "someValue";
    row.value2 = 234;

    return row;
}

If this is not the situation you are in then I am going to need some example code to be able to figure out what you are trying to do.

Josh
It is for an (awkward) ORM that I wrote, I am testing that a Dao queries my DBWrapper object to get a DataRow and builds the object from it. While it would be more expedient to use a mock, I guess something like this will have to do.
George Mauer
Yeah that is a tough one. Normally I would say to just avoid using a concrete type altogether and instead rely on some interface, but what you are trying to accomplish wouldn't accommodate this.
Josh
A: 

I also use Typemock Isolator for this, it can mock things that other mocking frameworks are unable to.