AutoMapper AssertConfigurationIsValid是否足以确保良好的映射?

我想问你一个关于AutoMapper的问题。 我们正在对我们的映射进行unit testing:

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

我想知道这个unit testing是否提供相同的覆盖范围?

 Mapper.CreateMap(); AutoMapper.AssertConfigurationIsValid() 

我查看了AutoMapper配置文档 ,对我来说不是很清楚。 我是否需要对每个映射进行unit testing或只使用AssertConfigurationIsValid方法?

它说:

执行此代码会产生AutoMapperConfigurationException,并带有描述性消息。 AutoMapper检查以确保每个Destination类型成员在源类型上具有相应的类型成员。

每个成员都与目标类型相关。 它可能不是正确的(因为总有exception情况),但它至少测试每个属性是从源类型移动到目标。