Search code examples
c#unit-testingtypemock

Typemock: How to run unit tests on data transformations?


I'm trying to add unit tests to an existing system, which uses AutoMapper extensively.

The class Search uses the DB class. The data type is transformed when exchanged using Automapper.

DB class: Returns DBSearchResult[]

Search class: Returns SearchResult (holds List of SearchResult and an integer, let's say 1000)

DBSearchResult mock holds: DBSearchResult[2]

Note that DBSearchResult is converted using AutoMapper to SearchResult.

My intention is to check whether the Search class SearchResult will contain the right values (2 and 1000), but this means Automapper kicks in.

How do I deal with Automapper's transformation of the datatypes without mocking it and basically testing a mock, and not the real implementation?


Solution

  • After consulting with TypeMock, the conclusion is: Mock everything but the data transformation.

    This way you test the actual work of AutoMapper, but avoid the other dependencies.

    AutoMapper is initialized like the application would init it.