I've seen in this video that mocking automapper its not a good approach: https://www.youtube.com/watch?v=RsnEZdc3MrE
Instead, you can use a Mapper creator and return your real application mapper.
In the test project:
//this is going to return your real mapper
var mapper = MapperBuilder.Create();
--
public static class MapperBuilder
{
public static IMapper Create()
{
return new AutoMapper.MapperConfiguration(options =>
{
options.AddProfile(new MyRealMapper());
}).CreateMapper();
}
}
In your Application project:
public class MyRealMapper : Profile
{
public MyRealMapper()
{
RequestToDomain();
DomainToResponse();
}
private void DomainToResponse()
{
CreateMap<User, ResponseUserCreateJson>();
CreateMap<User, ResponseUserChangePasswordJson>();
}
private void RequestToDomain()
{
CreateMap<RequestUserCreateJson, User>()
.ForMember(u => u.Password, config => config.Ignore());
}
}