Ejemplo n.º 1
0
        public void TestDefaultMergerIgnoringException()
        {
            StringBuilder buffer = new StringBuilder();

            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)null).Father)
            };

            var merger = new SourceMerger <Student, Person>(propMappers,
                                                            null,
                                                            r => buffer.AppendLine(string.Format("ToString after mapping: {0}", r.ToString()))
                                                            );

            Student st = new Student {
                Name = "mario", Surname = "monti", AnnoNascita = 1
            };
            Person pr = new Person();

            merger.IgnoreExceptionOnMapping = true;
            merger.Merge(st, pr);

            merger.IgnoreExceptionOnMapping = false;
            merger.Merge(st, pr);
        }
Ejemplo n.º 2
0
        public void TestCustomMerger()
        {
            IList <IPropertyMapper <Student, Person> > propMappers = new List <IPropertyMapper <Student, Person> >
            {
                new PropertyMapper <Student, Person>((student, person) => person.Name          = student.Name.ToUpper(), "Name", "Name")
                , new PropertyMapper <Student, Person>((student, person) => person.AnnoNascita = student.AnnoNascita)
            };

            ISourceMerger <Student, Person> mapper = new SourceMerger <Student, Person>(propMappers, null, null);

            Student st = new Student {
                Name = "mario", Surname = "monti", AnnoNascita = 19
            };
            Person pr = mapper.Merge(st, new Person());

            Assert.AreEqual(st.Name.ToUpper(), pr.Name, "Property [Name] was not set.");
            Assert.AreNotEqual(st.Surname.ToUpper(), pr.Surname);
            Assert.AreEqual(st.AnnoNascita, pr.AnnoNascita);
        }
Ejemplo n.º 3
0
        public void TestCustomMerger()
        {
            IList<IPropertyMapper<Student, Person>> propMappers = new List<IPropertyMapper<Student, Person>>
                {
                    new PropertyMapper<Student, Person>( (student, person) => person.Name = student.Name.ToUpper(), "Name", "Name")
                    , new PropertyMapper<Student, Person>( (student, person) => person.AnnoNascita = student.AnnoNascita )
                };

            ISourceMerger<Student, Person> mapper = new SourceMerger<Student, Person>(propMappers, null, null);

            Student st = new Student { Name = "mario", Surname = "monti", AnnoNascita = 19 };
            Person pr = mapper.Merge(st, new Person());

            Assert.AreEqual(st.Name.ToUpper(), pr.Name, "Property [Name] was not set.");
            Assert.AreNotEqual(st.Surname.ToUpper(), pr.Surname);
            Assert.AreEqual(st.AnnoNascita, pr.AnnoNascita);
        }
Ejemplo n.º 4
0
        public void TestDefaultMergerIgnoringException()
        {
            StringBuilder buffer = new StringBuilder();

            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)null).Father )
                };

            var merger = new SourceMerger<Student, Person>(propMappers,
                    null,
                    r => buffer.AppendLine(string.Format("ToString after mapping: {0}", r.ToString()))
                );

            Student st = new Student { Name = "mario", Surname = "monti", AnnoNascita = 1 };
            Person pr = new Person();

            merger.IgnoreExceptionOnMapping = true;
            merger.Merge(st, pr);

            merger.IgnoreExceptionOnMapping = false;
            merger.Merge(st, pr);
        }