单元测试Automapper配置文件 [英] Unit test the Automapper profiles
问题描述
我想要要在CreateMap
方法中测试自定义逻辑.我确实不要测试某些类型的映射是否存在.
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)));
}
}
推荐答案
这是用于配置测试的文档: http://docs.automapper.org/en/stable/Configuration-validation.html
This is the documentation for configuration testing: http://docs.automapper.org/en/stable/Configuration-validation.html
您可以在此处查看示例: https://stackoverflow.com/a/14150006/1505426
You can see an example of it here: https://stackoverflow.com/a/14150006/1505426
这篇关于单元测试Automapper配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!