public void GetNormalized_AppliedToNormalized_ReturnsSelf()
        {
            var element = new JsonPathRecursiveDescentElement(new JsonPathPropertyElement("name"));

            var actual = element.GetNormalized();

            actual.Should().Be(element);
        }
        public void As_RecursiveDescentAppliedToPropertyToArrayIndex_ReturnsNull()
        {
            JsonPathElement element = new JsonPathRecursiveDescentElement(ElementCreator.CreateAny(JsonPathElementType.Property));

            var actual = element.As <JsonPathArrayIndexElement>();

            actual.Should().BeNull();
        }
        public void CastTo_RecursiveDescentAppliedToPropertyToArrayIndex_Throws()
        {
            JsonPathElement element = new JsonPathRecursiveDescentElement(ElementCreator.CreateAny(JsonPathElementType.Property));

            Action action = () => element.CastTo <JsonPathArrayIndexElement>();

            action.Should().Throw <InvalidCastException>();
        }
        public void Matches_RecursiveDescent(string propertyName, string otherPropertyName, bool expected)
        {
            var element = new JsonPathRecursiveDescentElement(new JsonPathPropertyElement(propertyName));
            var other   = new JsonPathRecursiveDescentElement(new JsonPathPropertyElement(otherPropertyName));

            bool?actual = element.Matches(other);

            actual.Should().Be(expected);
        }
        public void GetNormalized_AppliedToNotNormalizedArraySlice_ReturnsAppliedToAnyArrayIndex()
        {
            var element  = new JsonPathRecursiveDescentElement(new JsonPathArraySliceElement(null, null));
            var expected = new JsonPathRecursiveDescentElement(new JsonPathAnyArrayIndexElement());

            var actual = element.GetNormalized();

            actual.Should().BeEquivalentTo(expected);
        }
        public void Matches_Any(JsonPathElementType type, bool?expected)
        {
            var element = new JsonPathRecursiveDescentElement(new JsonPathArrayIndexElement(0));
            var other   = ElementCreator.CreateAny(type);

            bool?actual = element.Matches(other);

            actual.Should().Be(expected);
        }
        public void GetUnderlyingElement_RecursiveDescentAppliedToProperty_ReturnsProperty()
        {
            var             property = ElementCreator.CreateAny(JsonPathElementType.Property);
            JsonPathElement element  = new JsonPathRecursiveDescentElement(property);

            var actual = element.GetUnderlyingElement();

            actual.Should().Be(property);
        }
        public void As_RecursiveDescentAppliedToPropertyToProperty_Casts()
        {
            var             property = ElementCreator.CreateAny(JsonPathElementType.Property);
            JsonPathElement element  = new JsonPathRecursiveDescentElement(property);

            var actual = element.As <JsonPathPropertyElement>();

            actual.Should().Be(property);
        }
Example #9
0
        private void AddElement(JsonPathElement element)
        {
            if (_isRecursiveDescent)
            {
                element = new JsonPathRecursiveDescentElement(element);
            }

            _elements.Add(element);
            _isRecursiveDescent = false;
        }
        public void IsNormalized_AppliedToNotNormalized_ReturnsFalse()
        {
            var element = new JsonPathRecursiveDescentElement(new JsonPathArraySliceElement(null, null));

            element.IsNormalized.Should().BeFalse();
        }
        public void IsNormalized_AppliedToNormalized_ReturnsTrue()
        {
            var element = new JsonPathRecursiveDescentElement(new JsonPathPropertyElement("name"));

            element.IsNormalized.Should().BeTrue();
        }
        public void IsStrict_ReturnsFalse()
        {
            var element = new JsonPathRecursiveDescentElement(new JsonPathPropertyElement("name"));

            element.IsStrict.Should().BeFalse();
        }
Example #13
0
 private static void AppendRecursiveDescent(this StringBuilder builder, JsonPathRecursiveDescentElement element)
 {
     builder.Append("..");
     builder.AppendElement(element.AppliedToElement, false);
 }