예제 #1
0
        public void JObjectGetValue_WithArray_Test()
        {
            var path = new JObjectPath(x => x["field"].ScanArr);

            var obj = JObject.FromObject(new { field = new[] { "name", "name1" } });

            path.Get(obj, new object[] { "field", 0 }).Should().Be("name");
            path.Get(obj, new object[] { "field", 1 }).Should().Be("name1");
        }
예제 #2
0
        public void JObjectPath_GetValue_Test()
        {
            var path = new JObjectPath(x => x["field"]);

            var obj = JObject.FromObject(new { field = "name" });

            path.Get(obj, new[] { "field" }).Should().Be("name");
        }
예제 #3
0
        public void JObjectPath_GetObject_Test()
        {
            var path = new JObjectPath(x => x["field"]);

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

            var res = (JObject)path.Get(obj, new[] { "field" });

            ((string)res["other"]).Should().Be("name");
        }
예제 #4
0
        public void JObjectPath_GetArray_Test()
        {
            var path = new JObjectPath(x => x["field"]);

            var obj = JObject.FromObject(new { field = new[] { "name" } });

            var res = (object[])path.Get(obj, new[] { "field" });

            res.Should().HaveCount(1);
            res[0].Should().Be("name");
        }
예제 #5
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);
        }