public static void AddRoute_AmbiguousRoute_FirstRouteIsChosen()
        {
            HttpRouteFactory routeFactory = new HttpRouteFactory("api");

            HttpRouteCollection routes = new HttpRouteCollection();
            var route1 = routeFactory.AddRoute("route1", "foo/bar/baz", null, routes);
            var route2 = routeFactory.AddRoute("route2", "foo/bar/baz", null, routes);

            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://host/api/foo/bar/baz");
            var routeData = routes.GetRouteData(request);

            Assert.Same(route1, routeData.Route);
        }
        public static void AddRoute_AppliesHttpMethodConstraint()
        {
            HttpRouteFactory routeFactory = new HttpRouteFactory("api");

            HttpRouteCollection routes = new HttpRouteCollection();
            var route1 = routeFactory.AddRoute("route1", "products/{category}/{id?}", new HttpMethod[] { HttpMethod.Get }, routes);
            var route2 = routeFactory.AddRoute("route2", "products/{category}/{id}", new HttpMethod[] { HttpMethod.Post }, routes);

            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://host/api/products/electronics/123");
            var routeData = routes.GetRouteData(request);

            Assert.Same(route1, routeData.Route);

            request   = new HttpRequestMessage(HttpMethod.Get, "http://host/api/products/electronics");
            routeData = routes.GetRouteData(request);
            Assert.Same(route1, routeData.Route);

            request   = new HttpRequestMessage(HttpMethod.Post, "http://host/api/products/electronics/123");
            routeData = routes.GetRouteData(request);
            Assert.Same(route2, routeData.Route);
        }
        public static void AddRoute_MethodsCollectionEmpty_AppliesHttpMethodConstraint()
        {
            HttpRouteFactory routeFactory = new HttpRouteFactory("api");

            HttpRouteCollection routes = new HttpRouteCollection();
            var route = routeFactory.AddRoute("route1", "products/{category}/{id?}", new HttpMethod[0], routes);

            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://host/api/products/electronics/123");
            var routeData = routes.GetRouteData(request);

            Assert.Null(routeData);

            request   = new HttpRequestMessage(HttpMethod.Post, "http://host/api/products/electronics/123");
            routeData = routes.GetRouteData(request);
            Assert.Null(routeData);
        }
        internal void InitializeHttpFunctions(Collection <FunctionDescriptor> functions)
        {
            // we must initialize the route factory here AFTER full configuration
            // has been resolved so we apply any route prefix customizations
            HttpRouteFactory httpRouteFactory = new HttpRouteFactory(_config.HttpRoutePrefix);

            _httpFunctions = new Dictionary <IHttpRoute, FunctionDescriptor>();
            _httpRoutes    = new HttpRouteCollection();

            foreach (var function in functions)
            {
                var httpTriggerBinding = function.Metadata.InputBindings.OfType <HttpTriggerBindingMetadata>().SingleOrDefault();
                if (httpTriggerBinding != null)
                {
                    var httpRoute = httpRouteFactory.AddRoute(function.Metadata.Name, httpTriggerBinding.Route, httpTriggerBinding.Methods, _httpRoutes);
                    _httpFunctions.Add(httpRoute, function);
                }
            }
        }