本文介绍了是AutoMapper AssertConfigurationIsValid足以保证良好的映射?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想问你一个关于AutoMapper问题。我们单元测试一样,我们的映射:

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()



我看着的,这不是很明显我。我是否需要进行单元测试每个映射,或只使用 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?

推荐答案

它说:

执行这个代码产生AutoMapperConfigurationException,与
A描述性消息。 AutoMapper检查以确保每一个
单一目的地型部件对
源类型的相应型部件

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

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.

这篇关于是AutoMapper AssertConfigurationIsValid足以保证良好的映射?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-26 22:07