/// <summary> /// Invert the all of the paths in an expandToken, such that they are now in the same order as they are present in the /// base url /// </summary> /// <param name="treeToInvert">the tree to invert paths on</param> /// <returns>a new tree with all of its paths inverted</returns> public ExpandToken NormalizePaths(ExpandToken treeToInvert) { // iterate through each expand term token, and reverse the tree in its path property List <ExpandTermToken> updatedTerms = new List <ExpandTermToken>(); foreach (ExpandTermToken term in treeToInvert.ExpandTerms) { PathReverser pathReverser = new PathReverser(); PathSegmentToken reversedPath = term.PathToNavProp.Accept(pathReverser); // we also need to call the select token normalizer for this level to reverse the select paths SelectToken newSelectToken = term.SelectOption; if (term.SelectOption != null) { SelectTreeNormalizer selectTreeNormalizer = new SelectTreeNormalizer(); newSelectToken = selectTreeNormalizer.NormalizeSelectTree(term.SelectOption); } ExpandToken subExpandTree; if (term.ExpandOption != null) { subExpandTree = this.NormalizePaths(term.ExpandOption); } else { subExpandTree = null; } ExpandTermToken newTerm = new ExpandTermToken(reversedPath, term.FilterOption, term.OrderByOptions, term.TopOption, term.SkipOption, term.CountQueryOption, term.LevelsOption, term.SearchOption, newSelectToken, subExpandTree); updatedTerms.Add(newTerm); } return(new ExpandToken(updatedTerms)); }
/// <summary> /// Invert the all of the paths in an expandToken, such that they are now in the same order as they are present in the /// base url /// </summary> /// <param name="treeToInvert">the tree to invert paths on</param> /// <returns>a new tree with all of its paths inverted</returns> public ExpandToken NormalizePaths(ExpandToken treeToInvert) { // iterate through each expand term token, and reverse the tree in its path property List<ExpandTermToken> updatedTerms = new List<ExpandTermToken>(); foreach (ExpandTermToken term in treeToInvert.ExpandTerms) { PathReverser pathReverser = new PathReverser(); PathSegmentToken reversedPath = term.PathToNavProp.Accept(pathReverser); // we also need to call the select token normalizer for this level to reverse the select paths SelectToken newSelectToken = term.SelectOption; if (term.SelectOption != null) { SelectTreeNormalizer selectTreeNormalizer = new SelectTreeNormalizer(); newSelectToken = selectTreeNormalizer.NormalizeSelectTree(term.SelectOption); } ExpandToken subExpandTree; if (term.ExpandOption != null) { subExpandTree = this.NormalizePaths(term.ExpandOption); } else { subExpandTree = null; } ExpandTermToken newTerm = new ExpandTermToken(reversedPath, term.FilterOption, term.OrderByOptions, term.TopOption, term.SkipOption, term.CountQueryOption, term.LevelsOption, term.SearchOption, newSelectToken, subExpandTree); updatedTerms.Add(newTerm); } return new ExpandToken(updatedTerms); }
public void NormalizeTreeResultsInReversedPath() { // $select=1/2/3 NonSystemToken endPath = new NonSystemToken("3", null, new NonSystemToken("2", null, new NonSystemToken("1", null, null))); SelectToken selectToken = new SelectToken(new NonSystemToken[]{endPath}); SelectTreeNormalizer selectTreeNormalizer = new SelectTreeNormalizer(); SelectToken normalizedToken = selectTreeNormalizer.NormalizeSelectTree(selectToken); normalizedToken.Properties.Single().ShouldBeNonSystemToken("1") .And.NextToken.ShouldBeNonSystemToken("2") .And.NextToken.ShouldBeNonSystemToken("3"); }
public void NormalizeTreeWorksForMultipleTerms() { // $select=1/2/3,4/5/6 NonSystemToken endPath = new NonSystemToken("3", null, new NonSystemToken("2", null, new NonSystemToken("1", null, null))); NonSystemToken endPath1 = new NonSystemToken("6", null, new NonSystemToken("5", null, new NonSystemToken("4", null, null))); SelectToken selectToken = new SelectToken(new NonSystemToken[]{endPath, endPath1}); SelectTreeNormalizer selectTreeNormalizer = new SelectTreeNormalizer(); SelectToken normalizedToken = selectTreeNormalizer.NormalizeSelectTree(selectToken); List<PathSegmentToken> tokens = normalizedToken.Properties.ToList(); tokens.Should().HaveCount(2); tokens.ElementAt(0).ShouldBeNonSystemToken("1") .And.NextToken.ShouldBeNonSystemToken("2") .And.NextToken.ShouldBeNonSystemToken("3"); tokens.ElementAt(1).ShouldBeNonSystemToken("4") .And.NextToken.ShouldBeNonSystemToken("5") .And.NextToken.ShouldBeNonSystemToken("6"); }