public async Task AttributeRouting_QueryProperty_AfterCallBoundFunction() { // Arrange const string RequestUri = @"http://localhost/Customers(12)/NS.GetOrder(orderId=4)/Amount"; CustomersModelWithInheritance model = new CustomersModelWithInheritance(); HttpConfiguration config = new[] { typeof(CustomersController) }.GetHttpConfiguration(); config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always; config.MapODataServiceRoute("odata", "", model.Model); HttpServer server = new HttpServer(config); config.EnsureInitialized(); HttpClient client = new HttpClient(server); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, RequestUri); // Act HttpResponseMessage response = await client.SendAsync(request); string responseString = await response.Content.ReadAsStringAsync(); // Assert Assert.True(response.IsSuccessStatusCode); Assert.Equal("{\r\n \"@odata.context\":\"http://localhost/$metadata#Edm.Int32\",\"value\":56\r\n}", responseString); }
public void Controller_DoesNotAppear_InApiDescriptions() { var config = new[] { typeof(MetadataController) }.GetHttpConfiguration(); config.Routes.MapHttpRoute("Default", "{controller}/{action}"); config.MapODataServiceRoute(new ODataConventionModelBuilder().GetEdmModel()); config.EnsureInitialized(); var explorer = config.Services.GetApiExplorer(); var apis = explorer.ApiDescriptions.Select(api => api.ActionDescriptor.ControllerDescriptor.ControllerName); Assert.DoesNotContain("ODataMetadata", apis); }
public void AttributeRoutingConvention_ConfigEnsureInitialized_DoesNotThrowForValidPathTemplate() { // Arrange IEdmModel model = new CustomersModelWithInheritance().Model; HttpConfiguration configuration = new[] { typeof(TestODataController) }.GetHttpConfiguration(); AttributeRoutingConvention convention = new AttributeRoutingConvention(model, configuration); // Act & Assert Assert.DoesNotThrow(() => configuration.EnsureInitialized()); }
public void AttributeRoutingConvention_ConfigEnsureInitialized_ThrowsForInvalidPathTemplate() { // Arrange IEdmModel model = new EdmModel(); HttpConfiguration configuration = new[] { typeof(TestODataController) }.GetHttpConfiguration(); AttributeRoutingConvention convention = new AttributeRoutingConvention(model, configuration); // Act & Assert Assert.Throws<InvalidOperationException>( () => configuration.EnsureInitialized(), "The path template 'Customers' on the action 'GetCustomers' in controller 'TestOData' is not a valid OData path template. " + "The operation import overloads matching 'Customers' are invalid. This is most likely an error in the IEdmModel."); }
public void MapODataServiceRoute_ConfigEnsureInitialized_DoesNotThrowForInvalidPathTemplateWithoutAttributeRouting() { // Arrange var builder = new ODataConventionModelBuilder(); builder.EntitySet<Customer>("Customers").EntityType.Ignore(c => c.Name); IEdmModel model = builder.GetEdmModel(); HttpConfiguration configuration = new[] { typeof(CustomersController) }.GetHttpConfiguration(); configuration.MapODataServiceRoute( "RouteName", "RoutePrefix", model, new DefaultODataPathHandler(), ODataRoutingConventions.CreateDefault()); // Act & Assert Assert.DoesNotThrow(() => configuration.EnsureInitialized()); }
public void MapODataServiceRoute_ConfigEnsureInitialized_DoesNotThrowForValidPathTemplateWithAttributeRouting() { // Arrange var builder = new ODataConventionModelBuilder(); builder.EntitySet<Customer>("Customers"); IEdmModel model = builder.GetEdmModel(); HttpConfiguration configuration = new[] { typeof(CustomersController) }.GetHttpConfiguration(); configuration.MapODataServiceRoute(model); // Act & Assert Assert.DoesNotThrow(() => configuration.EnsureInitialized()); }