public SelectExpandTest() { _configuration = RoutingConfigurationFactory.CreateWithTypes( new[] { typeof(SelectExpandTestCustomersController), typeof(SelectExpandTestCustomersAliasController), typeof(PlayersController), typeof(NonODataSelectExpandTestCustomersController), typeof(AttributedSelectExpandCustomersController), typeof(SelectExpandTestCustomer), typeof(SelectExpandTestSpecialCustomer), typeof(SelectExpandTestCustomerWithAlias), typeof(SelectExpandTestOrder), typeof(SelectExpandTestSpecialOrder), typeof(SelectExpandTestSpecialOrderWithAlias), typeof(ReferenceNavigationPropertyExpandFilterController), }); _configuration.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always; _configuration.Count().Filter().OrderBy().Expand().MaxTop(null).Select(); _configuration.MapODataServiceRoute("odata", "odata", GetModel()); _configuration.MapODataServiceRoute("odata-inheritance", "odata-inheritance", GetModelWithInheritance()); _configuration.MapODataServiceRoute("odata-alias", "odata-alias", GetModelWithCustomerAlias()); _configuration.MapODataServiceRoute( "odata-alias2-inheritance", "odata-alias2-inheritance", GetModelWithCustomerAliasAndInheritance()); _configuration.MapODataServiceRoute("odata2", "odata2", GetModelWithOperations()); _configuration.MapODataServiceRoute("odata-expandfilter", "odata-expandfilter", GetModelWithReferenceNavigationPropertyFilter()); _configuration.Routes.MapHttpRoute("api", "api/{controller}", new { controller = "NonODataSelectExpandTestCustomers" }); _configuration.EnableDependencyInjection(); HttpServer server = new HttpServer(_configuration); _client = new HttpClient(server); }
public async Task ExtensionResolver_Works_EnumPrefixFree_QueryOption(string query, bool enableEnumPrefix, HttpStatusCode statusCode, string output) { // Arrange IEdmModel model = GetEdmModel(); var config = RoutingConfigurationFactory.CreateWithTypes(new[] { typeof(ParserExtenstionCustomersController) }); ODataUriResolver resolver = new ODataUriResolver(); if (enableEnumPrefix) { resolver = new StringAsEnumResolver(); } config.MapODataServiceRoute("odata", "odata", builder => builder.AddService(ServiceLifetime.Singleton, sp => model) .AddService <IEnumerable <IODataRoutingConvention> >(ServiceLifetime.Singleton, sp => ODataRoutingConventions.CreateDefaultWithAttributeRouting("odata", config)) .AddService(ServiceLifetime.Singleton, sp => resolver)); HttpClient client = new HttpClient(new HttpServer(config)); // Act HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, String.Format("http://localhost/odata/ParserExtenstionCustomers?{0}", query)); HttpResponseMessage response = await client.SendAsync(request); // Assert Assert.Equal(statusCode, response.StatusCode); if (statusCode == HttpStatusCode.OK) { JObject content = await response.Content.ReadAsAsync <JObject>(); Assert.Equal(output, String.Join(",", content["value"].Select(e => e["Id"]))); } }
public async Task ExtensionResolver_Works_EnumPrefixFree(string parameter, bool enableEnumPrefix, HttpStatusCode statusCode) { // Arrange IEdmModel model = GetEdmModel(); var config = RoutingConfigurationFactory.CreateWithTypes(new[] { typeof(ParserExtenstionCustomersController) }); ODataUriResolver resolver = new ODataUriResolver(); if (enableEnumPrefix) { resolver = new StringAsEnumResolver(); } config.MapODataServiceRoute("odata", "odata", builder => builder.AddService(ServiceLifetime.Singleton, sp => model) .AddService <IEnumerable <IODataRoutingConvention> >(ServiceLifetime.Singleton, sp => ODataRoutingConventions.CreateDefaultWithAttributeRouting("odata", config)) .AddService(ServiceLifetime.Singleton, sp => resolver)); HttpClient client = new HttpClient(new HttpServer(config)); // Act HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, String.Format("http://localhost/odata/ParserExtenstionCustomers/Default.GetCustomerByGender({0})", parameter)); HttpResponseMessage response = await client.SendAsync(request); // Assert Assert.Equal(statusCode, response.StatusCode); if (statusCode == HttpStatusCode.OK) { Assert.Equal("GetCustomerByGender/Male", (response.Content as ObjectContent <string>).Value); } }
private static HttpClient GetClient(DependencyInjectionModel instance) { var config = RoutingConfigurationFactory.CreateWithTypes(new[] { typeof(DependencyInjectionModelsController) }); IEdmModel model = GetEdmModel(); config.MapODataServiceRoute("odata", "odata", builder => builder.AddService(ServiceLifetime.Singleton, sp => instance) .AddService(ServiceLifetime.Singleton, sp => model) .AddService <IEnumerable <IODataRoutingConvention> >(ServiceLifetime.Singleton, sp => ODataRoutingConventions.CreateDefaultWithAttributeRouting("odata", config))); return(new HttpClient(new HttpServer(config))); }
public void MapODataServiceRoute_ConfigEnsureInitialized_DoesNotThrowForValidPathTemplateWithAttributeRouting() { // Arrange var builder = ODataConventionModelBuilderFactory.Create(); builder.EntitySet <Customer>("Customers"); IEdmModel model = builder.GetEdmModel(); var configuration = RoutingConfigurationFactory.CreateWithTypes(new[] { typeof(CustomersController) }); configuration.MapODataServiceRoute(model); // Act & Assert ExceptionAssert.DoesNotThrow(() => configuration.EnsureInitialized()); }
public SelectExpandNestedDollarCountTest() { _configuration = RoutingConfigurationFactory.CreateWithTypes( new[] { typeof(MsCustomersController), typeof(MetadataController) }); _configuration.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always; _configuration.Count().OrderBy().Filter().Expand().MaxTop(null); _configuration.MapODataServiceRoute("odata", "odata", GetModel()); HttpServer server = new HttpServer(_configuration); _client = new HttpClient(server); }
public async Task AGet_Minimial() { // Arrange var configuration = RoutingConfigurationFactory.CreateWithTypes(new[] { typeof(AccountsController) }); configuration.MapODataServiceRoute("odata", "odata", GetEdmModel()); HttpClient client = new HttpClient(new HttpServer(configuration)); // Act HttpResponseMessage response = await client.GetAsync(_requestRooturl + "Accounts?$expand=PayoutPI&$format=application/json;odata.metadata=minimal"); // Assert Assert.True(response.IsSuccessStatusCode); }
public QueryableLimitationTest() { _configuration = RoutingConfigurationFactory.CreateWithTypes(new[] { typeof(QueryLimitCustomersController), typeof(OpenCustomersController), typeof(MetadataController) }); _model = GetEdmModel(); _configuration.Count().OrderBy().Filter().Expand().MaxTop(null); _configuration.MapODataServiceRoute("odata", "odata", _model); HttpServer server = new HttpServer(_configuration); _client = new HttpClient(server); }
public void MapODataServiceRoute_ConfigEnsureInitialized_DoesNotThrowForInvalidPathTemplateWithoutAttributeRouting() { // Arrange var builder = ODataConventionModelBuilderFactory.Create(); builder.EntitySet <Customer>("Customers").EntityType.Ignore(c => c.Name); IEdmModel model = builder.GetEdmModel(); var configuration = RoutingConfigurationFactory.CreateWithTypes(new[] { typeof(CustomersController) }); configuration.MapODataServiceRoute( "RouteName", "RoutePrefix", model, new DefaultODataPathHandler(), ODataRoutingConventions.CreateDefault()); // Act & Assert ExceptionAssert.DoesNotThrow(() => configuration.EnsureInitialized()); }
private static HttpConfiguration GetQueryOptionConfiguration(bool caseInsensitive) { var config = RoutingConfigurationFactory.CreateWithTypes(new[] { typeof(ParserExtenstionCustomersController) }); ODataUriResolver resolver = new ODataUriResolver(); if (caseInsensitive) { resolver = new CaseInsensitiveResolver(); } config.Count().OrderBy().Filter().Expand().MaxTop(null).Select(); config.MapODataServiceRoute("query", "query", builder => builder.AddService(ServiceLifetime.Singleton, sp => GetEdmModel()) .AddService <IEnumerable <IODataRoutingConvention> >(ServiceLifetime.Singleton, sp => ODataRoutingConventions.CreateDefaultWithAttributeRouting("query", config)) .AddService(ServiceLifetime.Singleton, sp => resolver)); return(config); }
public async Task DollarFormat_Applies_IfPresent(string path, string mediaTypeFormat) { // Arrange MediaTypeHeaderValue expected = MediaTypeHeaderValue.Parse(mediaTypeFormat); string url = string.Format("http://localhost/{0}?$format={1}", path, mediaTypeFormat); IEdmModel model = GetEdmModel(); var configuration = RoutingConfigurationFactory.CreateWithTypes( new[] { typeof(FormatCustomersController), typeof(ThisController) }); HttpServer server = new HttpServer(configuration); HttpClient client = new HttpClient(server); configuration.MapODataServiceRoute("odata", routePrefix: null, model: model); // Act HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, url); request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/json")); HttpResponseMessage response = await client.SendAsync(request); // Assert ExceptionAssert.DoesNotThrow(() => response.EnsureSuccessStatusCode()); Assert.Equal(expected, response.Content.Headers.ContentType); }
private static HttpConfiguration GetConfiguration(bool caseInsensitive, bool unqualifiedNameCall) { IEdmModel model = ODataRoutingModel.GetModel(); HttpConfiguration config = RoutingConfigurationFactory.CreateWithTypes(new[] { typeof(MetadataController), typeof(ProductsController), typeof(RoutingCustomersController), }); ODataUriResolver resolver = new ODataUriResolver(); if (unqualifiedNameCall) { resolver = new UnqualifiedODataUriResolver(); if (caseInsensitive) { resolver = new UnqualifiedCaseInsensitiveResolver(); } } else { if (caseInsensitive) { resolver = new CaseInsensitiveResolver(); } } config.Count().Filter().OrderBy().Expand().MaxTop(null).Select(); config.MapODataServiceRoute("odata", "odata", builder => builder.AddService(ServiceLifetime.Singleton, sp => model) .AddService <IEnumerable <IODataRoutingConvention> >(ServiceLifetime.Singleton, sp => ODataRoutingConventions.CreateDefaultWithAttributeRouting("odata", config)) .AddService(ServiceLifetime.Singleton, sp => resolver)); return(config); }