Example #1
0
        public void MatchShouldMatchAnyString()
        {
            NodeMatchResult result = this.node.Match(
                new StringSegment("/string/", 1, 7));

            Assert.That(result.Success, Is.True);
        }
Example #2
0
        public void MatchShouldIgnoreTheCaseWhenComparing()
        {
            NodeMatchResult result = this.node.Match(
                new StringSegment(LiteralString.ToUpperInvariant(), 0, LiteralString.Length));

            Assert.That(result.Success, Is.True);
        }
Example #3
0
        public void MatchShouldReturnSuccessIfTheLiteralIfTheSubstringMatchesTheLiteral()
        {
            NodeMatchResult result = this.node.Match(
                new StringSegment("ignore_" + LiteralString, "ignore_".Length, "ignore_".Length + LiteralString.Length));

            Assert.That(result.Success, Is.True);
        }
Example #4
0
        public void MatchShouldReturnUnsuccessfulIfTheLiteralIsNotAtTheSpecifiedLocation()
        {
            NodeMatchResult result = this.node.Match(
                new StringSegment("not_here_literal", 0, 16));

            Assert.That(result.Success, Is.False);
        }
Example #5
0
        public void MatchShouldSaveTheCapturedParameter()
        {
            NodeMatchResult result = this.node.Match(
                new StringSegment("01234", 2, 4));

            Assert.That(result.Name, Is.EqualTo(ParameterName));
            Assert.That(result.Value, Is.EqualTo("23"));
        }
Example #6
0
        public void ShouldCaptureTypesWithTypeConverters()
        {
            ParameterInfo capture = CreateParameter <CustomData>("capture");

            IMatchNode[]    nodes   = builder.Parse("/{capture}/", new[] { capture });
            StringSegment   segment = new StringSegment("custom_data", 0, 11);
            NodeMatchResult match   = nodes.Single().Match(segment);

            Assert.That(match.Success, Is.True);
            Assert.That(((CustomData)match.Value).Data, Is.EqualTo("custom_data"));
        }
Example #7
0
        public void ShouldReturnNodesThatMatchTheRoute()
        {
            ParameterInfo captureParameter = CreateParameter <string>("capture");

            IMatchNode[]    nodes    = this.builder.Parse("/literal/{capture}/", new[] { captureParameter });
            StringSegment[] segments = UrlParser.GetSegments("/literal/string_value").ToArray();

            NodeMatchResult literal = nodes[0].Match(segments[0]);
            NodeMatchResult capture = nodes[1].Match(segments[1]);

            Assert.That(nodes, Has.Length.EqualTo(2));
            Assert.That(literal.Success, Is.True);
            Assert.That(capture.Success, Is.True);
            Assert.That(capture.Value, Is.EqualTo("string_value"));
        }