Esempio n. 1
0
        public ParseNode Find(JsonPointer referencePointer)
        {
            var yamlNode = referencePointer.Find(_yamlDocument.RootNode);

            if (yamlNode == null)
            {
                return(null);
            }

            return(Create(Context, yamlNode));
        }
Esempio n. 2
0
        public void Remove_a_property()
        {

            var sample = PatchTests.GetSample2();

            var patchDocument = new PatchDocument();
            var pointer = new JsonPointer("/books/0/author");

            patchDocument.AddOperation(new RemoveOperation() { Path = pointer });

            new JsonPatcher().Patch(ref sample, patchDocument);

            Assert.Throws(typeof(ArgumentException), () => { pointer.Find(sample); });
        }
Esempio n. 3
0
        public void Replace_a_property_value_with_a_new_value()
        {

            var sample = PatchTests.GetSample2();

            var patchDocument = new PatchDocument();
            var pointer = new JsonPointer("/books/0/author");

            patchDocument.AddOperation(new ReplaceOperation() { Path = pointer, Value = new JValue("Bob Brown") });

            new JsonPatcher().Patch(ref sample, patchDocument);

            Assert.Equal("Bob Brown", (string)pointer.Find(sample));
        }
Esempio n. 4
0
        public void Replace_a_property_value_with_an_object()
        {

            var sample = PatchTests.GetSample2();

            var patchDocument = new PatchDocument();
            var pointer = new JsonPointer("/books/0/author");

            patchDocument.AddOperation(new ReplaceOperation() { Path = pointer, Value = new JObject(new[] { new JProperty("hello", "world") }) });

            new JsonPatcher().Patch(ref sample, patchDocument);

            var newPointer = new JsonPointer("/books/0/author/hello");
            Assert.Equal("world", (string)newPointer.Find(sample));
        }
Esempio n. 5
0
        public void Replace_a_property_value_with_a_new_value()
        {
            var sample = PatchTests.GetSample2();

            var patchDocument = new PatchDocument();
            var pointer       = new JsonPointer("/books/0/author");

            patchDocument.AddOperation(new ReplaceOperation()
            {
                Path = pointer, Value = new JValue("Bob Brown")
            });

            patchDocument.ApplyTo(new JsonNetTargetAdapter(sample));

            Assert.Equal("Bob Brown", (string)pointer.Find(sample));
        }
Esempio n. 6
0
        public void Remove_a_property()
        {
            var sample = PatchTests.GetSample2();

            var patchDocument = new PatchDocument();
            var pointer       = new JsonPointer("/books/0/author");

            patchDocument.AddOperation(new RemoveOperation()
            {
                Path = pointer
            });

            patchDocument.ApplyTo(sample);

            Assert.Throws(typeof(ArgumentException), () => { pointer.Find(sample); });
        }
Esempio n. 7
0
        public void Move_array_element()
        {
            var sample = PatchTests.GetSample2();

            var patchDocument = new PatchDocument();
            var frompointer = new JsonPointer("/books/1");
            var topointer = new JsonPointer("/books/0/child");

            patchDocument.AddOperation(new MoveOperation() { FromPath = frompointer, Path = topointer });

            var patcher = new JsonPatcher();
            patcher.Patch(ref sample, patchDocument);


            var result = topointer.Find(sample);
            Assert.IsType(typeof(JObject), result);
        }
Esempio n. 8
0
        public void Move_property()
        {
            var sample = PatchTests.GetSample2();

            var patchDocument = new PatchDocument();
            var frompointer = new JsonPointer("/books/0/author");
            var topointer = new JsonPointer("/books/1/author");

            patchDocument.AddOperation(new MoveOperation() { FromPath = frompointer, Path = topointer });

            var patcher = new JsonPatcher();
            patcher.Patch(ref sample, patchDocument);


            var result = (string)topointer.Find(sample);
            Assert.Equal("F. Scott Fitzgerald", result);
        }
Esempio n. 9
0
        public void Replace_a_property_value_with_an_object()
        {
            var sample = PatchTests.GetSample2();

            var patchDocument = new PatchDocument();
            var pointer       = new JsonPointer("/books/0/author");

            patchDocument.AddOperation(new ReplaceOperation()
            {
                Path = pointer, Value = new JObject(new[] { new JProperty("hello", "world") })
            });

            patchDocument.ApplyTo(new JsonNetTargetAdapter(sample));

            var newPointer = new JsonPointer("/books/0/author/hello");

            Assert.Equal("world", (string)newPointer.Find(sample));
        }
Esempio n. 10
0
        public void Add_an_non_existing_member_property()  // Why isn't this replace?
        {

            var sample = PatchTests.GetSample2();

            var patchDocument = new PatchDocument();
            var pointer = new JsonPointer("/books/0/ISBN");

            patchDocument.AddOperation(new AddOperation() { Path = pointer, Value = new JValue("213324234343") });

            var patcher = new JsonPatcher();
            patcher.Patch(ref sample, patchDocument);


            var result = (string)pointer.Find(sample);
            Assert.Equal("213324234343", result);

        }
Esempio n. 11
0
        public void Remove_an_array_element()
        {
            var sample = PatchTests.GetSample2();

            var patchDocument = new PatchDocument();
            var pointer       = new JsonPointer("/books/0");

            patchDocument.AddOperation(new RemoveOperation()
            {
                Path = pointer
            });

            patchDocument.ApplyTo(sample);

            Assert.Throws(typeof(PathNotFoundException), () =>
            {
                var x = pointer.Find("/books/1");
            });
        }
Esempio n. 12
0
        public void Remove_an_array_element()
        {

            var sample = PatchTests.GetSample2();

            var patchDocument = new PatchDocument();
            var pointer = new JsonPointer("/books/0");

            patchDocument.AddOperation(new RemoveOperation() { Path = pointer });

            var patcher = new JsonPatcher();
            patcher.Patch(ref sample, patchDocument);

            Assert.Throws(typeof(ArgumentException), () =>
            {
                var x = pointer.Find("/books/1");
            });

        }
Esempio n. 13
0
        public void Add_an_non_existing_member_property()  // Why isn't this replace?
        {
            var sample = PatchTests.GetSample2();

            var patchDocument = new PatchDocument();
            var pointer       = new JsonPointer("/books/0/ISBN");

            patchDocument.AddOperation(new AddOperation()
            {
                Path = pointer, Value = new JValue("213324234343")
            });

            patchDocument.ApplyTo(sample);


            var result = (string)pointer.Find(sample);

            Assert.Equal("213324234343", result);
        }
Esempio n. 14
0
        public void Move_array_element()
        {
            var sample = PatchTests.GetSample2();

            var patchDocument = new PatchDocument();
            var frompointer   = new JsonPointer("/books/1");
            var topointer     = new JsonPointer("/books/0/child");

            patchDocument.AddOperation(new MoveOperation()
            {
                FromPath = frompointer, Path = topointer
            });

            patchDocument.ApplyTo(sample);


            var result = topointer.Find(sample);

            Assert.IsType(typeof(JObject), result);
        }
Esempio n. 15
0
        public void Move_property()
        {
            var sample = PatchTests.GetSample2();

            var patchDocument = new PatchDocument();
            var frompointer   = new JsonPointer("/books/0/author");
            var topointer     = new JsonPointer("/books/1/author");

            patchDocument.AddOperation(new MoveOperation()
            {
                FromPath = frompointer, Path = topointer
            });

            patchDocument.ApplyTo(sample);


            var result = (string)topointer.Find(sample);

            Assert.Equal("F. Scott Fitzgerald", result);
        }
Esempio n. 16
0
        public void Add_a_non_existing_member_property_with_slash_character()
        {
            var sample = PatchTests.GetSample2();

            var patchDocument = new PatchDocument();
            var pointer       = new JsonPointer("/books/0/b~1c");

            patchDocument.AddOperation(new AddOperation()
            {
                Path = pointer, Value = new JValue("42")
            });

            var patcher = new JsonPatcher();

            patcher.Patch(ref sample, patchDocument);


            var result = (string)pointer.Find(sample);

            Assert.AreEqual("42", result);
        }
Esempio n. 17
0
        public void Add_an_existing_member_property()  // Why isn't this replace?
        {
            var sample = PatchTests.GetSample2();

            var patchDocument = new PatchDocument();
            var pointer       = new JsonPointer("/books/0/title");

            patchDocument.AddOperation(new AddOperation()
            {
                Path = pointer, Value = new JValue("Little Red Riding Hood")
            });

            var patcher = new JsonPatcher();

            patcher.Patch(ref sample, patchDocument);


            var result = (string)pointer.Find(sample);

            Assert.Equal("Little Red Riding Hood", result);
        }