public void AdvancedMapODataServiceRoute_ConfiguresARoute_WithAnODataRouteConstraintAndVersionConstraints() { // Arrange HttpRouteCollection routes = new HttpRouteCollection(); IEdmModel model = new EdmModel(); string routeName = "name"; string routePrefix = "prefix"; var pathHandler = new DefaultODataPathHandler(); var conventions = new List <IODataRoutingConvention>(); // Act routes.MapODataServiceRoute(routeName, routePrefix, model, pathHandler, conventions); // Assert IHttpRoute odataRoute = routes[routeName]; Assert.Single(routes); Assert.Equal(routePrefix + "/{*odataPath}", odataRoute.RouteTemplate); Assert.Equal(2, odataRoute.Constraints.Count); var odataPathConstraint = Assert.Single(odataRoute.Constraints.Values.OfType <ODataPathRouteConstraint>()); Assert.Same(model, odataPathConstraint.EdmModel); Assert.IsType <DefaultODataPathHandler>(odataPathConstraint.PathHandler); Assert.NotNull(odataPathConstraint.RoutingConventions); var odataVersionConstraint = Assert.Single(odataRoute.Constraints.Values.OfType <ODataVersionConstraint>()); Assert.Equal(ODataVersion.V1, odataVersionConstraint.MinVersion); Assert.Equal(ODataVersion.V3, odataVersionConstraint.MaxVersion); }
public void AdvancedMapODataServiceRoute_ConfiguresARoute_WithAnODataRouteConstraintAndVersionConstraints() { // Arrange HttpRouteCollection routes = new HttpRouteCollection(); IEdmModel model = new EdmModel(); string routeName = "name"; string routePrefix = "prefix"; var pathHandler = new DefaultODataPathHandler(); var conventions = new List<IODataRoutingConvention>(); // Act routes.MapODataServiceRoute(routeName, routePrefix, model, pathHandler, conventions); // Assert IHttpRoute odataRoute = routes[routeName]; Assert.Single(routes); Assert.Equal(routePrefix + "/{*odataPath}", odataRoute.RouteTemplate); Assert.Equal(2, odataRoute.Constraints.Count); var odataPathConstraint = Assert.Single(odataRoute.Constraints.Values.OfType<ODataPathRouteConstraint>()); Assert.Same(model, odataPathConstraint.EdmModel); Assert.IsType<DefaultODataPathHandler>(odataPathConstraint.PathHandler); Assert.NotNull(odataPathConstraint.RoutingConventions); var odataVersionConstraint = Assert.Single(odataRoute.Constraints.Values.OfType<ODataVersionConstraint>()); Assert.Equal(ODataVersion.V1, odataVersionConstraint.MinVersion); Assert.Equal(ODataVersion.V3, odataVersionConstraint.MaxVersion); }
public void MapODataRoute_Returns_ODataRoute() { // Arrange HttpRouteCollection routes = new HttpRouteCollection(); IEdmModel model = new EdmModel(); // Act ODataRoute route = routes.MapODataServiceRoute("odata", "odata", model); // Assert Assert.NotNull(route); Assert.Same(model, route.PathRouteConstraint.EdmModel); Assert.Equal("odata", route.PathRouteConstraint.RouteName); }
public void MapODataServiceRoute_AddsBatchRoute_WhenBatchHandlerIsProvided() { HttpRouteCollection routes = new HttpRouteCollection(); IEdmModel model = new EdmModel(); string routeName = "name"; string routePrefix = "prefix"; var batchHandler = new DefaultODataBatchHandler(new HttpServer()); routes.MapODataServiceRoute(routeName, routePrefix, model, batchHandler); IHttpRoute batchRoute = routes["nameBatch"]; Assert.NotNull(batchRoute); Assert.Same(batchHandler, batchRoute.Handler); Assert.Equal("prefix/$batch", batchRoute.RouteTemplate); }
public void MapODataServiceRoute_ConfiguresARoute_WithAnODataRouteConstraint() { HttpRouteCollection routes = new HttpRouteCollection(); IEdmModel model = new EdmModel(); string routeName = "name"; string routePrefix = "prefix"; routes.MapODataServiceRoute(routeName, routePrefix, model); IHttpRoute odataRoute = routes[routeName]; Assert.Single(routes); Assert.Equal(routePrefix + "/{*odataPath}", odataRoute.RouteTemplate); var constraint = Assert.Single(odataRoute.Constraints); var odataConstraint = Assert.IsType<ODataPathRouteConstraint>(constraint.Value); Assert.Same(model, odataConstraint.EdmModel); Assert.IsType<DefaultODataPathHandler>(odataConstraint.PathHandler); Assert.IsType<List<IODataRoutingConvention>>(odataConstraint.RoutingConventions); }
public void MapODataServiceRoute_AddsBatchRoute_WhenBatchHandlerIsProvided() { // Arrange HttpRouteCollection routes = new HttpRouteCollection(); IEdmModel model = new EdmModel(); string routeName = "name"; string routePrefix = "prefix"; var batchHandler = new DefaultODataBatchHandler(new HttpServer()); // Act routes.MapODataServiceRoute(routeName, routePrefix, model, batchHandler); // Assert IHttpRoute batchRoute = routes["nameBatch"]; Assert.NotNull(batchRoute); Assert.Same(batchHandler, batchRoute.Handler); Assert.Equal("prefix/$batch", batchRoute.RouteTemplate); }
/// <summary> /// Configure the OData routes to use the functionality provided in this library. /// </summary> /// <param name="routes"></param> /// <param name="routeName"></param> /// <param name="routePrefix"></param> /// <param name="httpServer">A web API <see cref="HttpServer"/> instance.</param> /// <param name="edmModel">An <see cref="IEdmModel"/>, to override the EDM model that would be created by <see cref="ContainerMetadata"/>.</param> /// <param name="maxOperationsPerChangeset"></param> public void ConfigureODataRoutes(HttpRouteCollection routes, string routeName, string routePrefix, HttpServer httpServer, IEdmModel edmModel = null, int?maxOperationsPerChangeset = null) { Contract.Requires <ArgumentNullException>(routes != null); Contract.Requires <ArgumentException>(!string.IsNullOrWhiteSpace(routeName)); Contract.Requires <ArgumentNullException>(routePrefix != null); Contract.Requires <ArgumentNullException>(httpServer != null); var batchHandler = new ODataServerBatchHandler(httpServer); if (maxOperationsPerChangeset != null) { batchHandler.MessageQuotas.MaxOperationsPerChangeset = maxOperationsPerChangeset.GetValueOrDefault(); } routes.MapODataServiceRoute(routeName, routePrefix, edmModel ?? BuildEdmModel(), //_containerMetadata.EdmModel, new DefaultODataPathHandler(), GetRoutingConventions(), batchHandler); }
public static void MapODataServiceRoute(this HttpRouteCollection routes, IEdmModel model) { routes.MapODataServiceRoute("IgnoredRouteName", null, model); }
/// <summary> /// Configure the OData routes to use the functionality provided in this library. /// </summary> /// <param name="routes"></param> /// <param name="routeName"></param> /// <param name="routePrefix"></param> /// <param name="httpServer">A web API <see cref="HttpServer"/> instance.</param> /// <param name="edmModel">An <see cref="IEdmModel"/>, to override the EDM model that would be created by <see cref="ContainerMetadata"/>.</param> /// <param name="maxOperationsPerChangeset"></param> public void ConfigureODataRoutes(HttpRouteCollection routes, string routeName, string routePrefix, HttpServer httpServer, IEdmModel edmModel = null, int? maxOperationsPerChangeset = null) { Contract.Requires<ArgumentNullException>(routes != null); Contract.Requires<ArgumentException>(! string.IsNullOrWhiteSpace(routeName)); Contract.Requires<ArgumentNullException>(routePrefix != null); Contract.Requires<ArgumentNullException>(httpServer != null); var batchHandler = new ODataServerBatchHandler(httpServer); if (maxOperationsPerChangeset != null) { batchHandler.MessageQuotas.MaxOperationsPerChangeset = maxOperationsPerChangeset.GetValueOrDefault(); } routes.MapODataServiceRoute(routeName, routePrefix, edmModel ?? BuildEdmModel(), //_containerMetadata.EdmModel, new DefaultODataPathHandler(), GetRoutingConventions(), batchHandler); }