Esempio n. 1
0
        /// <summary>
        /// Registers Web API routes
        /// </summary>
        public static void RegisterWebApiRoutes(HttpConfiguration configuration, HttpBatchHandler batchHandler)
        {
            configuration.MapHttpAttributeRoutes();

            configuration.Routes.MapHttpBatchRoute("Batch", "api/batch", batchHandler);
            configuration.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}", new { id = RouteParameter.Optional });
        }
 public static IHttpRoute MapHttpBatchRoute(
     this HttpRouteCollection routes,
     string routeName,
     string routeTemplate,
     HttpBatchHandler batchHandler
     )
 {
     return(routes.MapHttpRoute(
                routeName,
                routeTemplate,
                defaults: null,
                constraints: null,
                handler: batchHandler
                ));
 }
        public void ExceptionHandlerGet_ReturnsSpecifiedInstance()
        {
            // Arrange
            IExceptionLogger  exceptionLogger          = CreateDummyExceptionLogger();
            IExceptionHandler expectedExceptionHandler = CreateDummyExceptionHandler();

            using (HttpServer server = CreateServer())
                using (HttpBatchHandler handler = CreateProductUnderTest(server, exceptionLogger,
                                                                         expectedExceptionHandler))
                {
                    // Act
                    IExceptionHandler exceptionHandler = handler.ExceptionHandler;

                    // Assert
                    Assert.Same(expectedExceptionHandler, exceptionHandler);
                }
        }
        public void ExceptionHandlerGet_IfUnset_ReturnsExceptionHandlerFromConfiguration()
        {
            // Arrange
            using (HttpConfiguration configuration = CreateConfiguration())
            {
                IExceptionHandler expectedExceptionHandler = CreateDummyExceptionHandler();
                configuration.Services.Replace(typeof(IExceptionHandler), expectedExceptionHandler);

                using (HttpServer server = new HttpServer(configuration))
                    using (HttpBatchHandler product = CreateProductUnderTest(server))
                    {
                        // Act
                        IExceptionHandler exceptionHandler = product.ExceptionHandler;

                        // Assert
                        LastChanceExceptionHandler lastChanceHandler = Assert.IsType <LastChanceExceptionHandler>(exceptionHandler);
                        Assert.Same(expectedExceptionHandler, lastChanceHandler.InnerHandler);
                    }
            }
        }
        public void ExceptionLoggerGet_IfUnset_ReturnsExceptionLoggerFromConfiguration()
        {
            // Arrange
            using (HttpConfiguration configuration = CreateConfiguration())
            {
                IExceptionLogger expectedExceptionLogger = CreateDummyExceptionLogger();
                configuration.Services.Add(typeof(IExceptionLogger), expectedExceptionLogger);

                using (HttpServer server = new HttpServer(configuration))
                    using (HttpBatchHandler product = CreateProductUnderTest(server))
                    {
                        // Act
                        IExceptionLogger exceptionLogger = product.ExceptionLogger;

                        // Assert
                        CompositeExceptionLogger       compositeLogger = Assert.IsType <CompositeExceptionLogger>(exceptionLogger);
                        IEnumerable <IExceptionLogger> loggers         = compositeLogger.Loggers;
                        Assert.NotNull(loggers);
                        IExceptionLogger logger = Assert.Single(loggers);
                        Assert.Same(expectedExceptionLogger, logger);
                    }
            }
        }
Esempio n. 6
0
        private static void MapRoute(HttpConfiguration httpConfiguration, IEdmModel edmModel, string routePrefix, HttpBatchHandler batchHandler)
        {
            // batch handler should be mapped first
            var routeTemplate = string.IsNullOrEmpty(routePrefix) ? ODataRouteConstants.Batch : routePrefix + '/' + ODataRouteConstants.Batch;

            httpConfiguration.Routes.MapHttpBatchRoute(routePrefix + "Batch", routeTemplate, batchHandler);

            var httpMessageHandler = HttpClientFactory.CreatePipeline(new HttpControllerDispatcher(httpConfiguration), new DelegatingHandler[0]);

            httpConfiguration.MapODataServiceRoute(routePrefix, routePrefix, edmModel, httpMessageHandler);
        }
Esempio n. 7
0
        public static HttpConfiguration MapODataServiceRoutes(this HttpConfiguration httpConfiguration, HttpBatchHandler batchHandler)
        {
            var edmModelBuilder = (IEdmModelBuilder)httpConfiguration.DependencyResolver.GetService(typeof(IEdmModelBuilder));
            var edmModels       = edmModelBuilder.Build();

            foreach (var pair in edmModels)
            {
                var routePrefix = pair.Key.Segments.Last();
                MapRoute(httpConfiguration, pair.Value, routePrefix, batchHandler);
            }

            return(httpConfiguration);
        }
 public static IHttpRoute MapODataServiceBatchRoute(this HttpRouteCollection routes, string routeName,
                                                    string routeTemplate, HttpBatchHandler batchHandler)
 {
     return(routes.MapODataServiceBatchRoute(routeName, routeTemplate, null, null, batchHandler));
 }
Esempio n. 9
0
 /// <summary> 映射指定的路由以处理 HTTP 批请求。</summary>
 /// <param name="routes">应用程序的路由的集合。</param>
 /// <param name="routeName">要映射的路由的名称。</param>
 /// <param name="routeTemplate">路由的路由模板。</param>
 /// <param name="batchHandler">用于处理批请求的 <see cref="T:System.Web.Http.Batch.HttpBatchHandler" />。</param>
 public static IHttpRoute MapHttpBatchRoute(this HttpRouteCollection routes, string routeName, string routeTemplate, HttpBatchHandler batchHandler)
 {
     return(routes.MapHttpRoute(routeName, routeTemplate, (object)null, (object)null, (HttpMessageHandler)batchHandler));
 }