public void TestExpectedBehavior()
        {
            var tokenizer = new RouteTokenizer();
            var route = "/the/path/{to}/*/{glory}";

            var token = tokenizer.Tokenize(route);

            int i = 0;

            Assert.IsInstanceOf<SeparatorToken>(token[i++]);      // /
            Assert.AreEqual("the", ((NameToken)token[i]).Name);
            Assert.IsInstanceOf<NameToken>(token[i++]);           // the
            Assert.IsInstanceOf<SeparatorToken>(token[i++]);      // /
            Assert.AreEqual("path", ((NameToken)token[i]).Name);
            Assert.IsInstanceOf<NameToken>(token[i++]);           // path
            Assert.IsInstanceOf<SeparatorToken>(token[i++]);      // /
            Assert.IsInstanceOf<StartParameterToken>(token[i++]); // {
            Assert.AreEqual("to", ((NameToken)token[i]).Name);
            Assert.IsInstanceOf<NameToken>(token[i++]);           // to
            Assert.IsInstanceOf<EndParameterToken>(token[i++]);   // }
            Assert.IsInstanceOf<SeparatorToken>(token[i++]);      // /
            Assert.IsInstanceOf<WildcardToken>(token[i++]);       // *
            Assert.IsInstanceOf<SeparatorToken>(token[i++]);      // /
            Assert.IsInstanceOf<StartParameterToken>(token[i++]); // {
            Assert.AreEqual("glory", ((NameToken)token[i]).Name);
            Assert.IsInstanceOf<NameToken>(token[i++]);           // glory
            Assert.IsInstanceOf<EndParameterToken>(token[i++]);   // }
            Assert.AreEqual(i, token.Length);
        }
Esempio n. 2
0
        public void TestExpectedBehavior()
        {
            var tokenizer = new RouteTokenizer();
            var parser = new RouteParser();

            var route = "/the/path/{to}/*/{glory}";
            var token = tokenizer.Tokenize(route);

            var routeInformation = parser.Parse(route, token);

            Assert.AreEqual(2, routeInformation.Parameter.Length);

            Assert.AreEqual("to", routeInformation.Parameter[0]);
            Assert.AreEqual("glory", routeInformation.Parameter[1]);

            Assert.AreEqual("the", routeInformation.Segments[0].Name);
            Assert.AreEqual(RouteSegmentType.Static, routeInformation.Segments[0].Type);
            Assert.AreEqual("path", routeInformation.Segments[1].Name);
            Assert.AreEqual(RouteSegmentType.Static, routeInformation.Segments[1].Type);
            Assert.AreEqual("to", routeInformation.Segments[2].Name);
            Assert.AreEqual(RouteSegmentType.Parameter, routeInformation.Segments[2].Type);
            Assert.AreEqual("*", routeInformation.Segments[3].Name);
            Assert.AreEqual(RouteSegmentType.Wildcard, routeInformation.Segments[3].Type);
            Assert.AreEqual("glory", routeInformation.Segments[4].Name);
            Assert.AreEqual(RouteSegmentType.Parameter, routeInformation.Segments[4].Type);
        }
        public void TestUnsupportedCharacter()
        {
            var tokenizer = new RouteTokenizer();
            var route = "/test/.";

            var exception = Assert.Throws<RouteParsingException>(() => {
                tokenizer.Tokenize(route);
            });

            Assert.AreEqual(6, exception.Position);
        }
        public void TestEmptyString()
        {
            var tokenizer = new RouteTokenizer();
            var route = "";

            var exception = Assert.Throws<RouteParsingException>(() => {
                tokenizer.Tokenize(route);
            });

            Assert.AreEqual(0, exception.Position);
        }
Esempio n. 5
0
        public void TestSlashInParameter()
        {
            var tokenizer = new RouteTokenizer();
            var parser = new RouteParser();

            var route = "/malformed/{rou/te}";
            var token = tokenizer.Tokenize(route);

            Assert.Throws<RouteParsingException>(() => {
                parser.Parse(route, token);
            });
        }
        public void TestMultipleRuns()
        {
            var tokenizer = new RouteTokenizer();

            var routes = new string[] {
                "/the/path/{to}/*/{glory}",
                "/pizza/is/{delicious}",
                "non/absolute/route",
                "/*/*/*/*/*/",
            };

            for (int i = 0; i < routes.Length * 4; i++)
            {
                tokenizer.Tokenize(routes[i % routes.Length]);
            }
        }
        public void TestWhitespaces()
        {
            var tokenizer = new RouteTokenizer();
            var route = "/a/ /b/";

            var exception = Assert.Throws<RouteParsingException>(() => {
                tokenizer.Tokenize(route);
            });

            Assert.AreEqual(3, exception.Position);
        }