Exemplo n.º 1
0
    public void Deep_Clone_Array_Property()
    {
        var test1 = new Test3 {
            MyTest1 = new object[] { new Test1(), new Test1() }
        };

        var clone = (Test3)test1.DeepClone();

        Assert.AreNotSame(test1, clone);
        Assert.AreEqual(test1.MyTest1.Length, clone.MyTest1.Length);
        for (var i = 0; i < test1.MyTest1.Length; i++)
        {
            Assert.IsNotNull(clone.MyTest1.ElementAt(i));
            Assert.AreNotSame(clone.MyTest1.ElementAt(i), test1.MyTest1.ElementAt(i));
        }
    }
Exemplo n.º 2
0
        public void Cannot_Deep_Clone_Collection_Properties_That_Are_Not_Cloneable()
        {
            var test1 = new Test3()
            {
                MyTest1 = new object[]
                {
                    new Test1(), "hello",
                    //not cloneable so this property will get skipped
                    new Test2()
                }
            };

            var clone = (Test3)test1.DeepClone();

            //it skipped this property so these will now be the same
            Assert.AreSame(clone.MyTest1, test1.MyTest1);
        }