示例#1
0
        public void GoessnerExample9Constructed()
        {
            var path = JsonPathWith.Search("book").Array(jv => jv.Name("price") < 10);

            Console.WriteLine(path);
            var expected = new JsonArray
            {
                new JsonObject
                {
                    { "category", "reference" },
                    { "author", "Nigel Rees" },
                    { "title", "Sayings of the Century" },
                    { "price", 8.95 }
                },
                new JsonObject
                {
                    { "category", "fiction" },
                    { "author", "Herman Melville" },
                    { "title", "Moby Dick" },
                    { "isbn", "0-553-21311-3" },
                    { "price", 8.99 }
                }
            };
            var actual = path.Evaluate(GoessnerData);

            Assert.AreEqual(expected, actual);
        }
示例#2
0
        public void GoessnerExample8Constructed()
        {
            var path     = JsonPathWith.Search("book").Array(jv => jv.HasProperty("isbn"));
            var expected = new JsonArray
            {
                new JsonObject
                {
                    { "category", "fiction" },
                    { "author", "Herman Melville" },
                    { "title", "Moby Dick" },
                    { "isbn", "0-553-21311-3" },
                    { "price", 8.99 }
                },
                new JsonObject
                {
                    { "category", "fiction" },
                    { "author", "J. R. R. Tolkien" },
                    { "title", "The Lord of the Rings" },
                    { "isbn", "0-395-19395-8" },
                    { "price", 22.99 }
                }
            };
            var actual = path.Evaluate(GoessnerData);

            Assert.AreEqual(expected, actual);
        }
示例#3
0
        public void ObjectNameLengthExpression_LastItem()
        {
            var json = new JsonObject
            {
                { "name", new JsonArray {
                      1, 2, 3
                  } },
                { "name2", new JsonArray {
                      1, 2, 3
                  } },
                { "test", new JsonArray {
                      1, 2
                  } },
            };
            var path     = JsonPathWith.Array(jv => JsonPathRoot.Name("test").Length());
            var expected = new JsonArray {
                new JsonArray {
                    1, 2
                }
            };

            var actual = path.Evaluate(json);

            Assert.AreEqual(expected, actual);
        }
示例#4
0
        public void ArrayIndexExpression_IndexOfObject()
        {
            var obj = new JsonObject {
                { "key", "value" }
            };

            Run("$[?(@.indexOf({\"key\":\"value\"}) == 4)]", JsonPathWith.Array(jv => jv.IndexOf(obj) == 4));
        }
示例#5
0
        public void ArrayIndexExpression_IndexOfArray()
        {
            var arr = new JsonArray {
                1, 2, 3
            };

            Run("$[?(@.indexOf([1,2,3]) == 4)]", JsonPathWith.Array(jv => jv.IndexOf(arr) == 4));
        }
        // This won't work the same.  Parsing generates a ValueExpression, but the only way to
        // construct the path is to pass the field, which generates a FieldExpression. The parsed
        // path would be different in structure but should still represent the same thing.
        // We have to test by evaluation.
        public void IndexOfArray()
        {
            var arr = new JsonArray {
                1, 2, 3
            };

            CompareEval(JsonPathWith.Array(jv => jv.IndexOf(arr) == 6), "$[?(@.indexOf([1,2,3]) == 6)]");
        }
示例#7
0
        public void Issue16_PathIntolerantOfUnderscoresInPropertyNames()
        {
            var expected = JsonPathWith.Name("properties").Name("id_person");

            var actual = JsonPath.Parse("$.properties.id_person");

            Assert.AreEqual(expected.ToString(), actual.ToString());
        }
示例#8
0
        public void SteppedSlicedArray()
        {
            var text     = "$[1:5:2]";
            var expected = JsonPathWith.Array(new Slice(1, 5, 2));

            var actual = JsonPath.Parse(text);

            Assert.AreEqual(expected, actual);
        }
示例#9
0
        public void NamedObjectWithWildcardSearch()
        {
            var text     = "$.name..*";
            var expected = JsonPathWith.Name("name").Search();

            var actual = JsonPath.Parse(text);

            Assert.AreEqual(expected, actual);
        }
示例#10
0
        public void MultiSlicedArray()
        {
            var text     = "$[1:5,7:11:2]";
            var expected = JsonPathWith.Array(new Slice(1, 5), new Slice(7, 11, 2));

            var actual = JsonPath.Parse(text);

            Assert.AreEqual(expected, actual);
        }
示例#11
0
        public void DoubleQuotedNamedSearch()
        {
            var text     = "$..\"quoted name\"";
            var expected = JsonPathWith.Search("quoted name");

            var actual = JsonPath.Parse(text);

            Assert.AreEqual(expected, actual);
        }
示例#12
0
        public void SingleWildcardSearch()
        {
            var text     = "$..*";
            var expected = JsonPathWith.Search();

            var actual = JsonPath.Parse(text);

            Assert.AreEqual(expected, actual);
        }
示例#13
0
        public void WildcardObjectWithNamedObject()
        {
            var text     = "$.*.name";
            var expected = JsonPathWith.Name().Name("name");

            var actual = JsonPath.Parse(text);

            Assert.AreEqual(expected, actual);
        }
示例#14
0
        public void SingleNamedSearch()
        {
            var text     = "$..name";
            var expected = JsonPathWith.Search("name");

            var actual = JsonPath.Parse(text);

            Assert.AreEqual(expected, actual);
        }
示例#15
0
        public void SearchIndexedArray()
        {
            var text     = "$..[1]";
            var expected = JsonPathWith.SearchArray(1);

            var actual = JsonPath.Parse(text);

            Assert.AreEqual(expected, actual);
        }
示例#16
0
        public void WildcardArray()
        {
            var text     = "$[*]";
            var expected = JsonPathWith.Array();

            var actual = JsonPath.Parse(text);

            Assert.AreEqual(expected, actual);
        }
示例#17
0
        public void MultiIndexedArray()
        {
            var text     = "$[1,3]";
            var expected = JsonPathWith.Array(1, 3);

            var actual = JsonPath.Parse(text);

            Assert.AreEqual(expected, actual);
        }
示例#18
0
        public void SlicedIndexedArray()
        {
            var text     = "$[1:5,7]";
            var expected = JsonPathWith.Array(new Slice(1, 5), 7);

            var actual = JsonPath.Parse(text);

            Assert.AreEqual(expected, actual);
        }
示例#19
0
        public void GoessnerExample2Constructed()
        {
            var path     = JsonPathWith.Search("author");
            var expected = new JsonArray {
                "Nigel Rees", "Evelyn Waugh", "Herman Melville", "J. R. R. Tolkien"
            };
            var actual = path.Evaluate(GoessnerData);

            Assert.AreEqual(expected, actual);
        }
示例#20
0
        public void GoessnerExample4Constructed()
        {
            var path     = JsonPathWith.Name("store").Search("price");
            var expected = new JsonArray {
                8.95, 12.99, 8.99, 22.99, 19.95
            };
            var actual = path.Evaluate(GoessnerData);

            Assert.AreEqual(expected, actual);
        }
        // This won't work the same.  Parsing generates a ValueExpression, but the only way to
        // construct the path is to pass the field, which generates a FieldExpression. The parsed
        // path would be different in structure but should still represent the same thing.
        // We have to test by evaluation.
        public void IndexOfObject()
        {
            var obj = new JsonObject
            {
                ["bool"]   = false,
                ["int"]    = 20,
                ["string"] = "value",
            };

            CompareEval(JsonPathWith.Array(jv => jv.IndexOf(obj) == 1), "$[?(@.indexOf({\"key\":\"value\"}) == 1)]");
        }
示例#22
0
        public void Issue31_JsonPathArrayOperatorShouldWorkOnObjects_Constructed()
        {
            var json = GoessnerExamplesTest.GoessnerData;
            var path = JsonPathWith.Name("store")
                       .Name("bicycle")
                       .Array(jv => 1 == 1);

            var results = path.Evaluate(json);

            Assert.AreEqual(new JsonArray {
                "red", 19.95
            }, results);
        }
示例#23
0
        public void ArrayLengthExpression_LastItem()
        {
            var json = new JsonArray {
                1, 2, 3
            };
            var path     = JsonPathWith.Array(jv => jv.Length() - 1);
            var expected = new JsonArray {
                3
            };

            var actual = path.Evaluate(json);

            Assert.AreEqual(expected, actual);
        }
示例#24
0
        public void GoessnerExample3Constructed()
        {
            var path     = JsonPathWith.Name("store").Name();
            var expected = new JsonArray
            {
                new JsonArray
                {
                    new JsonObject
                    {
                        { "category", "reference" },
                        { "author", "Nigel Rees" },
                        { "title", "Sayings of the Century" },
                        { "price", 8.95 }
                    },
                    new JsonObject
                    {
                        { "category", "fiction" },
                        { "author", "Evelyn Waugh" },
                        { "title", "Sword of Honour" },
                        { "price", 12.99 }
                    },
                    new JsonObject
                    {
                        { "category", "fiction" },
                        { "author", "Herman Melville" },
                        { "title", "Moby Dick" },
                        { "isbn", "0-553-21311-3" },
                        { "price", 8.99 }
                    },
                    new JsonObject
                    {
                        { "category", "fiction" },
                        { "author", "J. R. R. Tolkien" },
                        { "title", "The Lord of the Rings" },
                        { "isbn", "0-395-19395-8" },
                        { "price", 22.99 }
                    }
                },
                new JsonObject
                {
                    { "color", "red" },
                    { "price", 19.95 }
                }
            };
            var actual = path.Evaluate(GoessnerData);

            Assert.AreEqual(expected, actual);
        }
示例#25
0
        public void GoessnerExample6BConstructed()
        {
            var path     = JsonPathWith.Search("book").Array(new Slice(-1, null));
            var expected = new JsonArray
            {
                new JsonObject
                {
                    { "category", "fiction" },
                    { "author", "J. R. R. Tolkien" },
                    { "title", "The Lord of the Rings" },
                    { "isbn", "0-395-19395-8" },
                    { "price", 22.99 }
                }
            };
            var actual = path.Evaluate(GoessnerData);

            Assert.AreEqual(expected, actual);
        }
示例#26
0
        public void GoessnerExample5Constructed()
        {
            var path     = JsonPathWith.Search("book").Array(2);
            var expected = new JsonArray
            {
                new JsonObject
                {
                    { "category", "fiction" },
                    { "author", "Herman Melville" },
                    { "title", "Moby Dick" },
                    { "isbn", "0-553-21311-3" },
                    { "price", 8.99 }
                }
            };
            var actual = path.Evaluate(GoessnerData);

            Assert.AreEqual(expected, actual);
        }
示例#27
0
        public void GoessnerExample7BConstructed()
        {
            var path     = JsonPathWith.Search("book").Array(new Slice(null, 2));
            var expected = new JsonArray
            {
                new JsonObject
                {
                    { "category", "reference" },
                    { "author", "Nigel Rees" },
                    { "title", "Sayings of the Century" },
                    { "price", 8.95 }
                },
                new JsonObject
                {
                    { "category", "fiction" },
                    { "author", "Evelyn Waugh" },
                    { "title", "Sword of Honour" },
                    { "price", 12.99 }
                }
            };
            var actual = path.Evaluate(GoessnerData);

            Assert.AreEqual(expected, actual);
        }
 public void DoesNotHaveProperty()
 {
     Run(JsonPathWith.Array(jv => !jv.HasProperty("test")), "$[?([email protected])]");
 }
 public void HasProperty()
 {
     Run(JsonPathWith.Array(jv => jv.HasProperty("test")), "$[?(@.test)]");
 }
 public void GroupedNot()
 {
     Run(JsonPathWith.Array(jv => !(jv.HasProperty("test") && jv.Name("name") == 5)), "$[?(!(@.test && @.name == 5))]");
 }