Esempio n. 1
0
        public void CopyMatchingObjectPropertiesToTest()
        {
            var source = new
            {
                IntPropNonNullable = 1,
                IntPropNullable    = (int?)null,
                StringProp         = "Source String",
                DateTimeProp       = DateTime.Now,
                DateRangeProp      = new DateRange(DateTime.Today, DateTime.Now),
                SubObject          = new
                {
                    IntPropNonNullable = 1,
                    IntPropNullable    = (int?)null,
                    StringProp         = "Source String",
                },
                StringArrayProp = new string[3] {
                    "Matt", "Joanne", "Robert"
                }
            };
            var dest = new ReflectionUtilsMockObject()
            {
                IntPropNonNullable = 10,
                IntPropNullable    = 20,
                StringProp         = "Destination String",
                DateTimeProp       = DateTime.Now.AddDays(1),
                DateRangeProp      = new DateRange(DateTime.Today.AddDays(1), DateTime.Now.AddDays(1)),
                StringArrayProp    = (string[])null
            };

            Assert.AreNotEqual(source.IntPropNonNullable, dest.IntPropNonNullable, "IntPropNonNullable");
            Assert.AreNotEqual(source.IntPropNullable, dest.IntPropNullable, "IntPropNullable");
            Assert.AreNotEqual(source.StringProp, dest.StringProp, "StringProp");
            Assert.AreNotEqual(source.StringProp, dest.StringProp, "DateTimeProp");
            Assert.AreNotEqual(source.StringProp, dest.StringProp, "DateRangeProp");
            Assert.AreNotEqual(source.SubObject.IntPropNonNullable, dest.IntPropNonNullable, "SubObject.IntPropNonNullable");
            Assert.AreNotEqual(source.SubObject.IntPropNullable, dest.IntPropNullable, "SubObject.IntPropNullable");
            Assert.AreNotEqual(source.SubObject.StringProp, dest.StringProp, "SubObject.StringProp");
            Assert.AreNotEqual(source.SubObject.StringProp, dest.StringProp, "SubObject.DateTimeProp");
            Assert.AreNotEqual(source.SubObject.StringProp, dest.StringProp, "SubObject.DateRangeProp");

            ObjectExtensions.CopyMatchingObjectPropertiesTo(source, dest);

            Assert.AreEqual(source.IntPropNonNullable, dest.IntPropNonNullable, "IntPropNonNullable");
            Assert.AreEqual(source.IntPropNullable, dest.IntPropNullable, "IntPropNullable");
            Assert.AreEqual(source.StringProp, dest.StringProp, "StringProp");
            Assert.AreEqual(source.DateTimeProp, dest.DateTimeProp, "DateTimeProp");
            Assert.AreEqual(source.DateRangeProp, dest.DateRangeProp, "DateRangeProp");
            Assert.AreEqual(source.SubObject.IntPropNonNullable, dest.IntPropNonNullable, "SubObject.IntPropNonNullable");
            Assert.AreEqual(source.SubObject.IntPropNullable, dest.IntPropNullable, "SubObject.IntPropNullable");
            Assert.AreEqual(source.SubObject.StringProp, dest.StringProp, "SubObject.StringProp");
            Assert.AreEqual(source.SubObject.StringProp, dest.StringProp, "SubObject.DateTimeProp");
            Assert.AreEqual(source.SubObject.StringProp, dest.StringProp, "SubObject.DateRangeProp");
            Assert.AreEqual(source.StringArrayProp[0], dest.StringArrayProp[0], "StringArrayProp[0]");
            Assert.AreEqual(source.StringArrayProp[1], dest.StringArrayProp[1], "StringArrayProp[1]");
            Assert.AreEqual(source.StringArrayProp[2], dest.StringArrayProp[2], "StringArrayProp[2]");
        }