예제 #1
0
        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)));
        }
예제 #2
0
        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)));
        }
예제 #3
0
        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);
        }