public void Build_Builds()
        {
            var expected = new RelativeJsonPathExpression(new JsonPathElement[]
            {
                new JsonPathRecursiveDescentElement(new JsonPathPropertyElement("a")),
                new JsonPathAnyPropertyElement(),
                new JsonPathPropertyListElement(new [] { "b", "c" }),
                new JsonPathArrayIndexElement(42),
                new JsonPathAnyArrayIndexElement(),
                new JsonPathArrayIndexListElement(new [] { 7, 42 }),
                new JsonPathArraySliceElement(0, 42, 2),
                new JsonPathExpressionElement("@.length-1"),
                new JsonPathFilterExpressionElement("@.name = 'a'")
            });

            var actual = RelativeJsonPathExpressionBuilder.Create()
                         .RecursiveDescentTo().Property("a")
                         .AnyProperty()
                         .Properties("b", "c")
                         .ArrayIndex(42)
                         .AnyArrayIndex()
                         .ArrayIndexes(7, 42)
                         .ArraySlice(0, 42, 2)
                         .Expression("@.length-1")
                         .FilterExpression("@.name = 'a'")
                         .Build();

            actual.Should().BeEquivalentTo(expected);
        }
コード例 #2
0
        public void Constructor_RelativePath_Succeeds()
        {
            var elements = new JsonPathElement[] { new JsonPathPropertyElement("a") };

            var actual = new RelativeJsonPathExpression(elements);

            actual.Elements.Should().BeEquivalentTo(elements);
        }
コード例 #3
0
        public void ReplaceLastWith_WithRootElementInRelativePath_Throws()
        {
            var path = new RelativeJsonPathExpression(new JsonPathElement[] { new JsonPathPropertyElement("a") });

            Action action = () => path.ReplaceLastWith(new JsonPathRootElement());

            action.Should().Throw <ArgumentException>();
        }
コード例 #4
0
        public void Append_RelativeJsonPathExpression(string path, string relativePath, string expected)
        {
            var pathExpr         = new JsonPathExpression(path);
            var relativePathExpr = new RelativeJsonPathExpression(relativePath);
            var expectedExpr     = new JsonPathExpression(expected);

            var actual = pathExpr.Append(relativePathExpr);

            actual.Should().BeEquivalentTo(expectedExpr);
        }
コード例 #5
0
        public void Create_ReturnsObjectOfTheSameType()
        {
            var path = new RelativeJsonPathExpression(new JsonPathElement[]
            {
                new JsonPathPropertyElement("a")
            });
            var elements = new JsonPathElement[]
            {
                new JsonPathPropertyElement("a"),
                new JsonPathArrayIndexElement(42)
            };

            var actual = path.Create(elements);

            actual.Elements.Should().BeEquivalentTo(elements);
            actual.GetType().Should().Be <RelativeJsonPathExpression>();
        }