Esempio n. 1
0
        public void PatchTargetWihDifferentType()
        {
            var jsonString = "{ int1: 1, string1: 'val1', dateTime1: '2018-12-04' }";
            var testObject = new TestObject();

            var targetObject = new TestObject2();

            var delta = JsonConvert.DeserializeObject <DeltaFor <TestObject> >(jsonString);

            delta.Patch(targetObject);

            targetObject.Int1.Should().Be(1);
            targetObject.String2.Should().Be(default(string));
            targetObject.DateTime1.Should().Be(new DateTime(2018, 12, 4));
        }
Esempio n. 2
0
        public void PatchWithMappings()
        {
            DeltaObjectMappingConfig <TestObject, TestObject2> .GlobalConfig()
            .Map(p => p.Int1, t => t.Int2)
            .Map(p => p.String1, t => t.String2)
            .Map(p => p.Bool1, t => t.Bool3);

            var jsonString = "{ int1: 1, string1: 'val1', bool1: true }";
            var testObject = new TestObject();

            var targetObject = new TestObject2();

            var delta = JsonConvert.DeserializeObject <DeltaFor <TestObject> >(jsonString);

            delta.Patch(targetObject);

            targetObject.Int2.Should().Be(1);
            targetObject.String2.Should().Be("val1");
            targetObject.Bool3.Should().Be(true);
        }
Esempio n. 3
0
        public void PatchIgnoringProperties()
        {
            DeltaObjectMappingConfig <TestObject, TestObject2> .GlobalConfig()
            .Map(p => p.String1, t => t.String2)
            .Ignore(p => p.Int1)
            .Ignore(p => p.Bool1)
            .Ignore(p => p.DateTime1);

            var jsonString = "{ int1: 1, string1: 'val1', dateTime1: '2018-12-04' }";
            var testObject = new TestObject();

            var targetObject = new TestObject2();

            var delta = JsonConvert.DeserializeObject <DeltaFor <TestObject> >(jsonString);

            delta.Patch(targetObject);

            targetObject.Int1.Should().Be(default(int));
            targetObject.String2.Should().Be("val1");
            targetObject.DateTime1.Should().Be(default(DateTime));
        }