コード例 #1
0
        public void WithSourceAddress()
        {
            var factory = MappingBuilder.DiscoverIn <Employee>().BuildFactory();
            var mapper  = factory.Create <Employee, EmployeeView>();
            var source  = new Employee
            {
                FirstName   = "Homer",
                LastName    = "Simpson",
                Age         = 40,
                IsMale      = true,
                HomeAddress = new Address
                {
                    HouseNumber = 742,
                    Street      = "Evergreen Terrace",
                    Town        = "Springfield"
                }
            };

            var target = mapper.Map(source);

            target.FirstName.ShouldBe(source.FirstName);
            target.LastName.ShouldBe(source.LastName);
            target.Age.ShouldBe(source.Age);
            target.IsMale.ShouldBe(source.IsMale);
            target.HomeAddress.ShouldBe("742 Evergreen Terrace, Springfield");
        }
コード例 #2
0
        private ObjectsMapperBaseImpl BuildObjectsMapper(
            string MapperTypeName,
            Type from,
            Type to,
            IMappingConfigurator mappingConfigurator)
        {
            TypeBuilder typeBuilder = DynamicAssemblyManager.DefineMapperType(MapperTypeName);

            CreateTargetInstanceBuilder.BuildCreateTargetInstanceMethod(to, typeBuilder);

            var mappingBuilder = new MappingBuilder(
                this,
                from,
                to,
                typeBuilder,
                mappingConfigurator
                );

            mappingBuilder.BuildCopyImplMethod();

            ObjectsMapperBaseImpl result =
                (ObjectsMapperBaseImpl)Activator.CreateInstance(typeBuilder.CreateType());

            result.Initialize(this, from, to, mappingConfigurator, mappingBuilder.storedObjects.ToArray());
            return(result);
        }
コード例 #3
0
 public void MappingBuilder_SameAssemblyAddedTwice_AndDiscoverIn_ThrowsException()
 {
     var exception = Should.Throw<ArgumentException>(() =>
         MappingBuilder.DiscoverIn<MappingBuilderTests>().AndDiscoverIn<MappingFactoryTests>());
     
     exception.Message.ShouldStartWith("Already added mappings in assembly HyperMap.Tests");
 }
コード例 #4
0
ファイル: MappingTests.cs プロジェクト: ahmadnazir/sdk-net
        public void StringMappingTest()
        {
            const string title = "My Title";

            var mapping = new MappingBuilder <CaseFile>()
                          .ForCreate()
                          .Map(x => x.Title)
                          .ForUpdate()
                          .Map(x => x.Title)
                          .GetMapping();

            var obj = new CaseFile {
                Title = title
            };
            var createValues = mapping.GetCreateValues(obj);
            var updateValues = mapping.GetUpdateValues(obj);

            Assert.IsNotNull(createValues);
            Assert.IsTrue(createValues.Count == 1);
            Assert.AreEqual(title, (string)createValues["Title"]);

            Assert.IsNotNull(updateValues);
            Assert.IsTrue(updateValues.Count == 1);
            Assert.AreEqual(title, (string)updateValues["Title"]);
        }
コード例 #5
0
ファイル: MappingTests.cs プロジェクト: ahmadnazir/sdk-net
        public void IntegerMappingTest()
        {
            const int status = 3;

            var mapping = new MappingBuilder <CaseFile>()
                          .ForCreate()
                          .Map(x => x.Status)
                          .ForUpdate()
                          .Map(x => x.Status)
                          .GetMapping();

            var obj = new CaseFile {
                Status = 3
            };
            var createValues = mapping.GetCreateValues(obj);
            var updateValues = mapping.GetUpdateValues(obj);

            Assert.IsNotNull(createValues);
            Assert.IsTrue(createValues.Count == 1);
            Assert.AreEqual(status, (int)createValues["Status"]);

            Assert.IsNotNull(updateValues);
            Assert.IsTrue(updateValues.Count == 1);
            Assert.AreEqual(status, (int)updateValues["Status"]);
        }
コード例 #6
0
        public void MappingFactoryExtensions_WithMappingFactory_RegisterWith_ReturnsMappingFactory()
        {
            var services = new ServiceCollection();

            var factory = MappingBuilder.DiscoverIn <User>().BuildFactory().RegisterWith(services);

            factory.ShouldNotBeNull();
        }
コード例 #7
0
        public void Issue_Should_Map_To_Redmine_Issue()
        {
            var redmineRepository = new RedmineRepository();
            var mapper            = MappingBuilder.Build();

            var testIssue    = MakeTestIssue();
            var redmineIssue = mapper.Map <Issue>(testIssue);
            var commonIssue  = mapper.Map <CommonRemineEntities.Issue>(redmineIssue);
        }
コード例 #8
0
        private void DefaultMappings()
        {
            var mappingBuilder = new MappingBuilder(new[] { new MappingFromFluent(null) });

            mappingBuilder.FromAssemblyOf <IFluentMapsVisitor>();
            foreach (var source in mappingBuilder.Sources)
            {
                SharedComponent(source, source.Description);
            }
        }
コード例 #9
0
        private MappingBuilder ResumeUploadRequest(string uploadLocationPath, long position, long length)
        {
            MappingBuilder builder = put(urlEqualTo(uploadLocationPath)).withHeader("Content-Length", equalTo(Convert.ToString(length - position)));

            if (position > 0)
            {
                builder = builder.withHeader("Content-Range", equalTo(format("bytes %d-%d/%d", position, length - 1, length)));
            }
            return(builder);
        }
コード例 #10
0
 public void MappingBuilder_WithCustomNamespace_BuildFactory_ReturnsFactory()
 {
     var options = new CompilerOptions
     {
         AssemblyName = "Test.Mappings"
     };
     
     var factory = MappingBuilder.DiscoverIn<MappingBuilderTests>().BuildFactory(options);
     
     factory.ShouldNotBeNull();
 }
コード例 #11
0
        private void DefaultMappings()
        {
            var mappingBuilder = new MappingBuilder(new[] { new MappingFromAttributes(_log) });

            mappingBuilder.FromAssemblyOf <ITypedEntity>();
            mappingBuilder.AddMapping(typeof(ITypedEntity).GetTypeInfo().Assembly, new InternalsMappingsSource(typeof(ITypedEntity).GetTypeInfo().Assembly));
            foreach (var source in mappingBuilder.Sources)
            {
                _container.RegisterInstance(source, source.Description);
            }
        }
コード例 #12
0
        public void MappingFactoryExtensions_WithMappingFactory_RegisterWith_AddsMappersIntoCollection()
        {
            var services = new ServiceCollection();

            MappingBuilder.DiscoverIn <User>().BuildFactory().RegisterWith(services);

            var provider = services.BuildServiceProvider();
            var mapper2  = provider.GetService <IMapper <User, UserView> >();

            mapper2.ShouldNotBeNull();
        }
コード例 #13
0
        protected override void ScenarioSetup()
        {
            var entityMapping = new Mock <IEntityMapping>(MockBehavior.Strict);

            entityMapping.SetupGet(instance => instance.Type).Returns(typeof(IProduct));
            MappingBuilder.Setup(instance => instance.BuildMappings(It.IsAny <IEnumerable <IMappingSource> >(), It.IsAny <IDictionary <Type, ICollection <ITermMappingProvider> > >()))
            .Returns(new Dictionary <Type, IEntityMapping>()
            {
                { typeof(IProduct), entityMapping.Object }
            });
        }
コード例 #14
0
        public void MappingFactoryExtensions_WithMappingFactory_RegisterWith_CollectionInstanceMatchesFactory()
        {
            var services = new ServiceCollection();

            var factory = MappingBuilder.DiscoverIn <User>().BuildFactory().RegisterWith(services);

            var mapper1  = factory.Create <User, UserView>();
            var provider = services.BuildServiceProvider();
            var mapper2  = provider.GetService <IMapper <User, UserView> >();

            mapper2.ShouldBe(mapper1);
        }
コード例 #15
0
        private void BuildMappingAssemblies(MappingBuilder builder, IEnumerable <Assembly> mappingAssemblies)
        {
            if (mappingAssemblies == null)
            {
                return;
            }

            foreach (var assembly in mappingAssemblies)
            {
                builder.FromAssembly(assembly);
            }
        }
コード例 #16
0
        private Mapping <SqlStorageModel <TEntity>, SqlStorageField <TEntity>, TypeModel <TView>, PropertyField> BuildMapping()
        {
            lock (_syncLock)
            {
                if (_mapping != null)
                {
                    return(_mapping);
                }

                var builder = new MappingBuilder <SqlStorageModel <TEntity>, SqlStorageField <TEntity>, TypeModel <TView>, PropertyField>(this);
                return(builder.Build());
            }
        }
コード例 #17
0
ファイル: Program.cs プロジェクト: mikezhuyuan/POCO_Demo
        protected override void OnMapping(MappingBuilder builder)
        {
            builder.Entity<Assignment>()
                   .PropertyName(_ => _.Parent_id, "ParentAssignment_id")
                   .PropertyValue(_ => _.AssignmentType, "AssignmentTypeCode",
                                 (string code) => (AssignmentType)Enum.Parse(typeof(AssignmentType), code))
                   ;

            //.Create(reader=>new Assignment(){Assignment_id = (int)reader["Assignment_id"]})
            //.IgnoreProperty(_ => _.Title)
            //.IgnoreProperty(_ => _.Parent_id)
            //.IgnoreProperty(_ => _.AssignmentType)
        }
コード例 #18
0
ファイル: MappingTests.cs プロジェクト: ahmadnazir/sdk-net
        public void KeyNotFoundTest()
        {
            var mapping = new MappingBuilder <CaseFile>()
                          .ForCreate()
                          .Map(x => x.Title)
                          .GetMapping();

            var obj = new CaseFile {
                Status = 3
            };

            mapping.GetUpdateValues(obj); //only create mapping created, so this should fail
        }
コード例 #19
0
        public void WithSourceEnum()
        {
            var factory = MappingBuilder.DiscoverIn <Login>().BuildFactory();
            var mapper  = factory.Create <Login, LoginView>();
            var source  = new Login {
                Name = "homer.simpson", States = LoginStates.Locked
            };

            var target = mapper.Map(source);

            target.Name.ShouldBe(source.Name);
            target.State.ShouldBe(source.States.ToString());
        }
コード例 #20
0
        /// <summary>Exposes the method to register mapping repositories.</summary>
        /// <param name="buildMappings">Delegate method to be used for building mappings.</param>
        /// <returns>This <see cref="EntityContextFactory" /> </returns>
        public EntityContextFactory WithMappings(Action <MappingBuilder> buildMappings)
        {
            var mappingBuilder = new MappingBuilder(_container.GetAllInstances <IMappingFrom>());

            _container.Invalidate();
            buildMappings.Invoke(mappingBuilder);
            foreach (var source in mappingBuilder.Sources)
            {
                _container.RegisterInstance(source, source.Description);
            }

            return(this);
        }
コード例 #21
0
        public MappingBuilder <T> AddTypeMapping <T>() where T : ControlTagHelper
        {
            Type typeOfT = typeof(T);

            if (this.MappingBuilders.ContainsKey(typeOfT))
            {
                return((MappingBuilder <T>) this.MappingBuilders[typeOfT]);
            }
            var mappingBuilder = new MappingBuilder <T>();

            this.MappingBuilders.Add(typeOfT, mappingBuilder);
            return(mappingBuilder);
        }
コード例 #22
0
        public void WithCustomConverter()
        {
            var factory = MappingBuilder.DiscoverIn <Address>().BuildFactory();
            var mapper  = factory.Create <Address, SingleLineAddressView>();
            var source  = new Address
            {
                HouseNumber = 742,
                Street      = "Evergreen Terrace",
                Town        = "Springfield"
            };

            var target = mapper.Map(source);

            target.Display.ShouldBe("742 Evergreen Terrace, Springfield");
        }
コード例 #23
0
ファイル: MappingTests.cs プロジェクト: lhotrifork/sdk-net
        public void KeyNotFoundTest()
        {
            var mapping = new MappingBuilder <CaseFile>()
                          .ForCreate()
                          .Map(x => x.Title)
                          .GetMapping();

            var obj = new CaseFile()
            {
                Status = 3
            };

            //only create mapping created, so this should fail
            Assert.That(() => mapping.GetUpdateValues(obj), Throws.TypeOf <KeyNotFoundException>());
        }
コード例 #24
0
        public override ISet <Item> Create()
        {
            var mapping = MappingBuilder
                          .WithIndex(Guid.NewGuid().ToString())
                          .WithKeyField("GuidProperty")
                          .Build();

            var settings =
                new ConnectionSettings(new Uri("http://127.0.0.1:9200"))
                .DefaultIndex("tests");

            return(new DelayedSetDecorator <Item>(
                       new ElasticsearchSet <Item>(
                           new ElasticClient(settings), mapping), 1000));
        }
コード例 #25
0
        protected override void ScenarioSetup()
        {
            var entityMapping = new Mock <IEntityMapping>(MockBehavior.Strict);

            entityMapping.SetupGet(instance => instance.Type).Returns(typeof(IProduct));
            var classMapping = new Mock <IStatementMapping>(MockBehavior.Strict);

            classMapping.SetupGet(instance => instance.Term).Returns(new Iri(ExpectedClass));
            classMapping.SetupGet(instance => instance.Graph).Returns((Iri)null);
            entityMapping.SetupGet(instance => instance.Classes).Returns(new[] { classMapping.Object });
            MappingBuilder.Setup(instance => instance.BuildMappings(It.IsAny <IEnumerable <IMappingSource> >(), It.IsAny <IDictionary <Type, ICollection <ITermMappingProvider> > >()))
            .Returns(new Dictionary <Type, IEntityMapping>()
            {
                { typeof(IProduct), entityMapping.Object }
            });
        }
コード例 #26
0
        public void WithDefaultConverters()
        {
            var factory = MappingBuilder.DiscoverIn <Address>().BuildFactory();
            var mapper  = factory.Create <Address, AddressView>();
            var source  = new Address
            {
                HouseNumber = 742,
                Street      = "Evergreen Terrace",
                Town        = "Springfield"
            };

            var target = mapper.Map(source);

            target.HouseNumber.ShouldBe(source.HouseNumber.ToString());
            target.Street.ShouldBe(source.Street);
            target.Town.ShouldBe(source.Town);
        }
コード例 #27
0
        protected override void ScenarioSetup()
        {
            MappingBuilder.Setup(instance => instance.BuildMappings(It.IsAny <IEnumerable <IMappingSource> >(), It.IsAny <IDictionary <Type, ICollection <ITermMappingProvider> > >()))
            .Returns(new Dictionary <Type, IEntityMapping>()
            {
                { typeof(IComplexEntity), CreateEntityMapping <IComplexEntity>(new Iri("ComplexEntity")) },
                { typeof(IProduct), CreateEntityMapping <IProduct>(new Iri("Product")) }
            });
            var entitySource   = new Mock <IEntitySource>(MockBehavior.Strict);
            var changeDetector = new Mock <IChangeDetector>(MockBehavior.Strict);
            var context        = new Mock <DefaultEntityContext>(MockBehavior.Strict, entitySource.Object, MappingsRepository, changeDetector.Object);

            context.SetupGet(instance => instance.Mappings).Returns(() => MappingsRepository);
            var entity = new Entity(new Iri(), context.Object);

            entity.CastedTypes.Add(typeof(IProduct));
            Entity = entity;
        }
コード例 #28
0
        public void WithList()
        {
            var factory = MappingBuilder.DiscoverIn <Customer>().BuildFactory();
            var mapper  = factory.Create <Customer, CustomerListView>();
            var source  = new Customer
            {
                Name   = "Homer Simpson",
                Orders = new[]
                {
                    new Order
                    {
                        Id = 101, Description = "Slippers", Quantity = 1
                    },
                    new Order
                    {
                        Id = 201, Description = "Socks", Quantity = 3
                    }
                }
            };

            var target = mapper.Map(source);

            target.Name.ShouldBe(source.Name);
            var firstSourceOrder = source.Orders.First();
            var firstTargetOrder = target.Orders.First();

            firstTargetOrder.Id.ShouldBe(firstSourceOrder.Id);
            firstTargetOrder.Description.ShouldBe(firstSourceOrder.Description);
            firstTargetOrder.Quantity.ShouldBe(firstSourceOrder.Quantity);
            var secondSourceOrder = source.Orders.First();
            var secondTargetOrder = target.Orders.First();

            secondTargetOrder.Id.ShouldBe(secondSourceOrder.Id);
            secondTargetOrder.Description.ShouldBe(secondSourceOrder.Description);
            secondTargetOrder.Quantity.ShouldBe(secondSourceOrder.Quantity);
        }
コード例 #29
0
    private static void BuildType(INamedTypeSymbol source, INamedTypeSymbol destination, ImmutableArray <string> propertyNames,
                                  Compilation compilation, IndentedTextWriter indentWriter, NamespaceGatherer namespaces)
    {
        indentWriter.WriteLine($"public static partial class {source.Name}MapToExtensions");
        indentWriter.WriteLine("{");
        indentWriter.Indent++;

        var constructors = destination.Constructors.Where(_ => _.DeclaredAccessibility == Accessibility.Public ||
                                                          destination.ContainingAssembly.ExposesInternalsTo(compilation.Assembly) && _.DeclaredAccessibility == Accessibility.Friend).ToArray();

        for (var i = 0; i < constructors.Length; i++)
        {
            var constructor = constructors[i];
            MappingBuilder.BuildMapExtensionMethod(source, destination, propertyNames, constructor, namespaces, indentWriter);

            if (i < constructors.Length - 1)
            {
                indentWriter.WriteLine();
            }
        }

        indentWriter.Indent--;
        indentWriter.WriteLine("}");
    }
コード例 #30
0
 private static void DefaultMappings(MappingBuilder mappings)
 {
     mappings.Fluent.FromAssemblyOf<ITypedEntity>();
     mappings.Attributes.FromAssemblyOf<ITypedEntity>();
 }
コード例 #31
0
 protected override void BuildMappings(MappingBuilder m)
 {
     m.Fluent.FromAssemblyOf<AnimalMap>();
     m.AddMapping(GetType().Assembly, Mappings);
 }
コード例 #32
0
        /// <summary>Exposes the method to register mapping repositories.</summary>
        /// <param name="buildMappings">Delegate method to be used for building mappings.</param>
        /// <returns>This <see cref="EntityContextFactory" /> </returns>
        public EntityContextFactory WithMappings(Action<MappingBuilder> buildMappings)
        {
            var mappingBuilder = new MappingBuilder(_mappingsRepository);
            buildMappings.Invoke(mappingBuilder);

            return this;
        }
コード例 #33
0
 protected virtual void BuildMappings(MappingBuilder m)
 {
     m.FromAssemblyOf<IAnimal>();
     m.AddMapping(GetType().Assembly, Mappings);
 }
コード例 #34
0
 protected virtual void BuildMappings(MappingBuilder m)
 {
     m.FromAssemblyOf <IAnimal>();
     m.AddMapping(GetType().GetTypeInfo().Assembly, Mappings);
 }
コード例 #35
0
 public MappingFromFluent(MappingBuilder mappingBuilder)
     : base(mappingBuilder)
 {
 }
コード例 #36
0
 protected override void BuildMappings(MappingBuilder m)
 {
     base.BuildMappings(m);
     m.FromAssemblyOf <AnimalMap>();
 }
コード例 #37
0
 public MappingFromAttributes(MappingBuilder mappingBuilder)
     : base(mappingBuilder)
 {
 }