/// <summary> /// Adds the specified node to this instance. /// </summary> /// <param name="nodes">The nodes to add.</param> /// <param name="index">The starting index of the first node to add.</param> /// <param name="value">The value to associate with the route.</param> public void Add(IReadOnlyList <IMatchNode> nodes, int index, T value) { IMatchNode matcher = nodes[index]; RouteNode <T> node = null; if (this.children != null) { node = this.children.FirstOrDefault(n => n.matcher.Equals(matcher)); } if (node == null) { node = new RouteNode <T>(matcher); this.AddChild(node); } index++; if (index == nodes.Count) { node.Value = value; } else { node.Add(nodes, index, value); } }
/// <inheritdoc /> public bool Equals(IMatchNode other) { var node = other as GenericCaptureNode; if (node == null) { return(false); } return(string.Equals(this.property, node.property, StringComparison.Ordinal) && (this.converter.GetType() == node.converter.GetType())); }
public void MatchShouldInvokeHigherPriorityNodesFirst() { this.matcher.Priority.Returns(100); IMatchNode important = Substitute.For <IMatchNode>(); important.Priority.Returns(200); important.Match(default(StringSegment)) .ReturnsForAnyArgs(new NodeMatchResult(null, null)); this.node.Add(new[] { important }, 0, null); this.node.Match("/route"); important.ReceivedWithAnyArgs().Match(default(StringSegment)); this.matcher.DidNotReceiveWithAnyArgs().Match(default(StringSegment)); }
public void AddShouldCombineMatchers() { // We need the child node so we can insert the value somewhere, // otherwise it will try to overwrite the value in this.matcher, // which isn't allowed IMatchNode duplicate = Substitute.For <IMatchNode>(); IMatchNode child = Substitute.For <IMatchNode>(); this.matcher.Equals(duplicate).Returns(true); this.node.Add(new[] { duplicate, child }, 0, null); this.node.Match("/route"); this.matcher.ReceivedWithAnyArgs().Match(default(StringSegment)); duplicate.DidNotReceiveWithAnyArgs().Match(default(StringSegment)); }
private static void AppendNodeString(StringBuilder buffer, IMatchNode node) { var literal = node as LiteralNode; if (literal != null) { buffer.Append(literal.Literal); } else { // We allow multiple captures as long as they don't have the // same priority (i.e. {100} and {200} are OK as we'll try to // match the 200 first) buffer.Append('{') .Append(node.Priority) .Append('}'); } }
public void EqualsShouldReturnFalseForNonStringCaptureNodes() { IMatchNode other = Substitute.For <IMatchNode>(); Assert.That(this.node.Equals(other), Is.False); }
/// <inheritdoc /> public bool Equals(IMatchNode other) { var node = other as StringCaptureNode; return(string.Equals(this.property, node?.property, StringComparison.Ordinal)); }
/// <inheritdoc /> public bool Equals(IMatchNode other) { var node = other as LiteralNode; return(string.Equals(this.Literal, node?.Literal, StringComparison.OrdinalIgnoreCase)); }
public void SetUp() { this.matcher = Substitute.For <IMatchNode>(); this.node = new RouteNode <string>(null); this.node.Add(new[] { this.matcher }, 0, MatcherValue); }
/// <summary> /// Initializes a new instance of the <see cref="RouteNode{T}"/> class. /// </summary> /// <param name="matcher">Used to match the part of the route.</param> public RouteNode(IMatchNode matcher) { this.matcher = matcher; }