/// <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 ReversePathWorksWithSingleSegment() { // $expand=1 PathReverser pathReverser = new PathReverser(); PathSegmentToken nonReversedPath = new NonSystemToken("1", null, null); PathSegmentToken reversedPath = nonReversedPath.Accept(pathReverser); reversedPath.ShouldBeNonSystemToken("1").And.NextToken.Should().BeNull(); }
public void ReversePathWorksWithATypeToken() { // $expand=Fully.Qualified.Namespace/1 PathReverser pathReverser = new PathReverser(); PathSegmentToken nonReversedPath = new NonSystemToken("1", null, new NonSystemToken("Fully.Qualified.Namespace", null, null)); PathSegmentToken reversedPath = nonReversedPath.Accept(pathReverser); reversedPath.ShouldBeNonSystemToken("Fully.Qualified.Namespace").And.NextToken.ShouldBeNonSystemToken("1"); }
public void ReversePathWorksWithStarToken() { // $expand=1/* PathReverser pathReverser = new PathReverser(); PathSegmentToken nonReversedPath = new NonSystemToken("*", null, new NonSystemToken("1", null, null)); PathSegmentToken reversedPath = nonReversedPath.Accept(pathReverser); reversedPath.ShouldBeNonSystemToken("1").And.NextToken.ShouldBeNonSystemToken("*"); }
public void ReversePathWorksWithSingleSegment() { // $expand=1 PathReverser pathReverser = new PathReverser(); PathSegmentToken nonReversedPath = new NonSystemToken("1", null, null); PathSegmentToken reversedPath = nonReversedPath.Accept(pathReverser); reversedPath.ShouldBeNonSystemToken("1").NextToken.Should().BeNull(); }
public void ReversePathWorksWithATypeToken() { // $expand=Fully.Qualified.Namespace/1 PathReverser pathReverser = new PathReverser(); PathSegmentToken nonReversedPath = new NonSystemToken("1", null, new NonSystemToken("Fully.Qualified.Namespace", null, null)); PathSegmentToken reversedPath = nonReversedPath.Accept(pathReverser); reversedPath.ShouldBeNonSystemToken("Fully.Qualified.Namespace").NextToken.ShouldBeNonSystemToken("1"); }
public void ReversePathWorksWithStarToken() { // $expand=1/* PathReverser pathReverser = new PathReverser(); PathSegmentToken nonReversedPath = new NonSystemToken("*", null, new NonSystemToken("1", null, null)); PathSegmentToken reversedPath = nonReversedPath.Accept(pathReverser); reversedPath.ShouldBeNonSystemToken("1").NextToken.ShouldBeNonSystemToken("*"); }
/// <summary> /// Normalize a SelectToken into something that can be used to trim an expand tree. /// </summary> /// <param name="treeToNormalize">The select token to normalize</param> /// <returns>Normalized SelectToken</returns> public SelectToken NormalizeSelectTree(SelectToken treeToNormalize) { PathReverser pathReverser = new PathReverser(); List<PathSegmentToken> invertedPaths = (from property in treeToNormalize.Properties select property.Accept(pathReverser)).ToList(); // to normalize a select token we just need to invert its paths, so that // we match the ordering on an ExpandToken. return new SelectToken(invertedPaths); }
public void ReversePathWorksWithDeepPath() { // $expand=1/2/3/4 PathReverser pathReverser = new PathReverser(); NonSystemToken endPath = new NonSystemToken("4", null, new NonSystemToken("3", null, new NonSystemToken("2", null, new NonSystemToken("1", null, null)))); PathSegmentToken reversedPath = endPath.Accept(pathReverser); reversedPath.ShouldBeNonSystemToken("1") .And.NextToken.ShouldBeNonSystemToken("2") .And.NextToken.ShouldBeNonSystemToken("3") .And.NextToken.ShouldBeNonSystemToken("4"); }
public void ReversePathWorksWithDeepPath() { // $expand=1/2/3/4 PathReverser pathReverser = new PathReverser(); NonSystemToken endPath = new NonSystemToken("4", null, new NonSystemToken("3", null, new NonSystemToken("2", null, new NonSystemToken("1", null, null)))); PathSegmentToken reversedPath = endPath.Accept(pathReverser); reversedPath.ShouldBeNonSystemToken("1") .NextToken.ShouldBeNonSystemToken("2") .NextToken.ShouldBeNonSystemToken("3") .NextToken.ShouldBeNonSystemToken("4"); }
/// <summary> /// Build the next level PathReverser /// </summary> /// <param name="nextLevelToken">the next level token</param> /// <param name="nextChildToken">the next levels child token</param> /// <returns>the path token from the next level.</returns> private static PathSegmentToken BuildNextStep(PathSegmentToken nextLevelToken, PathSegmentToken nextChildToken) { PathReverser nextStepReverser = new PathReverser(nextChildToken); return(nextLevelToken.Accept(nextStepReverser)); }