IPath BuildPath(Stack <Tuple <JProperty, bool> > propertyStack, JProperty jProperty, JToken root) { var path = new JsonPath(); path.ActualPath = string.Join(JsonPath.SeperatorSymbol, propertyStack.Reverse().Select(p => path.CreatePathSegment(p.Item1).ToString(p.Item2))); var displayPathSegments = propertyStack.Reverse() .Select(p => new Tuple <IPathSegment, bool>(path.CreatePathSegment(p.Item1), p.Item2)) .ToList(); var recordsetEncountered = false; for (int i = displayPathSegments.Count - 1; i >= 0; i--) { var pathSegment = displayPathSegments[i]; if (recordsetEncountered) { pathSegment.Item1.IsEnumarable = false; } if (pathSegment.Item1.IsEnumarable && pathSegment.Item2) { recordsetEncountered = true; } } path.DisplayPath = string.Join(JsonPath.SeperatorSymbol, displayPathSegments.Select(p => p.Item1.ToString(p.Item2))); if (path.ActualPath != string.Empty) { path.ActualPath += JsonPath.SeperatorSymbol; } if (path.DisplayPath != string.Empty) { path.DisplayPath += JsonPath.SeperatorSymbol; } path.ActualPath += path.CreatePathSegment(jProperty); path.DisplayPath += path.CreatePathSegment(jProperty); path.SampleData += GetSampleData(root, path); return(path); }
public void ToStringOnEnumerableSegment_WhereEnumerablesAreConsidered_Expected_ScalarFormat() { JsonPath path = new JsonPath(); IPathSegment segment = path.CreatePathSegment("Collection()"); const string expected = "Collection()"; string actual = segment.ToString(true); Assert.AreEqual(expected, actual); }
public void ToStringOnScalarSegment_Expected_ScalarFormat() { JsonPath path = new JsonPath(); IPathSegment segment = path.CreatePathSegment("Name"); const string expected = "Name"; string actual = segment.ToString(); Assert.AreEqual(expected, actual); }
public void CreateScalarPathSegmentFromJProperty_Expected_ScalarJsonPathSegment() { JProperty jProperty = new JProperty("ScalarProperty", "ScalarValue"); JsonPath path = new JsonPath(); IPathSegment segment = path.CreatePathSegment(jProperty); bool expected = false; bool actual = segment.IsEnumarable; Assert.AreEqual(expected, actual); }
public void CreateEnumerablePathSegmentFromJProperty_Expected_EnumerableJsonPathSegment() { JProperty jProperty = new JProperty("EnumerableProperty", new JArray( new JObject(new JProperty("ScalarProperty", "ScalarValue"), new JProperty("ScalarProperty1", "ScalarValue1")))); JsonPath path = new JsonPath(); IPathSegment segment = path.CreatePathSegment(jProperty); bool expected = true; bool actual = segment.IsEnumarable; Assert.AreEqual(expected, actual); }
private IPath BuildPath(Stack<Tuple<JProperty, bool>> propertyStack, JProperty jProperty, JToken root) { var path = new JsonPath(); path.ActualPath = string.Join(JsonPath.SeperatorSymbol, propertyStack.Reverse().Select(p => path.CreatePathSegment(p.Item1).ToString(p.Item2))); List<Tuple<IPathSegment, bool>> displayPathSegments = propertyStack.Reverse() .Select(p => new Tuple<IPathSegment, bool>(path.CreatePathSegment(p.Item1), p.Item2)) .ToList(); bool recordsetEncountered = false; for (int i = displayPathSegments.Count - 1; i >= 0; i--) { Tuple<IPathSegment, bool> pathSegment = displayPathSegments[i]; if (recordsetEncountered) { pathSegment.Item1.IsEnumarable = false; } if (pathSegment.Item1.IsEnumarable && pathSegment.Item2) recordsetEncountered = true; } path.DisplayPath = string.Join(JsonPath.SeperatorSymbol, displayPathSegments.Select(p => p.Item1.ToString(p.Item2))); if (path.ActualPath != string.Empty) { path.ActualPath += JsonPath.SeperatorSymbol; } if (path.DisplayPath != string.Empty) { path.DisplayPath += JsonPath.SeperatorSymbol; } path.ActualPath += path.CreatePathSegment(jProperty).ToString(); path.DisplayPath += path.CreatePathSegment(jProperty).ToString(); path.SampleData += GetSampleData(root, path); return path; }
public void CreateEnumerablePathSegmentFromSegmentText_Expected_EnumerableJsonPathSegment() { JsonPath path = new JsonPath(); IPathSegment segment = path.CreatePathSegment("EnumerableData()"); bool expected = true; bool actual = segment.IsEnumarable; Assert.AreEqual(expected, actual); }
public void CreateScalarPathSegmentFromSegmentText_Expected_ScalarJsonPathSegment() { JsonPath path = new JsonPath(); IPathSegment segment = path.CreatePathSegment("Name"); bool expected = false; bool actual = segment.IsEnumarable; Assert.AreEqual(expected, actual); }