예제 #1
0
        public void ReplaceNestedObjectWithSerialization()
        {
            // Arrange
            var doc = new SimpleDTOWithNestedDTO()
            {
                IntegerValue = 1
            };

            var newNested = new NestedDTO() { StringProperty = "B" };

            // create patch
            var patchDoc = new JsonPatchDocument<SimpleDTOWithNestedDTO>();
            patchDoc.Replace<NestedDTO>(o => o.NestedDTO, newNested);

            var serialized = JsonConvert.SerializeObject(patchDoc);
            var deserialized = JsonConvert.DeserializeObject<JsonPatchDocument<SimpleDTOWithNestedDTO>>(serialized);

            // Act
            deserialized.ApplyTo(doc);

            // Assert
            Assert.Equal("B", doc.NestedDTO.StringProperty);
        }
예제 #2
0
        public void ReplaceNestedObject()
        {
            // Arrange
            var doc = new SimpleDTOWithNestedDTO()
            {
                IntegerValue = 1
            };

            var newNested = new NestedDTO() { StringProperty = "B" };

            // create patch
            var patchDoc = new JsonPatchDocument<SimpleDTOWithNestedDTO>();
            patchDoc.Replace<NestedDTO>(o => o.NestedDTO, newNested);

            // Act
            patchDoc.ApplyTo(doc);

            // Assert
            Assert.Equal("B", doc.NestedDTO.StringProperty);
        }