Rhino Mocks: How to mock ADO.NET DataRow?

ADO.NET has the infamous DataRow class, which cannot be created using the new one. This is the problem now that I find it necessary to mock her using Rhino Mocks.

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

+4
source share
3 answers

I am curious why you need to mock DataRow. Sometimes you can be catching up with mockery and forget that it can be just as wise to use the real thing. If you are passing data rows, you can simply create an instance using the helper method and use this as the return value for your layout.

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, I will need some sample code to understand what you are trying to do.

+11
source

I also use Typemock Insulator for this, it can mock what other mocking frameworks cannot do.

+1
source

At any time when I can’t mock something (I prefer MoQ over Rhino, but it’s not), I must encode it.

As I can see, you have only two options. Pay for excellent frameworks such as TypeMock, which can mock any class or encode a wrapper around classes that were not written to mock.

His sad state of affairs is within. TDD did not cause much concern for 1.1 days.

0
source

Source: https://habr.com/ru/post/1277341/


All Articles