Пример #1
0
        public void AddNewPropertyToExpandoOjectInTypedObject()
        {
            var doc = new NestedDTO()
            {
                DynamicProperty = new ExpandoObject()
            };

            // create patch
            JsonPatchDocument patchDoc = new JsonPatchDocument();

            patchDoc.Add("DynamicProperty/NewInt", 1);

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

            deserialized.ApplyTo(doc);

            Assert.Equal(1, doc.DynamicProperty.NewInt);
        }
Пример #2
0
        public void ShouldNotBeAbleToAddToNonExistingPropertyThatIsNotTheRoot()
        {
            //Adding to a Nonexistent Target
            //
            //   An example target JSON document:
            //   { "foo": "bar" }
            //   A JSON Patch document:
            //   [
            //        { "op": "add", "path": "/baz/bat", "value": "qux" }
            //      ]
            //   This JSON Patch document, applied to the target JSON document above,
            //   would result in an error (therefore, it would not be applied),
            //   because the "add" operation's target location that references neither
            //   the root of the document, nor a member of an existing object, nor a
            //   member of an existing array.

            var doc = new NestedDTO()
            {
                DynamicProperty = new ExpandoObject()
            };

            // create patch
            JsonPatchDocument patchDoc = new JsonPatchDocument();

            patchDoc.Add("DynamicProperty/OtherProperty/IntProperty", 1);

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

            var exception = Assert.Throws <JsonPatchException>(() =>
            {
                deserialized.ApplyTo(doc);
            });

            Assert.Equal(
                "The property at path '/DynamicProperty/OtherProperty/IntProperty' could not be added.",
                exception.Message);
        }
Пример #3
0
        public void AddNewPropertyToTypedObjectInExpandoObject()
        {
            dynamic dynamicProperty = new ExpandoObject();

            dynamicProperty.StringProperty = "A";

            var doc = new NestedDTO()
            {
                DynamicProperty = dynamicProperty
            };

            // create patch
            JsonPatchDocument patchDoc = new JsonPatchDocument();

            patchDoc.Add("DynamicProperty/StringProperty", "B");

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

            deserialized.ApplyTo(doc);

            Assert.Equal("B", doc.DynamicProperty.StringProperty);
        }
Пример #4
0
        public void ShouldNotBeAbleToAddToNonExistingPropertyThatIsNotTheRoot()
        {
            //Adding to a Nonexistent Target
            //
            //   An example target JSON document:
            //   { "foo": "bar" }
            //   A JSON Patch document:
            //   [
            //        { "op": "add", "path": "/baz/bat", "value": "qux" }
            //      ]
            //   This JSON Patch document, applied to the target JSON document above,
            //   would result in an error (therefore, it would not be applied),
            //   because the "add" operation's target location that references neither
            //   the root of the document, nor a member of an existing object, nor a
            //   member of an existing array.

            var doc = new NestedDTO()
            {
                DynamicProperty = new ExpandoObject()
            };

            // create patch
            JsonPatchDocument patchDoc = new JsonPatchDocument();
            patchDoc.Add("DynamicProperty/OtherProperty/IntProperty", 1);

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

            var exception = Assert.Throws<JsonPatchException>(() =>
            {
                deserialized.ApplyTo(doc);
            });
            Assert.Equal(
                "The property at path '/DynamicProperty/OtherProperty/IntProperty' could not be added.",
                exception.Message);
        }
Пример #5
0
        public void AddNewPropertyToTypedObjectInExpandoObject()
        {
            dynamic dynamicProperty = new ExpandoObject();
            dynamicProperty.StringProperty = "A";

            var doc = new NestedDTO()
            {
                DynamicProperty = dynamicProperty
            };

            // create patch
            JsonPatchDocument patchDoc = new JsonPatchDocument();
            patchDoc.Add("DynamicProperty/StringProperty", "B");

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

            deserialized.ApplyTo(doc);

            Assert.Equal("B", doc.DynamicProperty.StringProperty);
        }
Пример #6
0
        public void AddNewPropertyToExpandoOjectInTypedObject()
        {
            var doc = new NestedDTO()
            {
                DynamicProperty = new ExpandoObject()
            };

            // create patch
            JsonPatchDocument patchDoc = new JsonPatchDocument();
            patchDoc.Add("DynamicProperty/NewInt", 1);

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

            deserialized.ApplyTo(doc);

            Assert.Equal(1, doc.DynamicProperty.NewInt);
        }
Пример #7
0
 public SimpleDTOWithNestedDTO()
 {
     NestedDTO       = new NestedDTO();
     SimpleDTO       = new SimpleDTO();
     ListOfSimpleDTO = new List <SimpleDTO>();
 }
Пример #8
0
 public SimpleDTOWithNestedDTO()
 {
     NestedDTO = new NestedDTO();
     SimpleDTO = new SimpleDTO();
     ListOfSimpleDTO = new List<SimpleDTO>();
 }