예제 #1
0
 private void RegisterIConfigurationProviderAndIProfileExpression(IKernel kernel)
 {
     kernel.Register(
         Component.For <IConfigurationProvider, IProfileExpression>()
         .UsingFactoryMethod(k => new Configuration(MapperRegistry.AllMappers()))
         );
 }
예제 #2
0
        private ConfigurationStore InstanceConfigurationStore(IKernel kernel)
        {
            ITypeMapFactory             typeMapFactory = kernel.Resolve <ITypeMapFactory>();
            IEnumerable <IObjectMapper> mappers        = MapperRegistry.AllMappers();

            return(new ConfigurationStore(typeMapFactory, mappers));
        }
        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);
        }
예제 #4
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));
            }
예제 #5
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);
        }
예제 #6
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);
            }
        }
예제 #7
0
        public void Should_Create_Valid_Map()
        {
            // arrange
            var configuration = new Configuration(MapperRegistry.AllMappers());

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

            // assert
            configuration.AssertConfigurationIsValid();
        }
예제 #8
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));
        }
        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>();
        }
예제 #10
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));
            }
        }
예제 #11
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;
        }
예제 #12
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();
 }
예제 #13
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()
                 );
        }
예제 #14
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);
        }
예제 #15
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);
        }
예제 #16
0
 public static ConfigurationStore CreateDefaultConfiguration()
 {
     return(new ConfigurationStore(new TypeMapFactory(), MapperRegistry.AllMappers()));
 }
 public static IMappingEngine RawMappingEngine()
 {
     return(new MappingEngine(new ConfigurationStore(new TypeMapFactory(), MapperRegistry.AllMappers())));
 }
예제 #18
0
 private static ConfigurationStore CreateConfiguration()
 {
     return(new ConfigurationStore(new TypeMapFactory(), MapperRegistry.AllMappers()));
 }