コード例 #1
0
        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);
        }
コード例 #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));
            }
コード例 #3
0
ファイル: AutoMapperInstaller.cs プロジェクト: jalex/Swarm
        private ConfigurationStore InstanceConfigurationStore(IKernel kernel)
        {
            ITypeMapFactory             typeMapFactory = kernel.Resolve <ITypeMapFactory>();
            IEnumerable <IObjectMapper> mappers        = MapperRegistry.AllMappers();

            return(new ConfigurationStore(typeMapFactory, mappers));
        }
コード例 #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);
 }
コード例 #5
0
 private void RegisterIConfigurationProviderAndIProfileExpression(IKernel kernel)
 {
     kernel.Register(
         Component.For <IConfigurationProvider, IProfileExpression>()
         .UsingFactoryMethod(k => new Configuration(MapperRegistry.AllMappers()))
         );
 }
コード例 #6
0
        public MapperConfiguration(Action<MapperRegistry> initializationExpression)
        {
            if (initializationExpression == null) throw new ArgumentNullException("initializationExpression");

            var registry = new MapperRegistry();

            initializationExpression(registry);
        }
コード例 #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);
        }
コード例 #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);
            }
        }
コード例 #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));
        }
コード例 #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);
		}
コード例 #11
0
        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>();
        }
コード例 #12
0
        public void Should_Create_Valid_Map()
        {
            // arrange
            var configuration = new Configuration(MapperRegistry.AllMappers());

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

            // assert
            configuration.AssertConfigurationIsValid();
        }
コード例 #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));
        }
コード例 #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);
        }
コード例 #15
0
ファイル: TestContext.cs プロジェクト: kouweizhong/Guidelines
        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));
            }
        }
コード例 #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);
		}
コード例 #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;
        }
コード例 #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);
		}
コード例 #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();
 }
コード例 #20
0
ファイル: MapingEngine.cs プロジェクト: saber-wang/nlite
        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);
        }
コード例 #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);
        }
コード例 #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()
                 );
        }
コード例 #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);
        }
コード例 #24
0
 protected ReportsRepository()
 {
     MapperRegistry.Initialize();
 }
コード例 #25
0
 public static ConfigurationStore CreateDefaultConfiguration()
 {
     return(new ConfigurationStore(new TypeMapFactory(), MapperRegistry.AllMappers()));
 }
コード例 #26
0
 /// <summary>
 /// Clear out all existing configuration
 /// </summary>
 public static void Reset()
 {
     MapperRegistry.Reset();
     _configuration = LazyFactory.Create(_configurationInit);
     _mappingEngine = LazyFactory.Create(_mappingEngineInit);
 }
コード例 #27
0
 public static IMappingEngine RawMappingEngine()
 {
     return(new MappingEngine(new ConfigurationStore(new TypeMapFactory(), MapperRegistry.AllMappers())));
 }
コード例 #28
0
 public DefaultRequestFactory(MapperRegistry mapper_registry)
 {
     this.mapper_registry = mapper_registry;
 }
コード例 #29
0
 private static ConfigurationStore CreateConfiguration()
 {
     return(new ConfigurationStore(new TypeMapFactory(), MapperRegistry.AllMappers()));
 }
コード例 #30
0
ファイル: MapperConfiguration.cs プロジェクト: sclcwwl/Gimela
        public MapperConfiguration(Action<MapperRegistry> initializationExpression)
        {
            var registry = new MapperRegistry();

            initializationExpression(registry);
        }
コード例 #31
0
        public MapperConfigurationExpression() : base()
        {
            IncludeSourceExtensionMethods(typeof(Enumerable));

            Mappers = MapperRegistry.Mappers();
        }
コード例 #32
0
ファイル: Mapper.cs プロジェクト: pbehin/AutoMapper
 public static void Reset()
 {
     MapperRegistry.Reset();
     _configuration = new Lazy <MapperConfiguration>(_configurationInit);
     _mappingEngine = new Lazy <Mapper>(_mappingEngineInit);
 }
コード例 #33
0
 public static void ResetMapper()
 {
     //upgrade v5.0 this method is obsolete
     //Mapper.Reset();
     MapperRegistry.Reset();
 }