Search code examples
c#unit-testingmockingrhino-mocks.nettiers

How to mock or stub a .netTiers generated DataRepository object


I am using Rhino mocks for unit test mocking of objects. Our DAL uses codesmith to generate code from .netTiers templates, which creates these DataRepository classes that contain all the methods for CRUD type transaction to the datasource. In unit testing, I am trying to mock this data repository object which has no interface class to use as a stub.

In Brief, has anyone successfully used Rhino mocks to mock a .netTiers generated DataRepository, avoiding the need for a test database and real transactions against the datasource that needs to be tore down at the end??


Solution

  • I've been pondering this one for a while, as no one has stepped up and written a mock DataRepository implementation for netTiers yet (to my knowledge).

    As I don't care too much for the record-replay steps of TypeMock and RhinoMocks, I've opted for the newer Moq, which will happily mock either the DataRepository classes or the Service layer calls themselves with minimal hassle.

    Assuming you're on .NET 3.5, I'd recommend it.