示例#1
0
        public async Task CanCloneSerializedModel()
        {
            var model = new CloneModel {
                IntProperty    = 1,
                StringProperty = "test",
                ListProperty   = new List <int> {
                    1
                },
                ObjectProperty = new CloneModel {
                    IntProperty = 1
                }
            };

            var serializer = new JsonNetSerializer();
            var json       = await serializer.SerializeToStringAsync(model);

            var deserialized = await serializer.DeserializeAsync <CloneModel>(json);

            Assert.Equal(model.IntProperty, deserialized.IntProperty);
            Assert.Equal(model.StringProperty, deserialized.StringProperty);
            Assert.Equal(model.ListProperty, deserialized.ListProperty);
            var dm = ((JToken)deserialized.ObjectProperty).ToObject <CloneModel>();

            Assert.Equal(((CloneModel)model.ObjectProperty).IntProperty, dm.IntProperty);

            var cloned = deserialized.DeepClone();

            Assert.Equal(model.IntProperty, cloned.IntProperty);
            Assert.Equal(model.StringProperty, cloned.StringProperty);
            Assert.Equal(model.ListProperty, cloned.ListProperty);
            var cdm = ((JToken)cloned.ObjectProperty).ToObject <CloneModel>();

            Assert.Equal(((CloneModel)model.ObjectProperty).IntProperty, cdm.IntProperty);
        }