我确实希望在CreateMap
方法中测试自定义逻辑。我不是而是想测试某些类型的映射是否存在。
我该怎么做,或者我需要知道什么类。我很感谢文件中的每一个提示。自动映射器单元测试似乎非常少...
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
您可以在此处查看示例:https://stackoverflow.com/a/14150006/1505426
关于unit-testing - 单元测试Automapper配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14177455/