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"); }
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"); }
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"); }
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"); }
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); }