Exemplo n.º 1
0
        public void KeySetMatcher()
        {
            var keySetMatcher = PathMatchers.KeySet("foo", "bar");

            new List <MatchResult>
            {
                keySetMatcher(new KeySet("foo", "bar")),
                keySetMatcher(new KeySet("foo")),
                keySetMatcher(new KeySet("bar")),
                keySetMatcher("foo"),
                keySetMatcher("bar")
            }.ForEach(test => Assert.True(test.IsMatched));
        }
Exemplo n.º 2
0
 public void RouteParsing()
 {
     new List <RouteParsingTest>
     {
         Route("foo").ShouldBehaveLike(PathMatchers.StringKey("foo")).ShouldMatch("foo").ShouldFail("bar"),
         Route("foo.bar[{ranges:baz}]")
         .ShouldBehaveLike(PathMatchers.StringKey("foo"), PathMatchers.StringKey("bar"),
                           PathMatchers.RangesPattern("baz"))
         .ShouldMatch("foo", "bar", new NumberRange(0, 1))
         .ShouldFail("bar"),
         Route("foo.bar[{keys}]")
         .ShouldBehaveLike(PathMatchers.StringKey("foo"), PathMatchers.StringKey("bar"),
                           PathMatchers.KeysPattern("any"))
         .ShouldMatch("foo", "bar", new KeySet("baz"))
         .ShouldFail("bar"),
         Route("foo.bar['baz', 'howdy']")
         .ShouldBehaveLike(PathMatchers.StringKey("foo"), PathMatchers.StringKey("bar"),
                           PathMatchers.KeySet("baz", "howdy"))
         .ShouldMatch("foo", "bar", "baz")
         .ShouldMatch("foo", "bar", "howdy")
         .ShouldFail("bar"),
         Route("foo.bar[{integers}].baz")
         .ShouldBehaveLike(PathMatchers.StringKey("foo"), PathMatchers.StringKey("bar"),
                           PathMatchers.IntegersPattern(), PathMatchers.StringKey("baz"))
         .ShouldMatch("foo", "bar", new NumericSet(1, 2, 3), "baz")
         .ShouldMatch("foo", "bar", 1, "baz")
         .ShouldFail("bar"),
         Route("foo.bar[{integers:ids}]['baz','texas']")
         .ShouldBehaveLike(PathMatchers.StringKey("foo"), PathMatchers.StringKey("bar"),
                           PathMatchers.IntegersPattern("ids"), PathMatchers.KeySet("baz", "texas"))
         .ShouldMatch("foo", "bar", 1, "baz")
         .ShouldMatch("foo", "bar", 1, "texas")
         .ShouldFail("bar")
     }
     .ForEach(test =>
     {
         "".x(() =>
         {
             var output = PathGrammar.RouteMatcher.Parse(test.RoutePath).ToList();
             foreach (var testPath in test.PathTests)
             {
                 var outputResult   = IsMatch(output, testPath.Path);
                 var expectedResult = IsMatch(test.ExpectedMatchers, testPath.Path);
                 Assert.True(outputResult == expectedResult);
                 Assert.True(outputResult == testPath.ShouldMatch);
             }
         });
     });
 }