コード例 #1
0
        public void RegisterMapperTest1()
        {
            TransformerObserver observer = new TransformerObserver();
            IList<IPropertyMapper<Student, Person>> propMappers = new List<IPropertyMapper<Student, Person>>
                {
                    new PropertyMapper<Student, Person>( (student, person) => person.Name = student.Name, "Name", "Name")
                    ,new PropertyMapper<Student, Person>( (student, person) => person.AnnoNascita = student.AnnoNascita )
                    ,new PropertyMapper<Student, Person>( (student, person) => person.Parent = student.Father )
                };
            SourceMapper<Student, Person> mapper1 = new SourceMapper<Student, Person>(propMappers, null, null);

            observer.RegisterMapper(mapper1);
            Student st = new Student { Name = "mario", Surname = "monti", AnnoNascita = 19 };
            StudentDetails st2 = new StudentDetails { Name = "mario", Surname = "monti", AnnoNascita = 19, CF = "CF"};

            var res = observer.TryToMap<Student, Person>(st);
            var res2 = observer.TryToMap<Student, Person>(st2);
            Assert.IsNotNull(res);
            Assert.IsNotNull(res2);
        }
コード例 #2
0
        public void Test()
        {
            ISourceMapper<Student, Person> mapper1 = FactoryMapper.DynamicResolutionMapper<Student, Person>();
            ISourceMapper mapper2 = FactoryMapper.DynamicResolutionMapper(typeof(PersonaGiuridica), typeof(PersonDetails));
            ISourceMapper mapper3 = FactoryMapper.DynamicResolutionMapper(typeof(IPersonHeader), typeof(PersonDetails));

            IList<IPropertyMapper<Student, Person>> propMappers = new List<IPropertyMapper<Student, Person>>
                {
                    new PropertyMapper<Student, Person>( (student, person) => person.Name = student.Name, "Name", "Name")
                    ,new PropertyMapper<Student, Person>( (student, person) => person.AnnoNascita = student.AnnoNascita )
                    ,new PropertyMapper<Student, Person>( (student, person) => person.Parent = student.Father )
                };

            SourceMapper<Student, Person> mapper4 = new SourceMapper<Student, Person>(propMappers, null, null);
            StudentDetails example = new StudentDetails();

            ServiceTransformer<ISourceMapper<Student, Person>> srv1 = new ServiceTransformer<ISourceMapper<Student, Person>>("default", mapper4);

            var res1 = srv1.Match<ISourceMapper<Student, Person>>("default");
            var res2 = srv1.Match<SourceMapper<Student, Person>>("default");

            var res3 = srv1.Match<ISourceMapper<Student, Person>>("ss");
            var res4 = srv1.Match<SourceMapper<Student, Person>>("ss");
            var res5 = srv1.Match("default", example.GetType(), typeof(Person));

            Assert.IsTrue(res1);
            Assert.IsFalse(res2);
            Assert.IsFalse(res3);
            Assert.IsFalse(res4);
            Assert.IsTrue(res5);
        }