dimanche 27 décembre 2015

How to unit test code that uses AutoMapper ProjectTo?

I'm using AutoMapper for mapping Entity Framework entities to business entities. Business logic classes take IMappingEngine as dependency through their constructors. Then it is used in methods like this:

public IEnumerable<UserBLL> GetAllUsers()
{
    return _dbContext.Users.ProjectTo<UserBLL>(null, _mappingEngine);
}

Everything works perfect. The problem is unit tests. I figured from ProjectTo implementation that I need to stub IMappingEngine.CreateMapExpression method. But it seems overcomplicated. Is there any easier solution? Of course, it's possible to just use AutoMapper's implementation by configuring mapping in test setup method, and then passing Mapper.Engine to SUT, but it smells like integration test, not unit.

Aucun commentaire:

Enregistrer un commentaire