本文整理汇总了C#中HttpRouteCollection.MapODataServiceRoute方法的典型用法代码示例。如果您正苦于以下问题:C# HttpRouteCollection.MapODataServiceRoute方法的具体用法?C# HttpRouteCollection.MapODataServiceRoute怎么用?C# HttpRouteCollection.MapODataServiceRoute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpRouteCollection
的用法示例。
在下文中一共展示了HttpRouteCollection.MapODataServiceRoute方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AdvancedMapODataServiceRoute_ConfiguresARoute_WithAnODataRouteConstraintAndVersionConstraints
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);
}
示例2: MapODataRoute_Returns_ODataRoute
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);
}
示例3: MapODataServiceRoute_AddsBatchRoute_WhenBatchHandlerIsProvided
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);
}
示例4: MapODataServiceRoute_ConfiguresARoute_WithAnODataRouteConstraint
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);
}
示例5: ConfigureODataRoutes
/// <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);
}