public void ShouldMapToNewISet() { var config = new ConfigurationStore(new TypeMapFactory(), MapperRegistry.AllMappers()); config.CreateMap <SourceWithIEnumerable, TargetWithISet>() .ForMember(dest => dest.Stuff, opt => opt.MapFrom(src => src.Stuff.Select(s => s.Value))); config.AssertConfigurationIsValid(); var engine = new MappingEngine(config); var source = new SourceWithIEnumerable { Stuff = new[] { new TypeWithStringProperty { Value = "Microphone" }, new TypeWithStringProperty { Value = "Check" }, new TypeWithStringProperty { Value = "1, 2" }, new TypeWithStringProperty { Value = "What is this?" } } }; var target = engine.Map <SourceWithIEnumerable, TargetWithISet>(source); }
protected override void Establish_context() { _configuration = new Configuration(new TypeMapFactory(), MapperRegistry.AllMappers()); _configuration.CreateMap <Source, Destination>(); _expected = _configuration.FindTypeMapFor(null, typeof(Source), typeof(Destination)); }
private ConfigurationStore InstanceConfigurationStore(IKernel kernel) { ITypeMapFactory typeMapFactory = kernel.Resolve <ITypeMapFactory>(); IEnumerable <IObjectMapper> mappers = MapperRegistry.AllMappers(); return(new ConfigurationStore(typeMapFactory, mappers)); }
/// <summary> /// Clear out all existing configuration /// </summary> public static void Reset() { MapperRegistry.Reset(); Extensions.ClearExpressionCache(); _configuration = LazyFactory.Create(_configurationInit); _mappingEngine = LazyFactory.Create(_mappingEngineInit); }
private void RegisterIConfigurationProviderAndIProfileExpression(IKernel kernel) { kernel.Register( Component.For <IConfigurationProvider, IProfileExpression>() .UsingFactoryMethod(k => new Configuration(MapperRegistry.AllMappers())) ); }
public MapperConfiguration(Action<MapperRegistry> initializationExpression) { if (initializationExpression == null) throw new ArgumentNullException("initializationExpression"); var registry = new MapperRegistry(); initializationExpression(registry); }
/// <summary> /// Create a configuration object. /// </summary> /// <returns>Default configuration for framework use.</returns> public static ConfigurationStore CreateDefaultConfiguration() { var configuration = new ConfigurationStore(new TypeMapFactory(), MapperRegistry.AllMappers()); configuration.RecognizeDestinationPostfixes("Text"); configuration.CreateMap <Enum, string>().ConvertUsing <EnumTypeConverter>(); return(configuration); }
public Mapper(IEnumerable <IMapperProfile> mapperProfiles) { _configuration = new AutoMapper.Configuration(new TypeMapFactory(), MapperRegistry.AllMappers()); _mappingEngine = new MappingEngine(_configuration); foreach (var mapperProfile in mapperProfiles) { _configuration.CreateProfile(mapperProfile.GetType().FullName, mapperProfile.Initialize); } }
internal IMapper GetOrCreateMap(Type fromType, Type toType) { var key = fromType.FullName + "->" + toType.FullName; if (MapperRegistry.ContainsKey(key)) { return(MapperRegistry[key]); } return(CreateMap(fromType, toType, key)); }
public void TestPipelineDataaIsNullThrowsException() { var registry = new MapperRegistry(); registry.Add(new FakeMap()); var map = registry.Get<ICommandMetadata, IInputModel>(); Assert.NotNull(map); var step = new GetInputModelStep(registry); var data = step.Execute(null); }
public AutomapperRegistry() { For <ConfigurationStore>().Singleton().Use <ConfigurationStore>() .Ctor <IEnumerable <IObjectMapper> >().Is(MapperRegistry.AllMappers()); For <IConfigurationProvider>().Use(ctx => ctx.GetInstance <ConfigurationStore>()); For <IConfiguration>().Use(ctx => ctx.GetInstance <ConfigurationStore>()); For <ITypeMapFactory>().Use <TypeMapFactory>(); For <IMappingEngine>().Use <MappingEngine>(); For <IEntityMapper>().Use <EntityMapper>(); }
public void Should_Create_Valid_Map() { // arrange var configuration = new Configuration(MapperRegistry.AllMappers()); // act new IndexModelToEmailMapCreator().CreateMap(configuration); // assert configuration.AssertConfigurationIsValid(); }
public void Should_Create_Map() { // arrange var configuration = new Configuration(MapperRegistry.AllMappers()); // act new IndexModelToEmailMapCreator().CreateMap(configuration); // assert Assert.That(configuration.GetAllTypeMaps(), Is.Not.Null & Has.Length.EqualTo(1)); }
public void TestRegistry() { //Arrange var mockMap = new Mock<IMapper<int, string>>(); mockMap.Setup(m => m.Source).Returns(typeof (int)); mockMap.Setup(m => m.Destination).Returns(typeof (string)); var registry = new MapperRegistry(); registry.Add(mockMap.Object); var map = registry.Get<int, string>(); Assert.NotNull(map); }
static TestContext() { var config = new ConfigurationStore(new TypeMapFactory(), MapperRegistry.AllMappers()); Mapper = new MappingEngine(config); var mappings = GetMappingProfileTypes <CoreMarker>(); mappings = mappings.Union(GetMappingProfileTypes <MappingAutoMapperMarker>()); foreach (var mapping in mappings) { config.AddProfile((Profile)Activator.CreateInstance(mapping)); } }
public void TestPipelineDataContainsNullValue() { var registry = new MapperRegistry(); registry.Add(new FakeMap()); var map = registry.Get<ICommandMetadata, IInputModel>(); Assert.NotNull(map); var data = new MapCommandPipelineData { CommandMetadata = null }; var step = new GetInputModelStep(registry); data = step.Execute(data); }
private static IMappingEngine ConfigureMappingEngine() { var config = new ConfigurationStore(new TypeMapFactory(), MapperRegistry.AllMappers()); ApplyMap.On(config).AddFromAssemblyOf <ProductMapCreator>().Apply(); config.AssertConfigurationIsValid(); return(new MappingEngine(config)); // Another way, Useful if we want to reuse the // static Mapper class' engine or we already have it // spread around in our code //Mapper.Initialize(cfg => // ApplyMap.On(cfg).AddFromAssemblyOf<ProductMapCreator>().Apply()); //return Mapper.Engine; }
public void TestMetadataToInputModelStep() { var registry = new MapperRegistry(); registry.Add(new FakeMap()); var map = registry.Get<ICommandMetadata, IInputModel>(); Assert.NotNull(map); var data = new MapCommandPipelineData { CommandMetadata = new Mock<ICommandMetadata>().Object }; var step = new GetInputModelStep(registry); data = step.Execute(data); Assert.NotNull(data.InputModel); }
protected override void Load(ContainerBuilder builder) { // Register the common thing once, not in each module. builder.RegisterType <MappingEngine>().As <IMappingEngine>(); // Here's where you dynamically get all the registered profiles // and add them at the same time to the config store. builder.Register(ctx => { var profiles = ctx.Resolve <IEnumerable <Profile> >(); var configStore = new ConfigurationStore (new TypeMapFactory(), MapperRegistry.AllMappers()); foreach (var profile in profiles) { configStore.AddProfile(profile); } return(configStore); }) .AsImplementedInterfaces() .SingleInstance(); }
private IMapper CreateMap(Type fromType, Type toType, string key) { IMapper mapper = null; foreach (var fac in FactoryRegistry) { if (fac.IsMatch(fromType, toType)) { mapper = CreateGenericMapper(fromType, toType, fac); MapperRegistry.Add(key, mapper); break; } } if (mapper == null) { throw new NotSupportedException("Mapper does not support " + key + "."); } return(mapper); }
public void should_inherit_base_aftermap() { // arrange var source = new Class { Prop = "test" }; var configurationProvider = new ConfigurationStore(new TypeMapFactory(), MapperRegistry.AllMappers()); configurationProvider .CreateMap <BaseClass, BaseDto>() .AfterMap((s, d) => d.DifferentProp = s.Prop) .Include <Class, Dto>(); configurationProvider.CreateMap <Class, Dto>(); var mappingEngine = new MappingEngine(configurationProvider); // act var dest = mappingEngine.Map <Class, Dto>(source); // assert Assert.AreEqual("test", dest.DifferentProp); }
public AutoMapperRegistry() { For <ConfigurationStore>() .Singleton() .Use <ConfigurationStore>() .Ctor <IEnumerable <IObjectMapper> >().Is(MapperRegistry.AllMappers()); For <IConfigurationProvider>() .Use(x => x.GetInstance <ConfigurationStore>()); For <IConfiguration>() .Use(x => x.GetInstance <ConfigurationStore>()); For <ITypeMapFactory>() .Use(x => x.GetInstance <TypeMapFactory>()); For <IMappingEngine>().Use(Mapper.Engine); Scan(x => x.TheCallingAssembly() ); }
public void ShouldMapOneToTwo() { var config = new ConfigurationStore(new TypeMapFactory(), MapperRegistry.AllMappers()); config.CreateMap <One, Two>(); config.CreateMap <IEnumerable <string>, IEnumerable <Item> >().ConvertUsing <StringToItemConverter>(); config.AssertConfigurationIsValid(); var engine = new MappingEngine(config); var one = new One { Stuff = new List <string> { "hi", "", "mom" } }; var two = engine.Map <One, Two>(one); two.ShouldNotBeNull(); two.Stuff.Count().ShouldEqual(2); }
protected ReportsRepository() { MapperRegistry.Initialize(); }
public static ConfigurationStore CreateDefaultConfiguration() { return(new ConfigurationStore(new TypeMapFactory(), MapperRegistry.AllMappers())); }
/// <summary> /// Clear out all existing configuration /// </summary> public static void Reset() { MapperRegistry.Reset(); _configuration = LazyFactory.Create(_configurationInit); _mappingEngine = LazyFactory.Create(_mappingEngineInit); }
public static IMappingEngine RawMappingEngine() { return(new MappingEngine(new ConfigurationStore(new TypeMapFactory(), MapperRegistry.AllMappers()))); }
public DefaultRequestFactory(MapperRegistry mapper_registry) { this.mapper_registry = mapper_registry; }
private static ConfigurationStore CreateConfiguration() { return(new ConfigurationStore(new TypeMapFactory(), MapperRegistry.AllMappers())); }
public MapperConfiguration(Action<MapperRegistry> initializationExpression) { var registry = new MapperRegistry(); initializationExpression(registry); }
public MapperConfigurationExpression() : base() { IncludeSourceExtensionMethods(typeof(Enumerable)); Mappers = MapperRegistry.Mappers(); }
public static void Reset() { MapperRegistry.Reset(); _configuration = new Lazy <MapperConfiguration>(_configurationInit); _mappingEngine = new Lazy <Mapper>(_mappingEngineInit); }
public static void ResetMapper() { //upgrade v5.0 this method is obsolete //Mapper.Reset(); MapperRegistry.Reset(); }