コード例 #1
0
        public static void MapODataRoute(this HttpRouteCollection routes, string routeName, string routePrefix, IEdmModel model,
                                         IODataPathHandler pathHandler, IEnumerable <IODataRoutingConvention> routingConventions, ODataBatchHandler batchHandler)
        {
            if (routes == null)
            {
                throw Error.ArgumentNull("routes");
            }

            if (!String.IsNullOrEmpty(routePrefix))
            {
                int prefixLastIndex = routePrefix.Length - 1;
                if (routePrefix[prefixLastIndex] == '/')
                {
                    // Remove the last trailing slash if it has one.
                    routePrefix = routePrefix.Substring(0, routePrefix.Length - 1);
                }
            }

            if (batchHandler != null)
            {
                batchHandler.ODataRouteName = routeName;
                string batchTemplate = String.IsNullOrEmpty(routePrefix) ? ODataRouteConstants.Batch : routePrefix + '/' + ODataRouteConstants.Batch;
                routes.MapHttpBatchRoute(routeName + "Batch", batchTemplate, batchHandler);
            }

            ODataPathRouteConstraint routeConstraint = new ODataPathRouteConstraint(pathHandler, model, routeName, routingConventions);

            routes.Add(routeName, new ODataRoute(routePrefix, routeConstraint));
        }
コード例 #2
0
        public static void MapODataRoute(this HttpRouteCollection routes, string routeName, string routePrefix, IEdmModel model,
                                         IODataPathHandler pathHandler, IEnumerable <IODataRoutingConvention> routingConventions, ODataBatchHandler batchHandler)
        {
            if (routes == null)
            {
                throw Error.ArgumentNull("routes");
            }

            if (!String.IsNullOrEmpty(routePrefix))
            {
                int routePrefixLastCharIndex = routePrefix.Length - 1;
                if (routePrefix[routePrefixLastCharIndex] != '/')
                {
                    // Add the last trailing slash if it doesn't have one.
                    routePrefix += "/";
                }
            }

            if (batchHandler != null)
            {
                batchHandler.ODataRouteName = routeName;
                routes.MapHttpBatchRoute(routeName + "Batch", routePrefix + ODataRouteConstants.Batch, batchHandler);
            }

            string routeTemplate = routePrefix + ODataRouteConstants.ODataPathTemplate;
            IHttpRouteConstraint     routeConstraint      = new ODataPathRouteConstraint(pathHandler, model, routeName, routingConventions);
            HttpRouteValueDictionary constraintDictionary = new HttpRouteValueDictionary()
            {
                { ODataRouteConstants.ConstraintName, routeConstraint }
            };

            routes.MapHttpRoute(routeName, routeTemplate, defaults: null, constraints: constraintDictionary);
        }
コード例 #3
0
        public void MapHttpBatchRoute_CreatesRoutesUsingCustomBatchHandler()
        {
            HttpRouteCollection routes           = new HttpRouteCollection();
            HttpBatchHandler    mockBatchHandler = new Mock <HttpBatchHandler>(new HttpServer()).Object;
            IHttpRoute          route            = routes.MapHttpBatchRoute("batch", "api/batch", mockBatchHandler);

            Assert.NotNull(route);
            Assert.Equal("api/batch", route.RouteTemplate);
            Assert.Same(route, routes["batch"]);
            Assert.Same(mockBatchHandler, route.Handler);
        }