示例#1
0
        public void Add_WithHostedHttpRoute_RegistersInnerRouteWithAspNetRouteCollection()
        {
            var route = new HostedHttpRoute("uri", null, null, null, null);

            _webApiRoutes.Add("name", route);

            var httpWebRoute = Assert.IsType <HttpWebRoute>(_aspNetRoutes["name"]);

            Assert.Same(route.OriginalRoute, httpWebRoute);
            Assert.Same(route, httpWebRoute.HttpRoute);
        }
        public void CustomHttpRouteGetVitualPathRunsCustomHttpRoute()
        {
            // Arrange
            DomainHttpRoute route = new DomainHttpRoute(
                "myDomain",
                "api/{controller}/{action}",
                new { controller = "SomeValue", action = "SomeAction" }
                );
            HostedHttpRouteCollection collection = new HostedHttpRouteCollection(
                new RouteCollection()
                );

            collection.Add("domainRoute", route);
            HttpRequestMessage       request     = CreateHttpRequestMessageWithContext();
            HttpRouteValueDictionary routeValues = new HttpRouteValueDictionary()
            {
                { "controller", "controllerName" },
                { "action", "actionName" },
                { "httproute", true }
            };

            request.SetRouteData(new HttpRouteData(route, routeValues));

            // Act
            IHttpVirtualPathData httpvPathData = collection.GetVirtualPath(
                request,
                "domainRoute",
                routeValues
                );

            // Assert
            Assert.NotNull(httpvPathData);
            Assert.Equal("/api/controllerName/actionNameFromDomain", httpvPathData.VirtualPath);
        }
        public void ConvertHttpRouteDataToRouteDataRunsCustomHttpRoute()
        {
            // Arrange
            DomainHttpRoute route = new DomainHttpRoute(
                "myDomain",
                "api/{controller}/{action}",
                new { controller = "Values", action = "GetTenant" }
                );
            HostedHttpRouteCollection collection = new HostedHttpRouteCollection(
                new RouteCollection()
                );

            collection.Add("domainRoute", route);
            HttpRequestMessage request       = CreateHttpRequestMessageWithContext();
            IHttpRouteData     httpRouteData = collection.GetRouteData(request);

            // Act
            RouteData routeData = httpRouteData.ToRouteData();

            // Assert
            Assert.NotNull(routeData.Values);
            Assert.Equal(3, routeData.Values.Count);
            Assert.Equal("controllerName", routeData.Values["controller"]);
            Assert.Equal("actionName", routeData.Values["action"]);
            Assert.Equal("myDomain", routeData.Values["domain"]);
        }
        public void CustomHttpRouteGetVitualPathRunsCustomHttpRoute()
        {
            // Arrange
            DomainHttpRoute route = new DomainHttpRoute("myDomain", "api/{controller}/{action}", new { controller = "SomeValue", action = "SomeAction" });
            HostedHttpRouteCollection collection = new HostedHttpRouteCollection(new RouteCollection());
            collection.Add("domainRoute", route);
            HttpRequestMessage request = CreateHttpRequestMessageWithContext();
            HttpRouteValueDictionary routeValues = new HttpRouteValueDictionary()
                {
                    {"controller", "controllerName"},
                    {"action", "actionName"},
                    {"httproute", true}
                };

            request.Properties[HttpPropertyKeys.HttpRouteDataKey] = new HttpRouteData(route, routeValues);
            
            // Act
            IHttpVirtualPathData httpvPathData = collection.GetVirtualPath(request, "domainRoute", routeValues);

            // Assert
            Assert.NotNull(httpvPathData);
            Assert.Equal("/api/controllerName/actionNameFromDomain", httpvPathData.VirtualPath);
        }
        public void ConvertHttpRouteDataToRouteDataRunsCustomHttpRoute()
        {
            // Arrange
            DomainHttpRoute route = new DomainHttpRoute("myDomain", "api/{controller}/{action}", new { controller = "Values", action = "GetTenant" });
            HostedHttpRouteCollection collection = new HostedHttpRouteCollection(new RouteCollection());
            collection.Add("domainRoute", route);
            HttpRequestMessage request = CreateHttpRequestMessageWithContext();
            IHttpRouteData httpRouteData = collection.GetRouteData(request);
            
            // Act
            RouteData routeData = httpRouteData.ToRouteData();

            // Assert
            Assert.NotNull(routeData.Values);
            Assert.Equal(3, routeData.Values.Count);
            Assert.Equal("controllerName", routeData.Values["controller"]);
            Assert.Equal("actionName", routeData.Values["action"]);
            Assert.Equal("myDomain", routeData.Values["domain"]);
        }
示例#6
-1
        public async Task WebHost_Batching_WithSpecialCharactersInUrl()
        {
            // Arrange
            var handler = new SuccessMessageHandler();

            var routeCollection = new HostedHttpRouteCollection(new RouteCollection(), "/");
            routeCollection.Add("default", routeCollection.CreateRoute(
                "values/  space",
                defaults: null,
                constraints: null,
                dataTokens: null,
                handler: handler));

            var configuration = new HttpConfiguration(routeCollection);

            var server = new HttpServer(configuration);

            var batchHandler = new DefaultHttpBatchHandler(server);
            var request = new HttpRequestMessage
            {
                Content = new MultipartContent("mixed")
                {
                    new HttpMessageContent(new HttpRequestMessage(HttpMethod.Post, "http://contoso.com/values/  space"))
                }
            };

            // Arrange
            var response = await batchHandler.ProcessBatchAsync(request, CancellationToken.None);

            // Assert
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.True(handler.IsCalled);
        }