private UrlSegment(Route route, string[] pathSegments, int pathSegmentIndex, UrlSegment parent, RouteMatchTree tree = null) { if (route == null) { throw new ArgumentNullException(nameof(route)); } tree = tree ?? (parent != null ? parent.tree : null); if (tree == null) { throw new ArgumentNullException(nameof(tree)); } if (parent != null && route.Parent != parent.Route) { throw new ArgumentException( "match child-parent relation must be same equivalent to route child-parent relation"); } this.tree = tree; Route = route; this.pathSegments = pathSegments; this.pathSegmentIndex = pathSegmentIndex; Parent = parent; }
public RouteMatchTree Resolve(IPomonaSession session, string path) { if (session == null) throw new ArgumentNullException(nameof(session)); if (path == null) throw new ArgumentNullException(nameof(path)); var match = new RouteMatchTree(this.rootRoute, path, session); return match.MatchCount > 0 ? match : null; }
public RouteMatchTree Resolve(IPomonaSession session, string path) { if (session == null) { throw new ArgumentNullException(nameof(session)); } if (path == null) { throw new ArgumentNullException(nameof(path)); } var match = new RouteMatchTree(this.rootRoute, path, session); return(match.MatchCount > 0 ? match : null); }
MatchChildren_FromRootRoute_IsSuccessful() { // Route might be dependant on parent node, for example: PigTail GetTail(Pig pig) // ..or it might not be: PigTail GetTail(int peonId, int animalId) <-- We need to make sure animal is of type Pig before invoking Route // WHEN ROUTE IS AMBIGUOUS BY TYPE, WE ALWAYS NEED TO FETCH THE LAST SINGLE-RESOURCE NODE, OR AT LEAST DETERMINE TYPE var tm = new TypeMapper(new Config()); var root = new RootRoute((ResourceType)tm.FromType<Root>()); var allNodes = root.WrapAsEnumerable<Route>().Flatten(x => x.Children).ToList(); RouteMatchTree routeMatchTree = new RouteMatchTree(root, "peons/fillifjonka/animals/1234/tail/end", Substitute.For<IPomonaSession>()); routeMatchTree.Leafs.ForEach(Console.WriteLine); var match1 = routeMatchTree.Root; Assert.That(match1.SelectedFinalMatch, Is.Null); var fork = match1.NextFork(); fork.SelectedChild = fork.Children.First(); Console.WriteLine(match1.SelectedFinalMatch); Console.WriteLine(match1); }
internal UrlSegment(Route route, string[] pathSegments, RouteMatchTree tree) : this(route, pathSegments, -1, null, tree) { }