Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rhino Mocks: How to mock ADO.NET's DataRow?

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?

like image 847
George Mauer Avatar asked Dec 13 '22 06:12

George Mauer


1 Answers

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.

like image 84
Josh Avatar answered Jan 03 '23 23:01

Josh