Exemple #1
0
        public void ValueTypeTest()
        {
            IMapperEmit m = AutoMapperEmit.Build(typeof(int), typeof(int));
            int         x = 1;
            int         i = (int)m.Map(x);

            Assert.AreEqual(x, i);
        }
Exemple #2
0
        public void MapParametersTest()
        {
            IMapperEmit m = AutoMapperEmit.Build(typeof(Student), typeof(Course));
            Student     s = new Student {
                ImAField = "ImAField", Nickname = "Zezito", Nr = 27721, Name = "Ze Manel", Address = "Rua de Cima"
            };
            Course c = (Course)m.Map(s);

            Assert.AreEqual(s.Address, c.Address);
        }
Exemple #3
0
        public void MapTest()
        {
            IMapperEmit m = AutoMapperEmit.Build(typeof(Student), typeof(Person));
            Student     s = new Student {
                Nr = 27721, Name = "Ze Manel"
            };
            Person p = (Person)m.Map(s);

            Assert.AreEqual(s.Name, p.Name);
        }
Exemple #4
0
        public void MapByBindTest()
        {
            IMapperEmit m = AutoMapperEmit.Build(typeof(Student), typeof(Person))
                            .Bind(MappingEmit.Fields);
            Student s = new Student {
                ImAField = "ImAField", Nickname = "Zezito", Nr = 27721, Name = "Ze Manel"
            };
            Person p = (Person)m.Map(s);

            Assert.AreEqual(s.ImAField, p.ImAField);
        }
Exemple #5
0
        public void MapCustomAttributeTest()
        {
            IMapperEmit m = AutoMapperEmit.Build(typeof(Student), typeof(Person))
                            .Bind(MappingEmit.CustomAttributes);
            Student s = new Student {
                ImAField = "ImAField", Nickname = "Zezito", Nr = 27721, Name = "Ze Manel"
            };
            Person p = (Person)m.Map(s);

            Assert.AreEqual(s.Nickname, p.Nickname);
        }
Exemple #6
0
        public void MapArrayTest()
        {
            IMapperEmit m = AutoMapperEmit.Build(typeof(Student), typeof(Person));

            Student[] s = { new Student {
                                ImAField = "ImAField", Nickname = "Zezito", Nr = 27721, Name = "Ze Manel"
                            },
                            new Student {
                                ImAField = "ImAField", Nickname = "Xico", Nr = 27722, Name = "Francisco"
                            } };
            Person[]  p = (Person[])m.Map(s);
            for (int i = 0; i < p.Length; ++i)
            {
                Assert.AreEqual(s[i].Name, p[i].Name);
            }
        }
Exemple #7
0
        public void MapByMatchTest()
        {
            int[]       array = { 27999, 27898, 27162 };
            IMapperEmit m     = AutoMapperEmit.Build(typeof(Student), typeof(Person))
                                .Match("Nr", "Id")
                                .Match("Org", "Org");
            Student s = new Student
            {
                ImAField = "ImAField",
                Nickname = "Zezito",
                Nr       = 27721,
                Name     = "Ze Manel",
                Org      = new School("Lisbon", array, "ISEL")
            };
            Person p = (Person)m.Map(s);

            Assert.AreEqual(s.Nr, p.Id);
            Assert.AreEqual(s.Org.Name, p.Org.Name);
        }