static void Main(string[] args) { School isel = new School("Isel", "Lisboa"); Student s = new Student { Nr = 27721, Name = "Ze Manel", School = isel }; Student[] a = Enumerable.Repeat(s, 1024).ToArray(); MapperEmit <Student, Person> mapper1 = AutoMapperEmit .Build <Student, Person>() .Match("Nr", "Id") .Match("School", "Org"); MapperEmit <Student, Person> mapper2 = AutoMapperEmit .Load("MapperBenchmark.exe") .Build <Student, Person>() .Match("Nr", "Id") .Match("School", "Org"); NBench.Bench(() => mapper1.Map(a), "Mapping 1 array of Students"); NBench.Bench(() => mapper2.Map(a), "Mapping 2 array of Students"); NBench.Bench(() => mapper1.Map(a), "Mapping 1 array of Students"); NBench.Bench(() => mapper2.Map(a), "Mapping 2 array of Students"); }
public void MapLazyTest() { Student s1 = new Student { Nr = 1234 }; IEnumerable <Student> stds = new List <Student>() { s1, new Student { Nr = 3121 } }; Mapper <Student, Person> m = (Mapper <Student, Person>)AutoMapperEmit.Build <Student, Person>() .Match("Nr", "Id"); using (IEnumerator <Student> st = stds.GetEnumerator()) { using (IEnumerator <Person> prsn = m.MapLazy(stds).GetEnumerator()) { s1.Nr = 36; while (st.MoveNext() && prsn.MoveNext()) { Assert.AreEqual(st.Current.Nr, prsn.Current.Id); } } } }
public void MapSudentsArraysTest() { MapperEmit <Student, Person> mapper = AutoMapperEmit .Build <Student, Person>() .Match("Nr", "Id") .Match("School", "Org"); School isel = new School("Isel", "Lisboa"); Student s = new Student { Nr = 27721, Name = "Ze Manel", School = isel }; // !!!!!!! Cuidado com o desempenho!!! Student[] a = Enumerable.Repeat(s, 1024).ToArray(); // argumento T é inferido a partir de s // <=> Student[] a = Enumerable.Repeat<Student>(s, 1024).ToArray(); /* <=> * Student[] a = new Student[1024]; * for (int i = 0; i < a.Length; i++) * { * a[i] = s; * } */ Person[] ps = mapper.Map(a); for (int i = 0; i < a.Length; i++) { Assert.AreEqual(ps[i].Id, a[i].Nr); Assert.AreEqual(ps[i].Name, a[i].Name); Assert.AreEqual(ps[i].Org.Name, a[i].School.Name); } }
public void CacheTest() { IMapperEmit mapper1 = AutoMapperEmit.Build(typeof(Student), typeof(Person)); IMapperEmit mapper2 = AutoMapperEmit.Build(typeof(Student), typeof(Person)); Assert.AreEqual(mapper1.GetHashCode(), mapper2.GetHashCode()); }
public void ForMethodTest() { Student std = new Student(); Mapper <Student, Person> m = AutoMapperEmit.Build <Student, Person>().For("Name", () => "João"); Person p = (Person)m.Map(std); Assert.AreEqual(std.Name, p.Name); }
public void ValueTypeTest() { IMapperEmit m = AutoMapperEmit.Build(typeof(int), typeof(int)); int x = 1; int i = (int)m.Map(x); Assert.AreEqual(x, i); }
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 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); }
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); }
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); }
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); }
public MappingEntities(PropertyInfo pSrc, PropertyInfo pDest, Dictionary <Type, IMapper> mappers) { this.pSrc = pSrc; this.pDest = pDest; if (mappers != null && mappers.ContainsKey(pSrc.PropertyType)) { this.mapper = mappers[pSrc.PropertyType]; } else { this.mapper = AutoMapperEmit.Build(pSrc.PropertyType, pDest.PropertyType); } }
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); } }
public void MapStudentToSchoolTest() { MapperEmit <Student, Person> mapper = AutoMapperEmit .Build <Student, Person>() .Match("Nr", "Id") .Match("School", "Org"); School isel = new School("Isel", "Lisboa"); Student s = new Student { Nr = 27721, Name = "Ze Manel", School = isel }; Person p = mapper.Map(s); Assert.AreEqual(p.Id, s.Nr); Assert.AreEqual(p.Name, s.Name); Assert.AreEqual(p.Org.Name, s.School.Name); }
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); }
public void GenericBuildTestForMap() { Student[] stds = { new Student { Nr = 27721, Name = "Ze Manel" }, new Student { Nr = 15642, Name = "Maria Papoila" } }; Mapper <Student, Person> m = (Mapper <Student, Person>)AutoMapperEmit.Build <Student, Person>() .Match("Nr", "Id"); Person [] ps = m.Map(stds); for (int i = 0; i < ps.Length; ++i) { Assert.AreEqual(stds[i].Name, ps[i].Name); Assert.AreEqual(stds[i].Nr, ps[i].Id); } }
public MappingEntities(PropertyInfo pSrc, PropertyInfo pDest) { this.pSrc = pSrc; this.pDest = pDest; this.mapper = AutoMapperEmit.Build(pSrc.PropertyType, pDest.PropertyType); }