Ejemplo n.º 1
0
        public UriRoute(Uri baseUri, string template = null, Verb verbs = Verb.All, Func<IOwinContext, bool> filter = null)
        {
            Contract.Assert(baseUri != null);
            BaseUri = baseUri;
            Template = template ?? baseUri.PathAndQuery;
            Verbs = verbs;

            if (template == null)
            {
                Template = baseUri.PathAndQuery;
            }
            else
            {
                if (template.StartsWith("/") || !baseUri.PathAndQuery.EndsWith("/"))
                {
                    Template = template;
                }
                else
                {
                    Template = baseUri.PathAndQuery + template;
                }
            }

            Mapper = new UriRouteMapper(this, filter);
        }
Ejemplo n.º 2
0
        public void Parse_NoParams(string uriString, string template)
        {
            var uri = new Uri(uriString);
            var route = new UriRoute(new Uri(uri.Scheme + Uri.SchemeDelimiter + uri.Host + (uri.Port > 0 ? (":" + uri.Port) : null)), template);
            var parser = new UriRouteMapper(route);

            Assert.That(parser.CanMap(uri));

            var parameters = parser.Parse(uri);
        }
Ejemplo n.º 3
0
        public void ParseWildCards()
        {
            var uri = new Uri("http://hosty/wild/man");
            var template = "/*/man";
            var route = new UriRoute(new Uri(uri.Scheme + Uri.SchemeDelimiter + uri.Host + (uri.Port > 0 ? (":" + uri.Port) : null)), template);
            var parser = new UriRouteMapper(route);

            Assert.That(parser.CanMap(uri));

            var parameters = parser.Parse(uri);

            Assert.That(parameters["wild"] == "wild");
        }