public void TestMethodTimeILFasterthanReflex() { Student s = new Student(); s.NrF = 27721; s.NameF = "ze Manel"; IMapper <Student, Person> m = AutoMapper.Build <Student, Person>().Bind(Mapping.FieldsReflex); var watch = System.Diagnostics.Stopwatch.StartNew(); for (int i = 0; i < 50000; i++) { Person p = (Person)m.Map(s); } watch.Stop(); var elapsedMs = watch.ElapsedMilliseconds; m = AutoMapper.Build <Student, Person>().Bind(Mapping.FieldsIl); watch = System.Diagnostics.Stopwatch.StartNew(); for (int i = 0; i < 50000; i++) { Person p = (Person)m.Map(s); } watch.Stop(); var elapsedMs1 = watch.ElapsedMilliseconds; Assert.IsTrue(elapsedMs1 < elapsedMs); }
public void TestMapWithCustomAttributes() { AutoMapper.mappers.Clear(); IMapper m = AutoMapper .Build(typeof(Student), typeof(Person)) .Bind(new Mapping(typeof(ToMapAttribute))) .Match("Nr", "Id"); Student s = new Student { Nr = 27721, Name = "Ze Manel", Height = 170, Org = new School { Name = "FCT", MembersIds = new int[] { 1, 2, 3 }, Location = "Lisboa, Portugal" } }; Person p = (Person)m.Map(s); Assert.AreEqual(s.Name, p.Name); Assert.AreEqual(s.Nr, p.Id); Assert.AreNotEqual(s.Height, p.Height); Assert.IsNull(p.Org); }
public void testMappingArray() { Mapper m = AutoMapper .Build(typeof(Student), typeof(Person)) .Bind(Mapping.Fields) .Match("Nr", "Id") .Match("Courses", "Subjects"); Student[] stds = { new Student { Nr = 42929, Name = "Gonçalo Barros" }, new Student{ Nr = 42144, Name = "Nuno Cardoso" }, new Student{ Nr = 42140, Name = "Marco Agostinho" } }; stds[0].Courses = new Course [] { new Course("AVE"), new Course("LS") }; stds[1].Courses = new Course[] { new Course("LS") }; stds[2].Courses = new Course[] { new Course("POO") }; object[] ps = m.Map(stds); Person[] pso = new Person[ps.Length]; for (int i = 0; i < stds.Length; i++) { pso[i] = (Person)ps[i]; Assert.AreEqual(stds[i].Nr, pso[i].Id); } }
public void CacheTest() { IMapper mapper1 = AutoMapper.Build(typeof(Student), typeof(Person)); IMapper mapper2 = AutoMapper.Build(typeof(Student), typeof(Person)); Assert.AreEqual(mapper1.GetHashCode(), mapper2.GetHashCode()); }
public void ValueTypeTest() { IMapper m = AutoMapper.Build(typeof(int), typeof(int)); int x = 1; int i = (int)m.Map(x); Assert.AreEqual(x, i); }
public void TestObjectNotMapped() { IMapper m = AutoMapper.Build(typeof(Student), typeof(Person)).Match("Nr", "Id"); Teacher teacher = new Teacher(123, "t"); Person p = (Person)m.Map(teacher); Assert.IsNull(p); }
public void TestPerformance() { Action reflectionAction = () => AutoMapper.Build(typeof(Student), typeof(Person)); Action emitAction = () => AutoMapperEmit.Build(typeof(Student), typeof(Person)); long reflection = Benchmark.Bench(reflectionAction, "Reflection - Person"); long emit = Benchmark.Bench(emitAction, "Emit - Person"); Assert.IsTrue(reflection < emit); }
public void TestPrivateFields() { IMapper m = AutoMapper.Build(typeof(Student), typeof(Person)); Student s = new Student { Nr = 27721, Name = "Ze Manel", field = 200 }; Person p = (Person)m.Map(s); Assert.AreEqual(s.getPrivateField(), p.getPrivateField()); }
public void TestPublicProperties() { IMapper m = AutoMapper.Build(typeof(Student), typeof(Person)); Student s = new Student { Nr = 27721, Name = "Ze Manel", field = 200 }; Person p = (Person)m.Map(s); Assert.AreEqual(s.Name, p.Name); }
public void MapTest() { IMapper m = AutoMapper.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); }
public void MapParametersTest() { IMapper m = AutoMapper.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); }
public void TestMatch() { IMapper m = AutoMapper.Build(typeof(Student), typeof(Person)).Match("Nr", "Id"); Student s = new Student { Nr = 27721, Name = "Ze Manel", field = 200 }; Person p = (Person)m.Map(s); Assert.AreEqual(s.Nr, p.Id); }
public void testAttributesBuildWithBind() { IMapper m = AutoMapper.Build(typeof(Student), typeof(Person)).Bind(Mapping.Fields); Student s = new Student { Nr = 27721, Name = "Ze Manel" }; Person p = (Person)m.Map(s); Assert.AreEqual(s.Name, p.Name); }
public void testMappingCustomAttr() { IMapper m = AutoMapper.Build(typeof(Student), typeof(Person)) .Bind(new MappingCustomAttributes(typeof(ToMapAttribute))); Student s = new Student { Nr = 27721, Name = "Ze Manel" }; Person p = (Person)m.Map(s); Assert.AreEqual(s.Name, p.Name); }
public void MapByBindTest() { IMapper m = AutoMapper.Build(typeof(Student), typeof(Person)) .Bind(Mapping.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); }
public void MapCustomAttributeTest() { IMapper m = AutoMapper.Build(typeof(Student), typeof(Person)) .Bind(Mapping.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); }
public void TestMethodStudentToPersonFieldsReflex() { Student s = new Student(); s.NrF = 27721; s.NameF = "ze Manel"; IMapper <Student, Person> m = AutoMapper.Build <Student, Person>().Bind(Mapping.FieldsReflex); Person p = (Person)m.Map(s); Assert.IsTrue(s.NameF.Equals(p.NameF)); }
public void ReferenceField() { IMapper m = AutoMapper.Build(typeof(Student), typeof(Person)).Match("Nr", "Id"); Student s = new Student { Nr = 27721, Name = "Ze Manel", field = 200, teacher = new Teacher(123, "t") }; Person p = (Person)m.Map(s); Object.ReferenceEquals(s.teacher, p.teacher); Assert.IsFalse(Object.ReferenceEquals(s.teacher, p.teacher)); Assert.AreEqual(s.teacher.name, p.teacher.name); }
public void TestMethodFor() { Student s = new Student(); s.NrF = 27721; s.NameF = "ze Manel"; IMapper <Student, Person> m = AutoMapper.Build <Student, Person>().Bind(Mapping.FieldsIl).For("IdF", () => 11111); Person p = (Person)m.Map(s); Assert.IsTrue(s.NameF.Equals(p.NameF) && p.IdF == 11111); }
public void TestMethodMapperAutoMapperILUsingProprieties() { Student s = new Student(); s.NrP = 27721; s.NameP = "ze Manel"; IMapper <Student, Person> m = AutoMapper.Build <Student, Person>().Bind(Mapping.PropertiesIl); Person p = (Person)m.Map(s); Assert.IsTrue(s.NameP.Equals(p.NameP)); }
public void TestStructProperties() { AutoMapper.mappers.Clear(); IMapper m = AutoMapper .Build(typeof(Nurse), typeof(Student)); Nurse nrs = new Nurse { Name = "D. Cristina", Nr = 1 }; Student s = (Student)m.Map(nrs); Assert.AreEqual(nrs.Name, s.Name); Assert.AreEqual(nrs.Nr, s.Nr); }
static void Main() { Mapper <Student, Person> mapper = AutoMapper .Build <Student, Person>() // .IgnoreMember("Nr") // .IgnoreMember("Name"); .To("Org", "IBM"); Student s = new Student { Nr = 27721, Name = "Ze Manel", School = "Isel" }; Person p = mapper.Map(s); Console.WriteLine(p); }
public void TestMapObject() { IMapper m = AutoMapper.Build(typeof(Student), typeof(Person)).Match("Nr", "Id"); Student s = new Student { Nr = 27721, Name = "Ze Manel", field = 200 }; Person p = (Person)m.Map(s); Assert.AreEqual(s.Nr, p.Id); Assert.AreEqual(s.Name, p.Name); Assert.AreEqual(s.field, p.field); Assert.AreEqual(s.getPrivateProperty(), p.getPrivateProperty()); Assert.AreEqual(s.getPrivateField(), p.getPrivateField()); }
public void testAttributesBuildWithMatchAndEmit() { IMapper m = AutoMapper.Build(typeof(Student), typeof(Person)) .Bind(new MappingEmit()) .Match("Nr", "Id"); Student s = new Student { Nr = 27721, Name = "Ze Manel" }; Person p = (Person)m.Map(s); Assert.AreEqual(s.Nr, p.Id); Assert.AreEqual(s.Name, p.Name); }
public void TestMapField_Default() { AutoMapper.mappers.Clear(); IMapper m = AutoMapper .Build(typeof(Doctor), typeof(Patient)) .Bind(Mapping.Fields); Doctor d = new Doctor { doctorNr = 213, name = "Zé Manel", localization = "Chelas" }; Patient pt = (Patient)m.Map(d); Assert.AreEqual(pt.name, d.name); Assert.AreEqual(pt.localization, d.localization); }
public void TestMatchComplexFields() { AutoMapper.mappers.Clear(); IMapper m = AutoMapper .Build(typeof(Doctor), typeof(Person)) .Bind(Mapping.Fields) .Match("doctorNr", "Id"); Doctor d = new Doctor { doctorNr = 213, name = "Zé Manel" }; Person p = (Person)m.Map(d); Assert.AreEqual(p.Id, d.doctorNr); }
public void MapByMatchTest() { int[] array = { 27999, 27898, 27162 }; IMapper m = AutoMapper.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); }
public void TestCache() { AutoMapper.mappers.Clear(); IMapper msp1 = AutoMapper .Build(typeof(Student), typeof(Person)); IMapper mst1 = AutoMapper .Build(typeof(Student), typeof(Teacher)); IMapper msp2 = AutoMapper .Build(typeof(Student), typeof(Person)); IMapper mst2 = AutoMapper .Build(typeof(Student), typeof(Teacher)); Assert.AreSame(msp1, msp2); Assert.AreSame(mst1, mst2); }
public void MapArrayTest() { IMapper m = AutoMapper.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); } }
public void TestMapPropertiesToConstructor_Default() { AutoMapper.mappers.Clear(); IMapper m = AutoMapper .Build(typeof(Student), typeof(Teacher)); Student s = new Student { Nr = 27721, Name = "Ze Manel", Height = 170 }; Teacher t = (Teacher)m.Map(s); Assert.AreEqual(s.Name, t.Name); Assert.AreEqual(s.Nr, t.Id); }