public void TestMap() { var person = new PersonFrom() { Name = "Person", Parent = new PersonFrom { Name = "Person Parent", Parent = new PersonFrom { Name = "Person Parent Parent" } } }; var to = this.Mapper.From(person).To <PersonTo>(); Assert.Equal("Person", to.Name); Assert.Equal("Person Parent", to.Parent.Name); Assert.Equal("Person Parent Parent", to.Parent.Parent.Name); to = this.Mapper.From(person).To <PersonTo>(opts => { opts.Map(x => x.Name, x => x.Parent.Name); }); Assert.Null(to.Name); Assert.Equal("Person", to.Parent.Name); Assert.Equal("Person Parent Parent", to.Parent.Parent.Name); to = this.Mapper.From(person).To <PersonTo>(opts => { opts.Map(x => x.Name, x => x.Parent.Name, x => x.Parent.Parent.Name); }); Assert.Null(to.Name); Assert.Equal("Person", to.Parent.Name); Assert.Equal("Person", to.Parent.Parent.Name); }
/// <summary> /// Стандартный метод (XAF его использует, чтобы показать объект в интерфейсе) /// </summary> /// <returns></returns> public override string ToString() { string Res = ""; Res = PersonFrom.ToString() + " - " + PersonTo.ToString(); return(Res); }
public void TestBase() { var from = new PersonFrom() { Name = "Person", Parent = new PersonFrom { Name = "Parent" }, Children = new List <PersonFrom> { new PersonFrom { Name = "Child 1" }, new PersonFrom { Name = "Child 2" } }, }; var to = this.Mapper.From(from).To <PersonTo>(); Assert.Equal("Person", to.Name); Assert.Equal("Parent", to.Parent.Name); Assert.Equal("Child 1", to.Children[0].Name); Assert.Equal("Child 2", to.Children[1].Name); }
public void TestObjectMap() { var from = new PersonFrom() { Name = "Person", Parent = new PersonFrom { Name = "Parent" }, Children = new List <PersonFrom> { new PersonFrom { Name = "Child 1" }, new PersonFrom { Name = "Child 2" } }, }; var to = this.Mapper.From(from, opts => opts.Map(x => x.Name, "Parent.Name")).To <PersonTo>(); Assert.Null(to.Name); Assert.Equal("Person", to.Parent.Name); Assert.Equal("Child 1", to.Children[0].Name); Assert.Equal("Child 2", to.Children[1].Name); to = this.Mapper.From(from).To <PersonTo>(opts => opts.Map(x => x.Name, x => x.Parent.Name)); Assert.Null(to.Name); Assert.Equal("Person", to.Parent.Name); Assert.Equal("Child 1", to.Children[0].Name); Assert.Equal("Child 2", to.Children[1].Name); }
public void TestIgnore() { var person = new PersonFrom() { Name = "Person", Parent = new PersonFrom { Name = "Person Parent", Parent = new PersonFrom { Name = "Person Parent Parent" } } }; { var mapper = new MapperBuilder() .Ignore <PersonFrom>(x => x.Name) .Build(); var to = mapper.From(person).To <PersonTo>(); Assert.Null(to.Name); Assert.Equal("Person Parent", to.Parent.Name); Assert.Equal("Person Parent Parent", to.Parent.Parent.Name); } { var mapper = new MapperBuilder() .Ignore <PersonFrom>(x => x.Parent.Name) .Build(); var to = mapper.From(person).To <PersonTo>(); Assert.Equal("Person", to.Name); Assert.Null(to.Parent.Name); Assert.Equal("Person Parent Parent", to.Parent.Parent.Name); } { var mapper = new MapperBuilder() .Ignore <PersonFrom>(x => x.Parent.Parent.Name) .Build(); var to = mapper.From(person).To <PersonTo>(); Assert.Equal("Person", to.Name); Assert.Equal("Person Parent", to.Parent.Name); Assert.Null(to.Parent.Parent.Name); } { var mapper = new MapperBuilder() .IgnoreFrom <PersonFrom>(x => x.Name) .Build(); var to = mapper.From(person).To <PersonTo>(); Assert.Null(to.Name); Assert.Equal("Person Parent", to.Parent.Name); Assert.Equal("Person Parent Parent", to.Parent.Parent.Name); } { var mapper = new MapperBuilder() .IgnoreFrom <PersonFrom>(x => x.Parent.Name) .Build(); var to = mapper.From(person).To <PersonTo>(); Assert.Equal("Person", to.Name); Assert.Null(to.Parent.Name); Assert.Equal("Person Parent Parent", to.Parent.Parent.Name); } { var mapper = new MapperBuilder() .IgnoreFrom <PersonFrom>(x => x.Parent.Parent.Name) .Build(); var to = mapper.From(person).To <PersonTo>(); Assert.Equal("Person", to.Name); Assert.Equal("Person Parent", to.Parent.Name); Assert.Null(to.Parent.Parent.Name); } { var mapper = new MapperBuilder() .IgnoreTo <PersonTo>(x => x.Name) .Build(); var to = mapper.From(person).To <PersonTo>(); Assert.Null(to.Name); Assert.Equal("Person Parent", to.Parent.Name); Assert.Equal("Person Parent Parent", to.Parent.Parent.Name); } { var mapper = new MapperBuilder() .IgnoreTo <PersonTo>(x => x.Parent.Name) .Build(); var to = mapper.From(person).To <PersonTo>(); Assert.Equal("Person", to.Name); Assert.Null(to.Parent.Name); Assert.Equal("Person Parent Parent", to.Parent.Parent.Name); } { var mapper = new MapperBuilder() .IgnoreTo <PersonTo>(x => x.Parent.Parent.Name) .Build(); var to = mapper.From(person).To <PersonTo>(); Assert.Equal("Person", to.Name); Assert.Equal("Person Parent", to.Parent.Name); Assert.Null(to.Parent.Parent.Name); } }