private async Task AsyncActionCall(bool isqualified, Action <HttpConfiguration, HttpServer> registerOData) { NorthwindContext ctx = GetDbContext(); Product product = ctx.Products.First(); var productID = product.ProductID; var price = product.UnitPrice; var response = await ODataTestHelpers.GetResponseNoContentValidation( isqualified? string.Format("http://localhost/api/Northwind/Products({0})/IncreasePriceAsync", productID) : string.Format("http://localhost/api/Northwind/Products({0})/Microsoft.OData.Service.Sample.Northwind.Models.IncreasePriceAsync", productID), HttpMethod.Post, new StringContent(@"{""diff"":2}", UTF8Encoding.Default, "application/json"), registerOData, HttpStatusCode.NoContent, null); var getResponse = await ODataTestHelpers.GetResponseNoContentValidation( string.Format("http://localhost/api/Northwind/Products({0})", productID), HttpMethod.Get, null, (config, server) => { WebApiConfig.RegisterNorthwind(config, server); }, HttpStatusCode.OK, null); }
public async Task VerifyQuery() { await PopulateData(1); using (var response = await ODataTestHelpers .GetResponseNoContentValidation(@"http://local/api/Prim/Dates(1)", HttpMethod.Get, null, RegisterApi, HttpStatusCode.OK)) { } }
private async Task FunctionCall(bool isqualified, Action <HttpConfiguration, HttpServer> registerOData) { var response = await ODataTestHelpers.GetResponseNoContentValidation( isqualified? "http://localhost/api/Northwind/Products/Microsoft.OData.Service.Sample.Northwind.Models.MostExpensive" : "http://localhost/api/Northwind/Products/MostExpensive", HttpMethod.Get, null, registerOData, HttpStatusCode.OK, null); }
public async Task VerifyChange() { await PopulateData(42); { dynamic newObj = new ExpandoObject(); newObj.DateProperty = "2016-01-04"; newObj.DTProperty = DateTime.UtcNow; newObj.DTOProperty = DateTimeOffset.Now; newObj.TODProperty = "08:09:10"; newObj.TSProperty = "PT4H12M"; string newOrderContent = JsonConvert.SerializeObject(newObj); StringContent content = new StringContent(newOrderContent, UTF8Encoding.Default, "application/json"); using (var response = await ODataTestHelpers .GetResponseNoContentValidation(@"http://local/api/Prim/Dates(42)", HttpMethod.Put, content, RegisterApi, HttpStatusCode.NoContent)) { using (var ctx = new PrimitivesContext()) { var item42 = ctx.Dates.First(e => e.RowId == 42); Assert.Equal(new DateTime(2016, 1, 4), item42.DateProperty); Assert.Equal(new TimeSpan(8, 9, 10), item42.TODProperty); Assert.Equal(new TimeSpan(4, 12, 0), item42.TSProperty); } } } { dynamic newObj = new ExpandoObject(); newObj.DateProperty = "2016-01-04"; newObj.DTProperty = DateTime.UtcNow; newObj.DTOProperty = DateTimeOffset.Now; newObj.RowId = 1024; newObj.TODProperty = "08:09:10"; newObj.TSProperty = "PT4H12M"; string newOrderContent = JsonConvert.SerializeObject(newObj); StringContent content = new StringContent(newOrderContent, UTF8Encoding.Default, "application/json"); using (var response = await ODataTestHelpers .GetResponseNoContentValidation(@"http://local/api/Prim/Dates", HttpMethod.Post, content, RegisterApi, HttpStatusCode.Created)) { var ret = await response.Content.ReadAsAsync <DateItem>(); Assert.Equal(new DateTime(2016, 1, 4), ret.DateProperty); Assert.Equal(new TimeSpan(8, 9, 10), ret.TODProperty); Assert.Equal(new TimeSpan(4, 12, 0), ret.TSProperty); using (var ctx = new PrimitivesContext()) { ret = ctx.Dates.First(e => e.RowId == 1024); Assert.Equal(new DateTime(2016, 1, 4), ret.DateProperty); Assert.Equal(new TimeSpan(8, 9, 10), ret.TODProperty); Assert.Equal(new TimeSpan(4, 12, 0), ret.TSProperty); } } } { dynamic newObj = new ExpandoObject(); newObj.DateProperty = "2017-01-04"; newObj.TODProperty = "10:09:08"; newObj.TSProperty = "PT4H32M"; string newOrderContent = JsonConvert.SerializeObject(newObj); StringContent content = new StringContent(newOrderContent, UTF8Encoding.Default, "application/json"); using (var response = await ODataTestHelpers .GetResponseNoContentValidation(@"http://local/api/Prim/Dates(1024)", new HttpMethod("Patch"), content, RegisterApi, HttpStatusCode.NoContent)) { using (var ctx = new PrimitivesContext()) { var ret = ctx.Dates.First(e => e.RowId == 1024); Assert.NotNull(ret.DTProperty); Assert.NotEqual(default(DateTimeOffset), ret.DTOProperty); Assert.Equal(new DateTime(2017, 1, 4), ret.DateProperty); Assert.Equal(new TimeSpan(10, 9, 8), ret.TODProperty); Assert.Equal(new TimeSpan(4, 32, 0), ret.TSProperty); } } } }