public void CreateObject_MapObjectToObject_Success() { var map = Map.Create("FooProfile", "BarProfile", MapItem.Create("Id", "Id", "Id"), MapItem.Create("Name", "FooName", "BarName")); var fooProfile = Profile.Create("FooProfile", ProfileProperty.Create("Id"), ProfileProperty.Create("FooName")); var barProfile = Profile.Create("BarProfile", ProfileProperty.Create("Id"), ProfileProperty.Create("BarName")); var client = MapperClient.Create(fooProfile, barProfile); var foo = new Foo() { Id = 1, FooName = "Hello World!" }; var bar = new Bar(); bar = client.Map(foo, bar, map); Assert.AreEqual(foo.Id, bar.Id); Assert.AreEqual(foo.FooName, bar.BarName); }
public void CreateObject_MapChildToChild_Success() { var foo = new Foo(); foo.Child.FooChildName = "Hello World!"; var bar = new Bar(); var map = Map.Create("FooProfile", "BarProfile", MapItem.Create("Name", "Child.FooChildName", "Child.BarChildName")); var fooProfile = Profile.Create("FooProfile", ProfileProperty.Create("Child.FooChildName")); var barProfile = Profile.Create("BarProfile", ProfileProperty.Create("Child.BarChildName")); var client = MapperClient.Create(fooProfile, barProfile); bar = client.Map(foo, bar, map); Assert.AreEqual(foo.Child.FooChildName, bar.Child.BarChildName); }
/// <summary> /// Create from a list of mapped strings. /// Syntax: '[]:Id FooName Child.FooChildName' /// </summary> /// <param name="mappingStrings"></param> /// <returns></returns> public static MapperClient Create(params string[] mappingStrings) { var client = new MapperClient(); foreach (var item in mappingStrings) { var splitItem = item.Split(':'); var props = new List <ProfileProperty>(); foreach (var propStr in splitItem[1].Split(' ')) { props.Add(ProfileProperty.Create(propStr)); } var profile = Profile.Create(splitItem[0], props.ToArray()); client.AddProfile(profile); } return(client); }