[InlineData("GET", "http://localhost/Customers(12)/NS.SpecialCustomer/NS.GetSalary()", "GetSalaryFromSpecialCustomer_12")] // call function on derived entity type public async Task AttriubteRouting_SelectsExpectedControllerAndAction(string method, string requestUri, string expectedResult) { // Arrange CustomersModelWithInheritance model = new CustomersModelWithInheritance(); var controllers = new[] { typeof(CustomersController), typeof(MetadataAndServiceController), typeof(OrdersController) }; TestAssemblyResolver resolver = new TestAssemblyResolver(new MockAssembly(controllers)); HttpConfiguration config = new HttpConfiguration(); config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always; config.Services.Replace(typeof(IAssembliesResolver), resolver); config.MapODataServiceRoute("odata", "", model.Model); HttpServer server = new HttpServer(config); config.EnsureInitialized(); HttpClient client = new HttpClient(server); HttpRequestMessage request = new HttpRequestMessage(new HttpMethod(method), requestUri); // Act var response = await client.SendAsync(request); // Assert if (!response.IsSuccessStatusCode) { Assert.False(true, await response.Content.ReadAsStringAsync()); } var result = await response.Content.ReadAsAsync<AttributeRoutingTestODataResponse>(); Assert.Equal(expectedResult, result.Value); }
public static HttpConfiguration GetHttpConfiguration(this Type[] controllers) { var resolver = new TestAssemblyResolver(new MockAssembly(controllers)); var configuration = new HttpConfiguration(); configuration.Services.Replace(typeof(IAssembliesResolver), resolver); return configuration; }
public ODataContainmentTest() { var controllers = new[] { typeof(MyOrdersController) }; var resolver = new TestAssemblyResolver(new MockAssembly(controllers)); _configuration = new HttpConfiguration { IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always }; _configuration.Services.Replace(typeof(IAssembliesResolver), resolver); _configuration.MapODataServiceRoute("odata", "odata", GetEdmModel()); var server = new HttpServer(_configuration); _client = new HttpClient(server); }
public AttributeRoutingUnboundTest() { _configuration = new HttpConfiguration(); _configuration.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always; _configuration.MapODataServiceRoute("odata", "", GetEdmModel(_configuration)); var controllers = new[] { typeof(ConventionCustomersController) }; TestAssemblyResolver resolver = new TestAssemblyResolver(new MockAssembly(controllers)); _configuration.Services.Replace(typeof(IAssembliesResolver), resolver); _server = new HttpServer(_configuration); _configuration.EnsureInitialized(); _client = new HttpClient(_server); }
public ODataActionTests() { HttpConfiguration configuration = new HttpConfiguration(); _model = GetModel(); configuration.Formatters.Clear(); configuration.Formatters.AddRange(ODataMediaTypeFormatters.Create()); configuration.MapODataServiceRoute(_model); var controllers = new[] { typeof(CustomersController) }; var assembliesResolver = new TestAssemblyResolver(new MockAssembly(controllers)); configuration.Services.Replace(typeof(IAssembliesResolver), assembliesResolver); _server = new HttpServer(configuration); _client = new HttpClient(_server); }
public void ResourceIsNotFound_IfContainsInvalidEnum(object value, string action, string parameterName) { // Arrange HttpConfiguration configuration = new HttpConfiguration(); configuration.Services.Replace(typeof(ModelBinderProvider), new ODataModelBinderProvider()); configuration.MapODataServiceRoute("odata", "", GetEdmModel()); var controllers = new[] { typeof(ODataModelBinderProviderTestODataController) }; TestAssemblyResolver resolver = new TestAssemblyResolver(new MockAssembly(controllers)); configuration.Services.Replace(typeof(IAssembliesResolver), resolver); HttpServer server = new HttpServer(configuration); HttpClient client = new HttpClient(server); // Act string url = String.Format( "http://localhost/{0}({1}={2})", action, parameterName, Uri.EscapeDataString(ConventionsHelpers.GetUriRepresentationForValue(value))); HttpResponseMessage response = client.GetAsync(url).Result; // Assert Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); }
public void ODataModelBinderProvider_Works_ForEnum(object value, string action, string parameterName) { // Arrange HttpConfiguration configuration = new HttpConfiguration(); configuration.Services.Replace(typeof(ModelBinderProvider), new ODataModelBinderProvider()); configuration.Routes.MapODataServiceRoute("odata", "", GetEdmModel()) .MapODataRouteAttributes(configuration); var controllers = new[] { typeof(ODataModelBinderProviderTestODataController) }; TestAssemblyResolver resolver = new TestAssemblyResolver(new MockAssembly(controllers)); configuration.Services.Replace(typeof(IAssembliesResolver), resolver); HttpServer server = new HttpServer(configuration); HttpClient client = new HttpClient(server); // Act string url = String.Format( "http://localhost/{0}({1}={2})", action, parameterName, Uri.EscapeDataString(ConventionsHelpers.GetUriRepresentationForValue(value))); HttpResponseMessage response = client.GetAsync(url).Result; // Assert response.EnsureSuccessStatusCode(); Assert.Equal( value, response.Content.ReadAsAsync(value.GetType(), configuration.Formatters).Result); }
private static HttpServer CreateServer(HttpConfiguration configuration) { // Need the MetadataController to resolve the service document as well as $metadata. var controllers = new[] { typeof(DateTimeOffsetKeyCustomersController), typeof(MetadataController), typeof(RoutingCustomersController), typeof(ProductsController), typeof(EnumCustomersController), typeof(DestinationsController), }; TestAssemblyResolver resolver = new TestAssemblyResolver(new MockAssembly(controllers)); configuration.Services.Replace(typeof(IAssembliesResolver), resolver); return new HttpServer(configuration); }
public void ODataModelBinderProvider_Works_OtherParameters(string action, string parameterName, string parameterValue) { // Arrange HttpConfiguration configuration = new HttpConfiguration(); configuration.Services.Replace(typeof(ModelBinderProvider), new ODataModelBinderProvider()); configuration.MapODataServiceRoute("odata", "", GetEdmModel()); var controllers = new[] { typeof(ODataModelBinderProviderTestODataController) }; TestAssemblyResolver resolver = new TestAssemblyResolver(new MockAssembly(controllers)); configuration.Services.Replace(typeof(IAssembliesResolver), resolver); HttpServer server = new HttpServer(configuration); HttpClient client = new HttpClient(server); // Act string url = String.Format("http://localhost/{0}({1}=@p)?@p={2}", action, parameterName, parameterValue); HttpResponseMessage response = client.GetAsync(url).Result; // Assert response.EnsureSuccessStatusCode(); }
public void ODataModelBinderProvider_Works_ForNullableEnum(object value, bool expect) { // Arrange HttpConfiguration configuration = new HttpConfiguration(); configuration.Services.Replace(typeof(ModelBinderProvider), new ODataModelBinderProvider()); configuration.MapODataServiceRoute("odata", "", GetEdmModel()); var controllers = new[] { typeof(ODataModelBinderProviderTestODataController) }; TestAssemblyResolver resolver = new TestAssemblyResolver(new MockAssembly(controllers)); configuration.Services.Replace(typeof(IAssembliesResolver), resolver); HttpServer server = new HttpServer(configuration); HttpClient client = new HttpClient(server); // Act string url = String.Format( "http://localhost/GetNullableFlagsEnum(flagsEnum={0})", value == null ? "null" : Uri.EscapeDataString(ConventionsHelpers.GetUriRepresentationForValue(value))); HttpResponseMessage response = client.GetAsync(url).Result; // Assert response.EnsureSuccessStatusCode(); Assert.Equal( expect, response.Content.ReadAsAsync(typeof(bool), configuration.Formatters).Result); }