private async Task ActionCall(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.GetResponse( isqualified? string.Format("http://localhost/api/Northwind/Products({0})/IncreasePrice", productID) : string.Format("http://localhost/api/Northwind/Products({0})/Microsoft.Restier.Samples.Northwind.Models.IncreasePrice", productID), HttpMethod.Post, new StringContent(@"{""diff"":2}", UTF8Encoding.Default, "application/json"), registerOData, null); Assert.Equal(HttpStatusCode.NoContent, response.StatusCode); var getResponse = await ODataTestHelpers.GetResponse( string.Format("http://localhost/api/Northwind/Products({0})", productID), HttpMethod.Get, null, (config, server) => { WebApiConfig.RegisterNorthwind(config, server); }, null); Assert.Equal(HttpStatusCode.OK, getResponse.StatusCode); var responseString = await BaselineHelpers.GetFormattedContent(getResponse); Assert.True(responseString.Contains(string.Format(@"""UnitPrice"":{0}", price + 2))); }
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); }
private async Task ActionCall(bool isqualified, Action <HttpConfiguration, HttpServer> registerOData) { var query = this.domain.Source <Product>("Products").OrderBy(p => p.ProductID).Take(1); QueryResult result = await this.domain.QueryAsync( new QueryRequest(query, true)); var product = result.Results.OfType <Product>().First(); var price = product.UnitPrice; var response = await ODataTestHelpers.GetResponse( isqualified? string.Format("http://localhost/api/Northwind/Products({0})/IncreasePrice", product.ProductID) : string.Format("http://localhost/api/Northwind/Products({0})/Microsoft.Restier.Samples.Northwind.Models.IncreasePrice", product.ProductID), HttpMethod.Post, new StringContent(@"{""diff"":2}", UTF8Encoding.Default, "application/json"), registerOData, null); Assert.Equal(HttpStatusCode.NoContent, response.StatusCode); var getResponse = await ODataTestHelpers.GetResponse( string.Format("http://localhost/api/Northwind/Products({0})", product.ProductID), HttpMethod.Get, null, (config, server) => { WebApiConfig.RegisterNorthwind(config, server); }, null); Assert.Equal(HttpStatusCode.OK, getResponse.StatusCode); var responseString = await BaselineHelpers.GetFormattedContent(getResponse); Assert.True(responseString.Contains(string.Format(@"""UnitPrice"":{0}", price + 2))); }
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)) { } }
public async Task VerifyQuery() { await PopulateData(1); using (var response = await ODataTestHelpers.GetResponse(@"http://local/api/Prim/Dates(1)", HttpMethod.Get, null, RegisterApi)) { Assert.Equal(HttpStatusCode.OK, response.StatusCode); var s = await response.Content.ReadAsStringAsync(); Assert.NotNull(s); } }
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); }
private async Task FunctionCall(bool isqualified, Action <HttpConfiguration, HttpServer> registerOData) { var response = await ODataTestHelpers.GetResponse( isqualified? "http://localhost/api/Northwind/Products/Microsoft.Restier.Samples.Northwind.Models.MostExpensive" : "http://localhost/api/Northwind/Products/MostExpensive", HttpMethod.Get, null, registerOData, null); var responseString = await BaselineHelpers.GetFormattedContent(response); Assert.Equal(HttpStatusCode.OK, response.StatusCode); }
public async Task TestCustomerKeyAsSegment() { // BLONP is the key for a customer var requestUri = "http://localhost/api/Northwind/Customers/BLONP"; //Enable Key as Segment HttpConfiguration httpConfig = new HttpConfiguration(); httpConfig.SetUrlKeyDelimiter(ODataUrlKeyDelimiter.Slash); Action <HttpConfiguration, HttpServer> registerOData = (config, server) => WebApiConfig.RegisterNorthwind(config, server); string baselineFileName = "TestCustomerKeyAsSegment"; using (HttpResponseMessage response = await ODataTestHelpers.GetResponseWithConfig(requestUri, HttpMethod.Get, null, httpConfig, registerOData, HttpStatusCode.OK, baselineFileName, null)) { } }
private static async Task TestODataRequest( string requestUri, HttpMethod httpMethod, HttpContent requestContent, HttpStatusCode expectedStatusCode, IEnumerable <KeyValuePair <string, string> > headers = null, Func <string, string> postProcessContentHandler = null, [CallerMemberName] string baselineFileName = "") { await ODataTestHelpers.TestRequest( requestUri, httpMethod, requestContent, expectedStatusCode, (config, server) => WebApiConfig.RegisterNorthwind(config, server), headers, postProcessContentHandler, baselineFileName); }
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.GetResponse(@"http://local/api/Prim/Dates(42)", HttpMethod.Put, content, RegisterApi)) { Assert.Equal(HttpStatusCode.NoContent, response.StatusCode); 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.GetResponse(@"http://local/api/Prim/Dates", HttpMethod.Post, content, RegisterApi)) { Assert.Equal(HttpStatusCode.Created, response.StatusCode); 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.GetResponse(@"http://local/api/Prim/Dates(1024)", new HttpMethod("Patch"), content, RegisterApi)) { Assert.Equal(HttpStatusCode.NoContent, response.StatusCode); 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); } } } }