public void RetreiveMapperFromObserver() { TransformerObserver observer = new TransformerObserver(); var builder = observer.MakeTransformerBuilder <IPersonHeader, PersonDetails>(BuilderType.DefaultMappers); var mapper1 = builder.BuildMapper(); var mapper2 = builder.BuildMapper("keymapper"); builder.BuildMerger(); builder.BuildMerger("merger"); Assert.IsNotNull(builder); Assert.AreEqual(mapper1, mapper2); Assert.AreNotSame(mapper1, mapper2); //IPersonHeader ps = new Person { Name = "name", Surname = "surname", AnnoNascita = 1980, Parent = null }; Assert.NotNull(observer.RetrieveMapper <ISourceMapper <IPersonHeader, PersonDetails> >()); Assert.Null(observer.RetrieveMapper <ISourceMapper <IPersonHeader, PersonDetails> >("mykey")); Assert.NotNull(observer.RetrieveMapper <ISourceMapper <IPersonHeader, PersonDetails> >("keymapper")); Assert.Null(observer.RetrieveMapper <ISourceMapper <Person, PersonDetails> >()); Assert.NotNull(observer.RetrieveMerger <ISourceMerger <IPersonHeader, PersonDetails> >()); Assert.NotNull(observer.RetrieveMerger <ISourceMerger <IPersonHeader, PersonDetails> >("merger")); Assert.Null(observer.RetrieveMerger <ISourceMerger <IPersonHeader, PersonDetails> >("merger1")); }
public void MakeTransformerBuilderTest2() { TransformerObserver observer = new TransformerObserver(); var mapper = observer.MakeTransformerBuilder <IPersonHeader, PersonDetails>(BuilderType.DefaultMappers); mapper.BuildMapper(); Assert.IsNotNull(mapper); IPersonHeader ps = new Person { Name = "name", Surname = "surname", AnnoNascita = 1980, Parent = null }; var resDto = observer.TryToMap <IPersonHeader, PersonDetails>(ps); Assert.IsNotNull(resDto); var resDto1 = observer.TryToMap(ps, typeof(PersonDetails)); Assert.IsNotNull(resDto1); Assert.IsTrue(resDto1 is PersonDetails); var resDto2 = observer.TryToMap <IPersonHeader, PersonDetails>(ps, "mykey"); Assert.IsNull(resDto2); var resDto3 = observer.TryToMap(ps, typeof(PersonDetails), "mykey"); Assert.IsNull(resDto3); }
public void MakeTransformerBuilderTest1() { TransformerObserver observer = new TransformerObserver(); var builder = observer.MakeTransformerBuilder <User, UserDto>(BuilderType.DefaultMappers); //builder.Include( // resolver => new PropertyMapper<User, UserDto>((user, dto) => dto.Parent = resolver.TryToMap<User, UserDto>(user.Parent))); builder.Include( resolver => new PropertyMapper <User, UserDto>((user, dto) => dto.Parent = (UserDto)resolver.TryToMap(user.Parent, typeof(UserDto)))); builder.BuildMapper(); User user1 = new User { Name = "name1", Surname = "surname1", Parent = new User { Name = "parteName1", Surname = "parentSurname1", Parent = new User { Name = "parentParentName1", Surname = "parentParentSurname1", Parent = new User() } } }; var resDto = observer.TryToMap <User, UserDto>(user1); Assert.IsNotNull(resDto); Assert.IsNotNull(resDto.Parent); var resDto1 = observer.TryToMap(user1, typeof(UserDto)); Assert.IsNotNull(resDto1); Assert.IsTrue(resDto1 is UserDto); Assert.IsNotNull(resDto1.GetType().GetProperty("Parent").GetValue(resDto1, null)); var resDto2 = observer.TryToMap <User, UserDto>(user1, "mykey"); Assert.IsNull(resDto2); var resDto3 = observer.TryToMap(user1, typeof(UserDto), "mykey"); Assert.IsNull(resDto3); }
public void MakeTransformerBuilderTest3() { TransformerObserver observer = new TransformerObserver(); var mapper = observer.MakeTransformerBuilder <Person, Student>(BuilderType.DynamicResolver); /* * here It's possible to add / delete property mappers. */ // before using the mapper object, It's needed to build it in order to associate into TransformerObserver mapper.BuildMapper(); Assert.IsNotNull(mapper); Person ps = new Person { Name = "name", Surname = "surname", AnnoNascita = 1980, Parent = new Person { Name = "parent_name", Surname = "parent_surname" } }; var resDto = observer.TryToMap <Person, Student>(ps); Assert.IsNotNull(resDto); Assert.IsNull(resDto.Father); var resDto1 = observer.TryToMap(ps, typeof(Student)); Assert.IsNotNull(resDto1); Assert.IsNull(resDto1.GetType().GetProperty("Father").GetValue(resDto1, null)); Assert.IsTrue(resDto1 is Student); var resDto2 = observer.TryToMap <Person, Student>(ps, "mykey"); Assert.IsNull(resDto2); var resDto3 = observer.TryToMap(ps, typeof(Student), "mykey"); Assert.IsNull(resDto3); }
public void MakeTransformerBuilderTest4() { TransformerObserver observer = new TransformerObserver(); var mapper = observer.MakeTransformerBuilder <Person, Student>(BuilderType.DynamicResolver); mapper.Include(new PropertyMapper <Person, Student>((person, student) => student.Father = person.Parent, "Father", "Parent")); mapper.BuildMapper(); Assert.IsNotNull(mapper); Person ps = new Person { Name = "name", Surname = "surname", AnnoNascita = 1980, Parent = new Person { Name = "parent_name", Surname = "parent_surname" } }; var resDto = observer.TryToMap <Person, Student>(ps); Assert.IsNotNull(resDto); Assert.IsNotNull(resDto.Father); var resDto1 = observer.TryToMap(ps, typeof(Student)); Assert.IsNotNull(resDto1); Assert.IsNotNull(resDto1.GetType().GetProperty("Father").GetValue(resDto1, null)); Assert.IsTrue(resDto1 is Student); var resDto2 = observer.TryToMap <Person, Student>(ps, "mykey"); Assert.IsNull(resDto2); var resDto3 = observer.TryToMap(ps, typeof(Student), "mykey"); var resDto4 = observer.TryToMap(ps, null, "mykey"); Assert.IsNull(resDto3); Assert.IsNull(resDto4); }
public void RetreiveMapperFromObserver() { TransformerObserver observer = new TransformerObserver(); var builder = observer.MakeTransformerBuilder<IPersonHeader, PersonDetails>(BuilderType.DefaultMappers); var mapper1 = builder.BuildMapper(); var mapper2 = builder.BuildMapper("keymapper"); builder.BuildMerger(); builder.BuildMerger("merger"); Assert.IsNotNull(builder); Assert.AreEqual(mapper1, mapper2); Assert.AreNotSame(mapper1, mapper2); //IPersonHeader ps = new Person { Name = "name", Surname = "surname", AnnoNascita = 1980, Parent = null }; Assert.NotNull(observer.RetrieveMapper<ISourceMapper<IPersonHeader, PersonDetails>>()); Assert.Null(observer.RetrieveMapper<ISourceMapper<IPersonHeader, PersonDetails>>("mykey")); Assert.NotNull(observer.RetrieveMapper<ISourceMapper<IPersonHeader, PersonDetails>>("keymapper")); Assert.Null(observer.RetrieveMapper<ISourceMapper<Person, PersonDetails>>()); Assert.NotNull(observer.RetrieveMerger<ISourceMerger<IPersonHeader, PersonDetails>>()); Assert.NotNull(observer.RetrieveMerger<ISourceMerger<IPersonHeader, PersonDetails>>("merger")); Assert.Null(observer.RetrieveMerger<ISourceMerger<IPersonHeader, PersonDetails>>("merger1")); }
public void MakeTransformerBuilderTest4() { TransformerObserver observer = new TransformerObserver(); var mapper = observer.MakeTransformerBuilder<Person, Student>(BuilderType.DynamicResolver); mapper.Include(new PropertyMapper<Person, Student>((person, student) => student.Father = person.Parent, "Father", "Parent")); mapper.BuildMapper(); Assert.IsNotNull(mapper); Person ps = new Person { Name = "name", Surname = "surname", AnnoNascita = 1980, Parent = new Person { Name = "parent_name", Surname = "parent_surname" } }; var resDto = observer.TryToMap<Person, Student>(ps); Assert.IsNotNull(resDto); Assert.IsNotNull(resDto.Father); var resDto1 = observer.TryToMap(ps, typeof(Student)); Assert.IsNotNull(resDto1); Assert.IsNotNull(resDto1.GetType().GetProperty("Father").GetValue(resDto1, null)); Assert.IsTrue(resDto1 is Student); var resDto2 = observer.TryToMap<Person, Student>(ps, "mykey"); Assert.IsNull(resDto2); var resDto3 = observer.TryToMap(ps, typeof(Student), "mykey"); var resDto4 = observer.TryToMap(ps, null, "mykey"); Assert.IsNull(resDto3); Assert.IsNull(resDto4); }
public void MakeTransformerBuilderTest3() { TransformerObserver observer = new TransformerObserver(); var mapper = observer.MakeTransformerBuilder<Person, Student>(BuilderType.DynamicResolver); /* * here It's possible to add / delete property mappers. */ // before using the mapper object, It's needed to build it in order to associate into TransformerObserver mapper.BuildMapper(); Assert.IsNotNull(mapper); Person ps = new Person { Name = "name", Surname = "surname", AnnoNascita = 1980, Parent = new Person { Name = "parent_name", Surname = "parent_surname" } }; var resDto = observer.TryToMap<Person, Student>(ps); Assert.IsNotNull(resDto); Assert.IsNull(resDto.Father); var resDto1 = observer.TryToMap(ps, typeof(Student)); Assert.IsNotNull(resDto1); Assert.IsNull(resDto1.GetType().GetProperty("Father").GetValue(resDto1, null)); Assert.IsTrue(resDto1 is Student); var resDto2 = observer.TryToMap<Person, Student>(ps, "mykey"); Assert.IsNull(resDto2); var resDto3 = observer.TryToMap(ps, typeof(Student), "mykey"); Assert.IsNull(resDto3); }
public void MakeTransformerBuilderTest2() { TransformerObserver observer = new TransformerObserver(); var mapper = observer.MakeTransformerBuilder<IPersonHeader, PersonDetails>(BuilderType.DefaultMappers); mapper.BuildMapper(); Assert.IsNotNull(mapper); IPersonHeader ps = new Person { Name = "name", Surname = "surname", AnnoNascita = 1980, Parent = null }; var resDto = observer.TryToMap<IPersonHeader, PersonDetails>(ps); Assert.IsNotNull(resDto); var resDto1 = observer.TryToMap(ps, typeof(PersonDetails)); Assert.IsNotNull(resDto1); Assert.IsTrue(resDto1 is PersonDetails); var resDto2 = observer.TryToMap<IPersonHeader, PersonDetails>(ps, "mykey"); Assert.IsNull(resDto2); var resDto3 = observer.TryToMap(ps, typeof(PersonDetails), "mykey"); Assert.IsNull(resDto3); }
public void MakeTransformerBuilderTest1() { TransformerObserver observer = new TransformerObserver(); var builder = observer.MakeTransformerBuilder<User, UserDto>(BuilderType.DefaultMappers); //builder.Include( // resolver => new PropertyMapper<User, UserDto>((user, dto) => dto.Parent = resolver.TryToMap<User, UserDto>(user.Parent))); builder.Include( resolver => new PropertyMapper<User, UserDto>((user, dto) => dto.Parent = (UserDto)resolver.TryToMap(user.Parent, typeof(UserDto)))); builder.BuildMapper(); User user1 = new User { Name = "name1", Surname = "surname1", Parent = new User { Name = "parteName1", Surname = "parentSurname1", Parent = new User { Name = "parentParentName1", Surname = "parentParentSurname1", Parent = new User() } } }; var resDto = observer.TryToMap<User, UserDto>(user1); Assert.IsNotNull(resDto); Assert.IsNotNull(resDto.Parent); var resDto1 = observer.TryToMap(user1, typeof (UserDto)); Assert.IsNotNull(resDto1); Assert.IsTrue(resDto1 is UserDto); Assert.IsNotNull(resDto1.GetType().GetProperty("Parent").GetValue(resDto1, null)); var resDto2 = observer.TryToMap<User, UserDto>(user1, "mykey"); Assert.IsNull(resDto2); var resDto3 = observer.TryToMap(user1, typeof(UserDto), "mykey"); Assert.IsNull(resDto3); }