Esempio n. 1
0
        public void SetAddTestObjectCollectionElement()
        {
            var payload = GetTestObject();

            payload = JsonPointer.Set(payload, "/Collection/-", "last");
            Assert.AreEqual("last", JsonPointer.Get <string>(payload, "/Collection/3"));
        }
Esempio n. 2
0
        public void ExampleCollectionTest()
        {
            var sample = @"{
              'books': [
                {
                  'title' : 'The Great Gatsby',
                  'author' : 'F. Scott Fitzgerald'
                },
                {
                  'title' : 'The Grapes of Wrath',
                  'author' : 'John Steinbeck'
                }
              ]
            }";

            var result = JsonPointer.Get <List <Book> >(sample, "/books");

            Assert.IsTrue(result.Count == 2);

            sample = JsonPointer.Set(sample, "/books/-", new Book {
                Title = "Jayne Eyre", Author = "Charlotte Brontë"
            });
            result = JsonPointer.Get <List <Book> >(sample, "/books");
            Assert.IsTrue(result.Count == 3);
        }
Esempio n. 3
0
        public void CannotSetRealObjectSubPropertiesThatDoNotExist()
        {
            var payload = GetTestObject();

            payload = JsonPointer.Set(payload, "/Settings/Wait", false);
            Assert.AreEqual(false, JsonPointer.Get <bool>(payload, "/Settings/Wait"));
        }
Esempio n. 4
0
        public void SetObjectSubPropertiesDoesNotExist()
        {
            var payload = GetPocoObject();

            payload = JsonPointer.Set(payload, "/Settings/Wait", false);
            Assert.AreEqual(false, JsonPointer.Get <bool>(payload, "/Settings/Wait"));
        }
Esempio n. 5
0
        public void SetTestObjectSubProperties()
        {
            var payload = GetTestObject();

            payload = JsonPointer.Set(payload, "/Settings/Launch", false);
            Assert.AreEqual(false, JsonPointer.Get <bool>(payload, "/Settings/Launch"));
        }
Esempio n. 6
0
        public void Issue1()
        {
            var input  = "[{\"Id\":\"b4120a48-d5b0-476f-a653-083f3725dfce\"}]";
            var result = JsonPointer.Get <List <Foo> >(input, "/");

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Count);
        }
Esempio n. 7
0
        public void ReplacePropertyUsingSet()
        {
            var obj = @"{ foo: 1, bar: { baz: 2}, qux: [3, 4, 5]}";

            obj = JsonPointer.Set(obj, "/foo", 6);   // sets obj.foo = 6;

            Assert.AreEqual(6, JsonPointer.Get <int>(obj, "/foo"));
        }
Esempio n. 8
0
        public void AddItemToCollectionUsingSet()
        {
            var obj = @"{ foo: 1, bar: { baz: 2}, qux: [3, 4, 5]}";

            obj = JsonPointer.Set(obj, "/qux/-", 6); // sets obj.qux = [3, 4, 5, 6]

            Assert.AreEqual(3, JsonPointer.Get <int>(obj, "/qux/0"));
            Assert.AreEqual(4, JsonPointer.Get <int>(obj, "/qux/1"));
            Assert.AreEqual(5, JsonPointer.Get <int>(obj, "/qux/2"));
            Assert.AreEqual(6, JsonPointer.Get <int>(obj, "/qux/3"));
        }
Esempio n. 9
0
        public void Example()
        {
            var obj = @"{ foo: 1, bar: { baz: 2}, qux: [3, 4, 5]}";

            Assert.AreEqual(1, JsonPointer.Get <int>(obj, "/foo"));
            Assert.AreEqual(2, JsonPointer.Get <int>(obj, "/bar/baz"));
            Assert.AreEqual(2, JsonPointer.Get <int>(obj, "/bar/baz"));
            Assert.AreEqual(3, JsonPointer.Get <int>(obj, "/qux/0"));
            Assert.AreEqual(4, JsonPointer.Get <int>(obj, "/qux/1"));
            Assert.AreEqual(5, JsonPointer.Get <int>(obj, "/qux/2"));
        }
Esempio n. 10
0
        public void Example2Test()
        {
            var sample = @"{
              'books': [
                {
                  'title' : 'The Great Gatsby',
                  'author' : 'F. Scott Fitzgerald'
                },
                {
                  'title' : 'The Grapes of Wrath',
                  'author' : 'John Steinbeck'
                }
              ]
            }";

            var result = JsonPointer.Get <string>(sample, "/books/1/author"); // returns "John Steinbeck"

            Assert.AreEqual("John Steinbeck", result);
        }
Esempio n. 11
0
        public void PointToTokenWithEmbeddedTilde()
        {
            var sample = GetJsonObject();

            Assert.AreEqual(8, JsonPointer.Get <int>(sample, "/m~0n"));
        }
Esempio n. 12
0
        public void PointToTokenWithEscapedSpace()
        {
            var sample = GetJsonObject();

            Assert.AreEqual(7, JsonPointer.Get <int>(sample, "/%20"));
        }
Esempio n. 13
0
        public void PointToTokenWithEscapedQuote()
        {
            var sample = GetJsonObject();

            Assert.AreEqual(6, JsonPointer.Get <int>(sample, "/k%22l"));
        }
Esempio n. 14
0
        public void PointToTokenWithEscapedBackSlash()
        {
            var sample = GetJsonObject();

            Assert.AreEqual(5, JsonPointer.Get <int>(sample, "/i%5Cj"));
        }
Esempio n. 15
0
        public void MissingPropertyThrowsArgumentException()
        {
            var obj = @"{ foo: 1, bar: { baz: 2}, qux: [3, 4, 5]}";

            JsonPointer.Get <int>(obj, "/quo");     // throws ArgumentException
        }
Esempio n. 16
0
        public void PointToRoot()
        {
            var sample = GetJsonObject();

            Assert.IsTrue(JToken.DeepEquals(sample, JsonPointer.Get <JObject>(sample, "")));
        }
Esempio n. 17
0
        public void GetStringFromArrayIndexedProperty()
        {
            var sample = GetJsonString();

            Assert.AreEqual("John Steinbeck", JsonPointer.Get <string>(sample, "/books/1/author"));
        }
Esempio n. 18
0
        public void PointToTokenWithEncodedPercent()
        {
            var sample = GetJsonObject();

            Assert.AreEqual(2, JsonPointer.Get <int>(sample, "/c%25d"));
        }
Esempio n. 19
0
        public void CanHandleTestObjectSubProperties()
        {
            var payload = GetTestObject();

            Assert.AreEqual(true, JsonPointer.Get <bool>(payload, "/Settings/Launch"));
        }
Esempio n. 20
0
        public void PointToArrayElementThatDoesNotExistThrowsException()
        {
            var sample = GetJsonObject();

            JsonPointer.Get <string>(sample, "/foo/10");
        }
Esempio n. 21
0
        public void PointToArrayElement()
        {
            var sample = GetJsonObject();

            Assert.AreEqual(sample["foo"][0], JsonPointer.Get <string>(sample, "/foo/0"));
        }
Esempio n. 22
0
        public void PointToArray()
        {
            var sample = GetJsonObject();

            CollectionAssert.AreEqual(sample["foo"].ToObject <List <string> >(), JsonPointer.Get <List <string> >(sample, "/foo"));
        }
Esempio n. 23
0
        public void PointToTokenTwoLevelsDeep()
        {
            var sample = GetJsonObject();

            Assert.AreEqual("a3", JsonPointer.Get <string>(sample, "/tee/black"));
        }
Esempio n. 24
0
        public void PointToTokenWithEncodedCaret()
        {
            var sample = GetJsonObject();

            Assert.AreEqual(3, JsonPointer.Get <int>(sample, "/e%5Ef"));
        }
Esempio n. 25
0
        public void PointToTokenThreeLevelsDeep()
        {
            var sample = GetJsonObject();

            Assert.AreEqual("blue", JsonPointer.Get <string>(sample, "/tee/pink/1"));
        }
Esempio n. 26
0
        public void PointToTokenWithEscapedPipe()
        {
            var sample = GetJsonObject();

            Assert.AreEqual(4, JsonPointer.Get <int>(sample, "/g%7Ch"));
        }
Esempio n. 27
0
        public void PointToElementThatDoesNotExistThrowsException()
        {
            var sample = GetJsonObject();

            JsonPointer.Get <string>(sample, "/tee/nope");
        }
Esempio n. 28
0
        public void CanHandleTestObjectCollections()
        {
            var payload = GetTestObject();

            Assert.AreEqual("second", JsonPointer.Get <string>(payload, "/Collection/1"));
        }
Esempio n. 29
0
        public void CanHandleObjectProperties()
        {
            var payload = GetPocoObject();

            Assert.AreEqual(false, JsonPointer.Get <bool>(payload, "/Enabled"));
        }
Esempio n. 30
0
        public void PointToTokenWithEmbeddedSlash()
        {
            var sample = GetJsonObject();

            Assert.AreEqual(1, JsonPointer.Get <int>(sample, "/a~1b"));
        }