Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is AutoMapper AssertConfigurationIsValid enough to ensure good mapping?

Tags:

I'd like to ask you a question about AutoMapper. We are unit testing our mapping like that:

var dtoFiltrePersonne = new DtoFiltrePersonne { Prop1 = "Test", Prop2 = 1234 }; Mapper.CreateMap<FiltrePersonne, DtoFiltrePersonne>(); var filtrePersonne = DtoAutoMappeur<DtoFiltrePersonne, FiltrePersonne>.Instance.MapFromDtoToEntity(dtoFiltrePersonne); Assert.AreEqual(dtoFiltrePersonne.Prop1, filtrePersonne.Prop1); Assert.AreEqual(dtoFiltrePersonne.Prop2, filtrePersonne.Prop2); 

I'd like to know if this unit test provides the same coverage?

Mapper.CreateMap<FiltrePersonne, DtoFiltrePersonne>(); AutoMapper.AssertConfigurationIsValid() 

I looked into the AutoMapper Configuration documentation and it's not pretty clear for me. Do I need to unit test each mapping or just use the AssertConfigurationIsValid method?

like image 600
Morgan Avatar asked Aug 20 '12 12:08

Morgan


1 Answers

It says:

Executing this code produces an AutoMapperConfigurationException, with a descriptive message. AutoMapper checks to make sure that every single Destination type member has a corresponding type member on the source type.

Every single member has correlation with destination type. It may not be the right one (since there are always exception cases), but it at least tests that every property is moved from source type to destination.

like image 157
Dmitry Reznik Avatar answered Oct 29 '22 21:10

Dmitry Reznik