Ejemplo n.º 1
0
        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 = TypeMerger.Ignore(() => class1.Name)
                         .Ignore(() => class2.Total)
                         .Merge(class1, class2);

            result.GetType().GetProperties().Length.Should().Be(5);

            result.GetType().GetProperty("SubClass").PropertyType.Should().Be(typeof(TestSubClass1));
            result.GetType().GetProperty("SubClass").GetValue(result)
            .GetType().GetProperty("Internal")
            .GetValue(result.GetType().GetProperty("SubClass")
                      .GetValue(result)).Should().Be(class1.SubClass.Internal);
        }
Ejemplo n.º 2
0
        public void Test_Derived_Class_with_Ignored_Base_Class_Property()
        {
            var obj1 = new DerivedClass {
                Name = "foo"
            };

            var obj2 = new { Value = 123 };

            var result = TypeMerger.Ignore(() => obj1.Name).Merge(obj1, obj2);

            result.GetType().GetProperties().Length.Should().Be(1);
        }
Ejemplo n.º 3
0
        public void Merge_Types_with_Ignore_Policy()
        {
            var obj1 = new { Property1 = "value1", Property2 = "value1" };
            var obj2 = new { Property1 = "value2", Property4 = "value4" };

            var result = TypeMerger.Ignore(() => obj1.Property1)
                         .Ignore(() => obj2.Property4)
                         .Merge(obj1, obj2);

            result.GetType().GetProperties().Length.Should().Be(2);
            result.GetType().GetProperty("Property1").GetValue(result).Should().Be("value2");
            result.GetType().GetProperty("Property2").Should().NotBeNull();
        }
Ejemplo n.º 4
0
        public void Merge_Types_with_Ignore_Policy()
        {
            var obj1 = new { Property1 = "values1", Property2 = "values1" };
            var obj2 = new { Property1 = "values2", Property4 = "values4" };

            var result = TypeMerger.Ignore(() => obj1.Property1)
                         .Ignore(() => obj2.Property4)
                         .Merge(obj1, obj2);

            Assert.Equal(2, result.GetType().GetProperties().Length);

            Assert.Equal("values2", result.GetType().GetProperty("Property1").GetValue(result));

            Assert.NotNull(result.GetType().GetProperty("Property2"));
        }
Ejemplo n.º 5
0
        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 = TypeMerger.Merge(obj1, obj2);

            result1.GetType().GetProperties().Length.Should().Be(3);
            result1.GetType().GetProperty("Property1").GetValue(result1).Should().Be("value1");

            var result2 = TypeMerger.Ignore(() => obj1.Property2)
                          .Merge(obj1, obj2);

            result2.GetType().GetProperties().Length.Should().Be(2);
            result2.GetType().GetProperty("Property3").GetValue(result2).Should().Be("3");
        }