对于初学者,我正在使用这个模块:
public class AutoMapperModule : NinjectModule
{
public override void Load()
{
Bind<ITypeMapFactory>().To<TypeMapFactory>();
foreach (var mapper in MapperRegistry.AllMappers())
{
Bind<IObjectMapper>().ToConstant(mapper);
}
Bind<AutoMapper.ConfigurationStore>().ToSelf().InSingletonScope().WithConstructorArgument("mappers", ctx => ctx.Kernel.GetAll<IObjectMapper>());
Bind<IConfiguration>().ToMethod(ctx => ctx.Kernel.Get<AutoMapper.ConfigurationStore>());
Bind<IConfigurationProvider>().ToMethod(ctx => ctx.Kernel.Get<AutoMapper.ConfigurationStore>());
Bind<IMappingEngine>().To<MappingEngine>();
}
}
我的所有地图都有一个引导程序类
public static void Configure(IKernel kernel)
{
Mapper.Initialize(map => map.ConstructServicesUsing(t => kernel.Get(t)));
}
我有访问数据库并需要注入存储库的解析器。它按原样工作,但我不知道如何让它与单元测试和 IMappingEngine 一起工作。
public HomeController(IMappingEngine mappingEngine)
{
_mappingEngine = mappingEngine;
}
_mappingEngine.Map 抛出异常,因为不存在地图。Mapper.Map 有效。
我错过了什么?如何让我的引导程序使用单元测试,以便解析器中的存储库使用假/模拟存储库?