Пример #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()));
 }