Unit test the Automapper profiles
I do want to test the custom logic in the CreateMap
method. I do NOT want to test whether the mapping exist at all for some types.
How can I do that or what are the classes that I need to know. I am grateful for every hint The document about. Automapper unit testing seems very rare...
public class UnitProfile : Profile
{
protected override void Configure()
{
// Here I create my maps with custom logic that needs to be tested
CreateMap<Unit, UnitTreeViewModel>()
.ForMember(dest => dest.IsFolder, o => o.MapFrom(src => src.UnitTypeState == UnitType.Folder ? true : false));
CreateMap<CreateUnitViewModel, Unit>()
.ForMember(dest => dest.UnitTypeState, o => o.MapFrom(src => (UnitType)Enum.ToObject(typeof(UnitType), src.SelectedFolderTypeId)));
}
}
This is the documentation for configuration testing: https://github.com/AutoMapper/AutoMapper/wiki/Configuration-validation
You can see an example of it here: https://stackoverflow.com/a/14150006/1505426
Is this what you were after?
链接地址: http://www.djcxy.com/p/74398.html上一篇: 如何使用AutoMapper模拟列表转换
下一篇: 单元测试Automapper配置文件