public void Map_BetweenSameTypesWithNull_MapsAllValues() { var p1 = new Person() { Name = null, DOB = DateTime.Now, Address = null }; var p2 = new Person(); Reflect.OnMappings.Map(p1, p2); Assert.Null(p2.Name); Assert.Null(p2.Address); }
public void Map_BetweenSameTypes_MapsAllValues() { var p1 = new Person() { Name = "Bob", DOB = DateTime.Now, Address = new Address() { Street = "Complex Street", StreetNr = 1 } }; var p2 = new Person(); Reflect.OnMappings.Map(p1, p2); Assert.Equal(p1.Name, p2.Name); Assert.Equal(p1.DOB, p2.DOB); Assert.Equal(p1.Address.Street, p2.Address.Street); Assert.Equal(p1.Address.StreetNr, p2.Address.StreetNr); }
public void Map_FromDictionariesToComplexType_MapsValues() { var dictionary = new Dictionary<string, object>() { { "Name", "Bob" }, { "DOB", DateTime.UtcNow }, { "Address", new Dictionary<string, object>() { { "StreetNr", 1 }, { "Street", "Main Rd" } } }, }; var instance = new Person(); Reflect.OnMappings.Map(dictionary, instance); Assert.Equal(instance.Name, "Bob"); Assert.Equal(instance.Address.Street, "Main Rd"); }
public void TurnObjectIntoDictionary_OnAnyComplexType_SubDictionaryKeyCountEqualsTwo() { var complexPerson = new Person() { Name = "Bob", DOB = DateTime.Now, Address = new Address() { Street = "Complex Street", StreetNr = 1 } }; var dictionary = Reflect.OnMappings.TurnObjectIntoDictionary(complexPerson); Assert.Equal(((Dictionary<string,object>)dictionary["Address"]).Keys.Count, 2); }
public void TurnObjectIntoDictionary_OnAnyComplexType_MapsToDictionary() { var complexPerson = new Person() { Name = "Bob", DOB = DateTime.Now, Address = new Address() { Street ="Complex Street", StreetNr = 1 } }; var dictionary = Reflect.OnMappings.TurnObjectIntoDictionary(complexPerson); Assert.IsType<Dictionary<string,object>>(dictionary); }