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);
        }
Exemplo n.º 2
0
            protected override void Establish_context()
            {
                _configuration = new Configuration(new TypeMapFactory(), MapperRegistry.AllMappers());
                _configuration.CreateMap <Source, Destination>();

                _expected = _configuration.FindTypeMapFor(null, typeof(Source), typeof(Destination));
            }
Exemplo n.º 3
0
        private ConfigurationStore InstanceConfigurationStore(IKernel kernel)
        {
            ITypeMapFactory             typeMapFactory = kernel.Resolve <ITypeMapFactory>();
            IEnumerable <IObjectMapper> mappers        = MapperRegistry.AllMappers();

            return(new ConfigurationStore(typeMapFactory, mappers));
        }
Exemplo n.º 4
0
 /// <summary>
 /// Clear out all existing configuration
 /// </summary>
 public static void Reset()
 {
     MapperRegistry.Reset();
     Extensions.ClearExpressionCache();
     _configuration = LazyFactory.Create(_configurationInit);
     _mappingEngine = LazyFactory.Create(_mappingEngineInit);
 }
Exemplo n.º 5
0
 private void RegisterIConfigurationProviderAndIProfileExpression(IKernel kernel)
 {
     kernel.Register(
         Component.For <IConfigurationProvider, IProfileExpression>()
         .UsingFactoryMethod(k => new Configuration(MapperRegistry.AllMappers()))
         );
 }
Exemplo n.º 6
0
        public MapperConfiguration(Action<MapperRegistry> initializationExpression)
        {
            if (initializationExpression == null) throw new ArgumentNullException("initializationExpression");

            var registry = new MapperRegistry();

            initializationExpression(registry);
        }
Exemplo n.º 7
0
        /// <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);
        }
Exemplo n.º 8
0
        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);
            }
        }
Exemplo n.º 9
0
        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));
        }
Exemplo n.º 10
0
		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>();
        }
Exemplo n.º 12
0
        public void Should_Create_Valid_Map()
        {
            // arrange
            var configuration = new Configuration(MapperRegistry.AllMappers());

            // act
            new IndexModelToEmailMapCreator().CreateMap(configuration);

            // assert
            configuration.AssertConfigurationIsValid();
        }
Exemplo n.º 13
0
        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));
        }
Exemplo n.º 14
0
        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);
        }
Exemplo n.º 15
0
        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));
            }
        }
Exemplo n.º 16
0
		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);
		}
Exemplo n.º 17
0
        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;
        }
Exemplo n.º 18
0
		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);
		}
Exemplo n.º 19
0
 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();
 }
Exemplo n.º 20
0
        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);
        }
Exemplo n.º 21
0
        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);
        }
Exemplo n.º 22
0
        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()
                 );
        }
Exemplo n.º 23
0
        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);
        }
Exemplo n.º 24
0
 protected ReportsRepository()
 {
     MapperRegistry.Initialize();
 }
Exemplo n.º 25
0
 public static ConfigurationStore CreateDefaultConfiguration()
 {
     return(new ConfigurationStore(new TypeMapFactory(), MapperRegistry.AllMappers()));
 }
Exemplo n.º 26
0
 /// <summary>
 /// Clear out all existing configuration
 /// </summary>
 public static void Reset()
 {
     MapperRegistry.Reset();
     _configuration = LazyFactory.Create(_configurationInit);
     _mappingEngine = LazyFactory.Create(_mappingEngineInit);
 }
Exemplo n.º 27
0
 public static IMappingEngine RawMappingEngine()
 {
     return(new MappingEngine(new ConfigurationStore(new TypeMapFactory(), MapperRegistry.AllMappers())));
 }
Exemplo n.º 28
0
 public DefaultRequestFactory(MapperRegistry mapper_registry)
 {
     this.mapper_registry = mapper_registry;
 }
Exemplo n.º 29
0
 private static ConfigurationStore CreateConfiguration()
 {
     return(new ConfigurationStore(new TypeMapFactory(), MapperRegistry.AllMappers()));
 }
Exemplo n.º 30
0
        public MapperConfiguration(Action<MapperRegistry> initializationExpression)
        {
            var registry = new MapperRegistry();

            initializationExpression(registry);
        }
Exemplo n.º 31
0
        public MapperConfigurationExpression() : base()
        {
            IncludeSourceExtensionMethods(typeof(Enumerable));

            Mappers = MapperRegistry.Mappers();
        }
Exemplo n.º 32
0
 public static void Reset()
 {
     MapperRegistry.Reset();
     _configuration = new Lazy <MapperConfiguration>(_configurationInit);
     _mappingEngine = new Lazy <Mapper>(_mappingEngineInit);
 }
Exemplo n.º 33
0
 public static void ResetMapper()
 {
     //upgrade v5.0 this method is obsolete
     //Mapper.Reset();
     MapperRegistry.Reset();
 }