public void Test_Type_Creation_from_Concrete_Classes() { var class1 = new TestClass1 { Name = "Foo", Description = "Test Class Instance", Number = 10, SubClass = new TestSubClass1 { Internal = "Inside" } }; var class2 = new TestClass2 { FullName = "Test Class 2", FullAddress = "123 Main St.", Total = 28 }; var result = Merger.Ignore(() => class1.Name) .Ignore(() => class2.Total) .Merge(class1, class2); Assert.AreEqual(5, result.GetType().GetProperties().Length); Assert.AreEqual(typeof(TestSubClass1), result.GetType().GetProperty("SubClass").PropertyType); Assert.AreEqual(class1.SubClass.Internal, result.GetType().GetProperty("SubClass").GetValue(result).GetType().GetProperty("Internal").GetValue(result.GetType().GetProperty("SubClass").GetValue(result))); }
public void Merge_Types_with_Ignore_Policy() { var obj1 = new { Property1 = "values1", Property2 = "values1" }; var obj2 = new { Property1 = "values2", Property4 = "values4" }; var result = Merger.Ignore(() => obj1.Property1) .Ignore(() => obj2.Property4) .Merge(obj1, obj2); Assert.AreEqual(2, result.GetType().GetProperties().Length); Assert.AreEqual("values2", result.GetType().GetProperty("Property1").GetValue(result)); Assert.IsNotNull(result.GetType().GetProperty("Property2")); }
public void Test_Multiple_Type_Creation_from_Same_Anonymous_Types_Sources() { var obj1 = new { Property1 = "value1", Property2 = "2" }; var obj2 = new { Property1 = "value2", Property3 = "3" }; var result1 = Merger.Merge(obj1, obj2); Assert.AreEqual(3, result1.GetType().GetProperties().Length); Assert.AreEqual("value1", result1.GetType().GetProperty("Property1").GetValue(result1)); var result2 = Merger.Ignore(() => obj1.Property2) .Merge(obj1, obj2); Assert.AreEqual(2, result2.GetType().GetProperties().Length); Assert.AreEqual("3", result2.GetType().GetProperty("Property3").GetValue(result2)); }