Example #1
0
        public void ObjectCloneTest()
        {
            var model = new TestModel
            {
                B      = "B",
                Model1 = new TestModel1("Model1"),
                Model2 = new TestModel2 {
                    A = "A", B = 1
                },
                Self = new TestModel {
                    B = "E"
                },
                SelfList = new List <TestModel> {
                    new TestModel {
                        B = "l"
                    }
                }
            };
            object obj       = model;
            var    testModel = ObjectCloneOperator.Clone(obj);

            Assert.NotSame(model, testModel);
            Assert.Equal(model.B, ((TestModel)testModel).B);
            Assert.NotNull(model.Model1);
            Assert.NotSame(model.Model2, ((TestModel)testModel).Model2);
            Assert.Equal(model.Model2.A, ((TestModel)testModel).Model2.A);
            Assert.Equal(model.Model2.B, ((TestModel)testModel).Model2.B);
            Assert.NotSame(model.Self, ((TestModel)testModel).Self);
            Assert.Equal(model.Self.B, ((TestModel)testModel).Self.B);
            Assert.NotSame(model.SelfList, ((TestModel)testModel).SelfList);
            Assert.Equal(model.SelfList[0].B, ((TestModel)testModel).SelfList[0].B);
        }
Example #2
0
        public void ObjectSourceTest()
        {
            object obj       = new object();
            var    testModel = ObjectCloneOperator.Clone(obj);

            Assert.NotNull(testModel);
            Assert.NotSame(obj, testModel);
        }
Example #3
0
        public void ObjectInnerTest()
        {
            TestModel.InnerClass model = new TestModel.InnerClass();
            model.Name     = "abc";
            model.SelfList = new List <TestModel> {
                new TestModel {
                    B = "l"
                }
            };
            object obj       = model;
            var    testModel = ObjectCloneOperator.Clone(obj);

            Assert.NotSame(obj, testModel);
            Assert.NotSame(model.SelfList, ((TestModel.InnerClass)testModel).SelfList);
            Assert.Equal(model.SelfList[0].B, ((TestModel.InnerClass)testModel).SelfList[0].B);
        }
Example #4
0
        public void ObjectCloneTest()
        {
            //System.ValueType
            Object obj    = 1;
            var    objNew = ObjectCloneOperator.Clone(obj);

            Assert.Same(obj, objNew);
            Assert.Equal(obj, objNew);
            //class
            object objA = new TestModel()
            {
                A = 2
            };
            object objB = ObjectCloneOperator.Clone(objA);

            Assert.NotNull(objB);
            Assert.NotSame(objA, objB);
            Assert.Equal(((TestModel)objA).A, ((TestModel)objB).A);
            //dict
            object dictA = new Dictionary <string, string>();
            object dictB = ObjectCloneOperator.Clone(dictA);

            Assert.NotNull(dictB);
            Assert.NotSame(dictA, dictB);
            //list
            object listA = new List <string>();
            object listB = ObjectCloneOperator.Clone(listA);

            Assert.NotNull(listB);
            Assert.NotSame(listA, listB);
            //arr
            object arrA = new string[0];
            object arrB = ObjectCloneOperator.Clone(arrA);

            Assert.NotNull(arrB);
            Assert.NotSame(arrA, arrB);
        }