Пример #1
0
        public void AutoPatch_works_with_null()
        {
            const string json = @"
            {
                'stringProperty' : null
            }";

            var patch = new Patch <SourceClass>(json);

            var targetObject = new TargetClass
            {
                StringProperty = "original",
            };

            patch.AutoPatch(targetObject,
                            x => x.StringProperty
                            );

            Assert.IsNull(targetObject.StringProperty);
        }
Пример #2
0
        public void Patch_value_is_not_applied_if_validation_fails()
        {
            const string json = @"
            {
                'IntProperty' : 15
            }";

            var patch = new Patch <SourceClass>(json);

            var targetObject = new TargetClass
            {
                IntProperty = 1
            };

            patch.AutoPatch(targetObject,
                            x => x.IntProperty
                            );

            Assert.AreEqual(1, targetObject.IntProperty);
        }
Пример #3
0
        public void Patch_is_case_insensitive()
        {
            const string json = @"
            {
                'stringproperty' : 'json_value',
                'INTPROPERTY' : 10
            }";

            var patch = new Patch <SourceClass>(json);

            var targetObject = new TargetClass
            {
                StringProperty = "original_value",
                IntProperty    = 1
            };

            patch.AutoPatch(targetObject,
                            x => x.StringProperty,
                            x => x.IntProperty
                            );

            Assert.AreEqual("json_value", targetObject.StringProperty);
            Assert.AreEqual(10, targetObject.IntProperty);
        }