Beispiel #1
0
        /// <summary>
        /// RecursionTest deep copy test
        /// </summary>
        public void DeepCopyRecursionTest()
        {
            var tempObj = new TestsTabelToListObject
            {
                Age        = 10,
                Name       = "k",
                Height     = 20.907,
                Right      = true,
                Sex        = EnumSex.boy,
                YouLong    = new TimeSpan(1, 1, 1, 5),
                AdressList = new List <string> {
                    "Chongqing", "Beijing", "Shanghai"
                }
            };
            var copyResult = DeepCopyHelper.DeepCopyRecursion(tempObj) as TestsTabelToListObject;

            new TimeSpan(1, 1, 1, 5).IsEqualTo(copyResult.YouLong);
            tempObj.AdressList[2] = "TianAnMen";
            tempObj.AdressList[2].IsNotEqualTo(copyResult.AdressList[2]);

            var list = new List <TestsTabelToListObject>();

            _testList.ForEach(f =>
            {
                var temp = new TestsTabelToListObject();
                temp     = DeepCopyHelper.DeepCopyRecursion(f) as TestsTabelToListObject;
                list.Add(temp);
            });
            list.Count.IsEqualTo(_testList.Count);
        }
Beispiel #2
0
        /// <summary>
        /// Test deep copy helper
        /// </summary>
        public void DeepCopyTest()
        {
            var tempObj = new TestsTabelToListObject
            {
                Age        = 10,
                Name       = "k",
                Height     = 20.907,
                Right      = true,
                Sex        = EnumSex.boy,
                YouLong    = new TimeSpan(1, 1, 1, 5),
                AdressList = new List <string> {
                    "Chongqing", "Beijing", "Shanghai"
                }
            };
            var copyResult = tempObj.DeepCopy();

            new TimeSpan(1, 1, 1, 5).IsEqualTo(copyResult.YouLong);

            var list = new List <TestsTabelToListObject>();

            _testList.ForEach(f =>
            {
                var temp = new TestsTabelToListObject();
                f.DeepCopy(temp);
                list.Add(temp);
            });
            list.Count.IsEqualTo(_testList.Count);
        }