AutoMapper IMappingEngine ConfigurationStore初始化不会发生

时间:2016-05-05 12:16:42

标签: asp.net-mvc-4 c#-4.0 automapper automapper-3

使用的AutoMapper版本:3.3.10

[TestClass]
public class AppControllerTests
{
    private IMappingEngine _mappingEngine = null;
    private ConfigurationStore _configurationStore = null;

    [TestInitialize]
    public void SetUp()
    {
      _configurationStore = new ConfigurationStore(new TypeMapFactory(), MapperRegistry.Mappers);
        _configurationStore.AddProfile(new AutoMapperProfile.AppProfile());
        _mappingEngine = new MappingEngine(_configurationStore);
     }

     [TestMethod]
    public void GetAppByAccountID()
    {
        // Error line 
        var mappingResult = _mappingEngine.Map<Category>(categoryList).AsQueryable();
    }
}

public class AppProfile : Profile
{
    protected override void Configure()
    {
      AutoMapperMappingConfigurations();
    }
    public void AutoMapperMappingConfigurations()
    {
         Mapper.CreateMap<DomainModels.Category, Category>().ReverseMap();
    }
}

例外:

  

“AutoMapper.AutoMapperMappingException”类型的例外   发生在AutoMapper.dll中,但未在用户代码中处理。

怀疑

_configurationStore.AddProfile(new OOS.PresentationModelService.AutoMapperProfile.AppProfile());
如果我编写手动映射它按预期工作,

无法创建AppProfile的等价。

_configurationStore.CreateMap<Category, Category>().ReverseMap();

0 个答案:

没有答案