public async Task Get_OpenEntityType(bool enableNullDynamicProperty) { // Arrange const string RequestUri = "http://localhost/odata/SimpleOpenCustomers(9)"; var controllers = new[] { typeof(SimpleOpenCustomersController) }; var server = TestServerFactory.Create(controllers, (config) => { config.SetSerializeNullDynamicProperty(enableNullDynamicProperty); config.MapODataServiceRoute("odata", "odata", GetEdmModel()); }); var client = TestServerFactory.CreateClient(server); // Act HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, RequestUri); request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/json;odata.metadata=full")); HttpResponseMessage response = await client.SendAsync(request); // Assert Assert.True(response.IsSuccessStatusCode); JObject result = JObject.Parse(await response.Content.ReadAsStringAsync()); Assert.Equal("http://localhost/odata/$metadata#SimpleOpenCustomers/Microsoft.Test.AspNet.OData.Common.SimpleVipCustomer/$entity", result["@odata.context"]); Assert.Equal("#Microsoft.Test.AspNet.OData.Common.SimpleVipCustomer", result["@odata.type"]); Assert.Equal(9, result["CustomerId"]); Assert.Equal("VipCustomer", result["Name"]); Assert.Equal("#Collection(Int32)", result["*****@*****.**"]); Assert.Equal(new JArray(new[] { 200, 100, 300, 0, 400 }), result["ListProp"]); Assert.Equal("0001-01-01", result["DateList"][0]); Assert.Equal("9999-12-31", result["DateList"][1]); if (enableNullDynamicProperty) { Assert.NotNull(result["Receipt"]); Assert.Equal(JValue.CreateNull(), result["Receipt"]); } else { Assert.Null(result["Receipt"]); } }
private static HttpClient GetClient(TimeZoneInfo timeZoneInfo) { var controllers = new[] { typeof(MetadataController), typeof(DateTimeModelsController) }; var server = TestServerFactory.Create(controllers, (config) => { config.Count().OrderBy().Filter().Expand().MaxTop(null).Select(); if (timeZoneInfo != null) { config.SetTimeZoneInfo(timeZoneInfo); } else { config.SetTimeZoneInfo(TimeZoneInfo.Local); } config.MapODataServiceRoute("odata", "odata", GetEdmModel()); }); return(TestServerFactory.CreateClient(server)); }
public async Task Post_UnTyped_OpenEntityType() { // Arrange const string Payload = "{" + "\"@odata.context\":\"http://localhost/odata/$metadata#UntypedSimpleOpenCustomers/$entity\"," + "\"CustomerId\":6,\"[email protected]\":\"#String\",\"Name\":\"FirstName 6\"," + "\"Address\":{" + "\"@odata.type\":\"#NS.Address\",\"Street\":\"Street 6\",\"City\":\"City 6\"" + "}," + "\"[email protected]\":\"#Collection(NS.Address)\"," + "\"Addresses\":[{" + "\"@odata.type\":\"#NS.Address\",\"Street\":\"Street 7\",\"City\":\"City 7\"" + "}]," + "\"[email protected]\":\"#Collection(Double)\"," + "\"DoubleList\":[5.5, 4.4, 3.3]," + "\"[email protected]\":\"#NS.Color\"," + "\"FavoriteColor\":\"Red\"," + "\"Color\":\"Red\"," + "\"[email protected]\":\"#Collection(NS.Color)\"," + "\"FavoriteColors\":[\"0\", \"1\"]" + "}"; var controllers = new[] { typeof(UntypedSimpleOpenCustomersController) }; var server = TestServerFactory.Create(controllers, (config) => { config.MapODataServiceRoute("odata", "odata", GetUntypedEdmModel()); }); var client = TestServerFactory.CreateClient(server); // Act HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, _untypedCustomerRequestRooturl); request.Content = new StringContent(Payload); request.Content.Headers.ContentType = MediaTypeWithQualityHeaderValue.Parse("application/json"); HttpResponseMessage response = await client.SendAsync(request); // Assert Assert.True(response.IsSuccessStatusCode); }
private static System.Web.Http.HttpServer CreateServer(string customersEntitySet) #endif { // We need to do this to avoid controllers with incorrect attribute // routing configuration in this assembly that cause an exception to // be thrown at runtime. With this, we restrict the test to the following // set of controllers. Type[] controllers = new Type[] { typeof(OnlyFilterAllowedCustomersController), typeof(OnlyFilterAndEqualsAllowedCustomersController), typeof(FilterDisabledCustomersController), typeof(EverythingAllowedCustomersController), typeof(OtherLimitationsCustomersController), }; ODataModelBuilder builder = ODataConventionModelBuilderFactory.Create(); builder.EntitySet <EnableQueryCustomer>(customersEntitySet); builder.EntityType <PremiumEnableQueryCustomer>(); builder.EntitySet <EnableQueryCategory>("EnableQueryCategories"); builder.EntityType <PremiumEnableQueryCategory>(); builder.EntitySet <EnableQueryOrder>("EnableQueryOrders"); builder.EntityType <DiscountedEnableQueryOrder>(); builder.EntitySet <EnableQueryOrderLine>("EnableQueryOrderLines"); builder.ComplexType <EnableQueryAddress>(); IEdmModel model = builder.GetEdmModel(); return(TestServerFactory.Create(controllers, (config) => { config.MapODataServiceRoute("odata", "odata", model); config.Count().OrderBy().Filter().Expand().MaxTop(null).Select(); })); }
public async Task Post_OpenEntityType() { // Arrange const string Payload = "{" + "\"@odata.context\":\"http://localhost/odata/$metadata#OpenCustomers/$entity\"," + "\"CustomerId\":6,\"Name\":\"FirstName 6\"," + "\"Address\":{" + "\"Street\":\"Street 6\",\"City\":\"City 6\",\"Place\":\"Earth\",\"[email protected]\":\"#Guid\"," + "\"Token\":\"4DB52263-4382-4BCB-A63E-3129C1B5FA0D\"," + "\"Number\":990" + "}," + "\"Website\": \"WebSite #6\"," + "\"[email protected]\":\"#String\",\"Place\":\"My Dynamic Place\"," + // odata.type is necessary, otherwise it will get an ODataUntypedValue "\"[email protected]\":\"#Guid\",\"Token\":\"2c1f450a-a2a7-4fe1-a25d-4d9332fc0694\"," + "\"[email protected]\":\"#Collection(Double)\"," + "\"DoubleList\":[5.5, 4.4, 3.3]" + "}"; const string RequestUri = "http://localhost/odata/SimpleOpenCustomers"; var controllers = new[] { typeof(SimpleOpenCustomersController) }; var server = TestServerFactory.Create(controllers, (config) => { config.MapODataServiceRoute("odata", "odata", GetEdmModel()); }); var client = TestServerFactory.CreateClient(server); // Act HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, RequestUri); request.Content = new StringContent(Payload); request.Content.Headers.ContentType = MediaTypeWithQualityHeaderValue.Parse("application/json"); HttpResponseMessage response = await client.SendAsync(request); // Assert Assert.True(response.IsSuccessStatusCode); }
public async Task CanDispatch_ActionPayload_With_EdmEnumObject() { const string RequestUri = "http://localhost/odata/UntypedSimpleOpenCustomers(1)/NS.AddColor"; const string Payload = @"{ ""Color"": ""0"" }"; var controllers = new[] { typeof(UntypedSimpleOpenCustomersController) }; var server = TestServerFactory.Create(controllers, (config) => { config.MapODataServiceRoute("odata", "odata", GetUntypedEdmModel()); }); var client = TestServerFactory.CreateClient(server); // Act HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, RequestUri); request.Content = new StringContent(Payload); request.Content.Headers.ContentType = MediaTypeWithQualityHeaderValue.Parse("application/json"); HttpResponseMessage response = await client.SendAsync(request); // Assert Assert.True(response.IsSuccessStatusCode); }
public async Task NullableEnumParameter_Works_WithNullEnumValue() { // Arrange const string expect = "{" + "\"@odata.context\":\"http://localhost/odata/$metadata#Edm.Boolean\",\"value\":false" + "}"; var controllers = new[] { typeof(NullableEnumValueController) }; var server = TestServerFactory.Create(controllers, (config) => { config.MapODataServiceRoute("odata", "odata", GetSampleModel()); }); HttpClient client = TestServerFactory.CreateClient(server); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/odata/NullableEnumFunction(ColorParameter=null)"); // Act HttpResponseMessage respone = await client.SendAsync(request); // Assert Assert.Equal(expect, await respone.Content.ReadAsStringAsync()); }