Is AutoMapper AssertConfigurationIsValid enough to ensure good mapping?

对着背影说爱祢 提交于 2019-11-30 16:27:27

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/12037986/is-automapper-assertconfigurationisvalid-enough-to-ensure-good-mapping

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!