Esempio n. 1
0
        public void Execute_Example_RowCount(string from, int rowCount)
        {
            var selects = new List <ElementSelect>()
            {
                new ElementSelect(new LiteralScalarResolver <string>("$"))
            };

            using (var reader = GetResourceReader("PurchaseOrders"))
            {
                var engine = new JsonPathEngine(new LiteralScalarResolver <string>(from), selects);
                var result = engine.Execute(reader);
                Assert.That(result.Count, Is.EqualTo(rowCount));
            }
        }
Esempio n. 2
0
        public void Execute_FromElement_ValueCorrect()
        {
            var from    = "$.PurchaseOrders[*].Items[*].ProductName";
            var selects = new List <ElementSelect>()
            {
                new ElementSelect(new LiteralScalarResolver <string>("$"))
            };

            using (var reader = GetResourceReader("PurchaseOrders"))
            {
                var engine = new JsonPathEngine(new LiteralScalarResolver <string>(from), selects);
                var result = engine.Execute(reader);
                Assert.That((result.ElementAt(0) as IEnumerable <object>).ElementAt(0), Is.EqualTo("Lawnmower"));
            }
        }
Esempio n. 3
0
        public void Execute_MissingElement_Null()
        {
            var from    = "$.PurchaseOrders[*]";
            var selects = new List <ElementSelect>()
            {
                new ElementSelect(new LiteralScalarResolver <string>("$.PurchaseOrderNumber"))
            };

            using (var reader = GetResourceReader("PurchaseOrders"))
            {
                var engine = new JsonPathEngine(new LiteralScalarResolver <string>(from), selects);
                var result = engine.Execute(reader);
                Assert.That((result.ElementAt(3) as IEnumerable <object>).ElementAt(0), Is.EqualTo("(null)"));
            }
        }
Esempio n. 4
0
        public void Execute_Example_FirstColumnIsCorrect()
        {
            var from    = "$.PurchaseOrders[*].Items[*]";
            var selects = new List <ElementSelect>()
            {
                new ElementSelect(new LiteralScalarResolver <string>("PartNumber"))
            };

            using (var reader = GetResourceReader("PurchaseOrders"))
            {
                var engine = new JsonPathEngine(new LiteralScalarResolver <string>(from), selects);
                var result = engine.Execute(reader);
                Assert.That(result.Count, Is.EqualTo(5));
                Assert.That(result.Select(x => ((x as IEnumerable <object>).ElementAt(0) as string).Length), Is.All.EqualTo(6)); //Format is 123-XY
            }
        }
Esempio n. 5
0
        public void Execute_ParentElementGoingAboveRoot_ValueCorrect()
        {
            var from    = "$.PurchaseOrders[*].Items[*]";
            var selects = new List <ElementSelect>()
            {
                new ElementSelect(new LiteralScalarResolver <string>("!!!!!!.PurchaseOrderNumber")),
                new ElementSelect(new LiteralScalarResolver <string>("$.PartNumber"))
            };

            using (var reader = GetResourceReader("PurchaseOrders"))
            {
                var engine = new JsonPathEngine(new LiteralScalarResolver <string>(from), selects);
                var result = engine.Execute(reader);
                Assert.That((result.ElementAt(0) as IEnumerable <object>).ElementAt(0), Does.Contain("(null)"));
                Assert.That((result.ElementAt(0) as IEnumerable <object>).ElementAt(1), Does.Contain("872-AA"));

                Assert.That((result.ElementAt(1) as IEnumerable <object>).ElementAt(0), Does.Contain("(null)"));
                Assert.That((result.ElementAt(1) as IEnumerable <object>).ElementAt(1), Does.Contain("926-AA"));

                Assert.That((result.ElementAt(2) as IEnumerable <object>).ElementAt(0), Does.Contain("(null)"));
                Assert.That((result.ElementAt(2) as IEnumerable <object>).ElementAt(1), Does.Contain("456-NM"));
            }
        }