Example #1
0
        public void JObject_GetAllIndexes_Test()
        {
            var path = new JObjectPath(x => x["field"]["other"]);

            var obj = JObject.FromObject(new { field = new { other = 1 } });

            var indexes = path.GetAllIndexes(obj).ToList();

            indexes.Should().HaveCount(1);
            ((string)indexes[0][0]).Should().Be("field");
            ((string)indexes[0][1]).Should().Be("other");
        }
Example #2
0
        public void JObject_GetAllIndexes_WithArr_Test2()
        {
            var path = new JObjectPath(x => x["field"].ScanArr["other"]);

            var obj = JObject.FromObject(new { field = new[] { new { other = 1 }, new { other = 2 } } });

            var indexes = path.GetAllIndexes(obj).ToList();

            indexes.Should().HaveCount(2);

            ((string)indexes[0][0]).Should().Be("field");
            ((int)indexes[0][1]).Should().Be(0);
            ((string)indexes[0][2]).Should().Be("other");

            ((string)indexes[1][0]).Should().Be("field");
            ((int)indexes[1][1]).Should().Be(1);
            ((string)indexes[1][2]).Should().Be("other");
        }
Example #3
0
        public void JObject_GetAllIndexes_ToJObject_Test()
        {
            var path = new JObjectPath(x => x["field"]["other"]);

            var obj = JObject.FromObject(new { field = new { other = new { other1 = 1 } } });

            var indexes = path.GetAllIndexes(obj).ToList();

            indexes.Should().HaveCount(1);
            ((string)indexes[0][0]).Should().Be("field");
            ((string)indexes[0][1]).Should().Be("other");

            var part = path.Get(obj, indexes[0]);

            part.Should().BeOfType <JObject>();
            var objPart = (JObject)part;

            ((int)objPart["other1"]).Should().Be(1);
        }