コード例 #1
0
        public async Task ReturnConflictUpdateDescriptionByBodyAndRouteRouteWin()
        {
            // Act
            string chartUpdate = "TestChart";
            var    originalChartSerialization = await GetApiResponseString("api/WFCharts/" + chartUpdate);

            WFChart originalChart = JsonConvert.DeserializeObject <WFChart>(originalChartSerialization);

            string originalDesc = originalChart.ChartDescription;
            string routeDesc    = "_RouteDescription";
            string bodyDesc     = "_BodyDescription";

            WFChart updatedBodyChart = new WFChart  {
                ChartId = 0, ChartName = originalChart.ChartName, ChartDescription = bodyDesc
            };
            string bodyWithDescription = JsonConvert.SerializeObject(updatedBodyChart);

            var respObj = await SendUpdateRequest("api/WFCharts/" + chartUpdate + "/" + routeDesc, bodyWithDescription);

            int returnedCode = (int)respObj.StatusCode;

            Assert.True((returnedCode >= 200) && (returnedCode <= 299), "Returned code for Update send do not indicate success");

            var updateContent = await respObj.Content.ReadAsStringAsync();

            WFChart respChart = JsonConvert.DeserializeObject <WFChart>(updateContent);

            //cleaning up
            Assert.True((respChart.ChartDescription == routeDesc), "In case of discrepancy between body and route preference to route");
            var cleanObj = await SendUpdateRequest("api/WFCharts/" + chartUpdate + "/", "");

            var cleanContent = await cleanObj.Content.ReadAsStringAsync();
        }
コード例 #2
0
        public async Task ReturnSuccessUpdateChartDescriptionByRoute()
        {
            // Act
            string chartUpdate = "TestChart";
            var    originalChartSerialization = await GetApiResponseString("api/WFCharts/" + chartUpdate);

            WFChart originalChart = JsonConvert.DeserializeObject <WFChart>(originalChartSerialization);

            string returnedDesc = originalChart.ChartDescription;
            string updatedDesc  = returnedDesc + "_1234567890";

            var respObj = await SendUpdateRequest("api/WFCharts/" + chartUpdate + "/" + updatedDesc, "");

            var responseContent = await respObj.Content.ReadAsStringAsync();

            int returnedUpdCode = (int)respObj.StatusCode;

            Assert.True((returnedUpdCode >= 200 && returnedUpdCode <= 299), "Update Chart by route not success");
            WFChart updateReturnedChart = JsonConvert.DeserializeObject <WFChart>(responseContent);

            Assert.True(updateReturnedChart.ChartName == chartUpdate, "returned wrong ChartName");
            Assert.True(updateReturnedChart.ChartDescription == updatedDesc, "returned wrong ChartDescription");

            var restoreObj  = SendUpdateRequest("api/WFCharts", originalChartSerialization);
            int restoreCode = (int)restoreObj.Result.StatusCode;

            Assert.True(restoreCode == 200, "Chart was not restored to original state");
        }
コード例 #3
0
        private async Task CreateDeleteChartByName(string newChart)
        {
            string newChartJson = "{\"ChartId\":3,\"ChartName\":\"" + newChart + "\",\"ChartDescription\":null}";
            var    returnedPost = await PostApiResponseString("api/WFCharts", newChartJson);

            int returnedCode = (int)returnedPost.StatusCode;

            Assert.True((returnedCode >= 200) && (returnedCode <= 299), "Returned code for Create post do not indicate success");

            string actual = await returnedPost.Content.ReadAsStringAsync();

            var actualChart = JsonConvert.DeserializeObject <WFChart>(actual);
            var chartId     = actualChart.ChartId;

            Assert.NotEmpty(chartId.ToString());

            string  expected      = newChartJson;
            WFChart expectedChart = JsonConvert.DeserializeObject <WFChart>(expected);

            Assert.Equal(expectedChart.ChartName, actualChart.ChartName);
            Assert.Equal(expectedChart.ChartDescription, actualChart.ChartDescription);

            var ret = await SendDeleteRequest("api/WFCharts/", newChart);

            int returnedDelCode = (int)ret.StatusCode;

            Assert.True((returnedDelCode >= 200) && (returnedDelCode <= 299), "Returned code for Delete send do not indicate success");
        }
コード例 #4
0
        public async Task ReturnSuccessUpdateChartDescriptionByBody()
        {
            // Act
            var originalChartSerialization = await GetApiResponseString("api/WFCharts/TestChart");

            WFChart returnedChart = JsonConvert.DeserializeObject <WFChart>(originalChartSerialization);

            string  returnedDesc = returnedChart.ChartDescription;
            string  updatedDesc  = returnedDesc + "_1234567890";
            WFChart updatedChart = new WFChart {
                ChartId = 0, ChartName = returnedChart.ChartName, ChartDescription = updatedDesc
            };

            updatedChart.ChartName = returnedChart.ChartName;
            string sendBody = JsonConvert.SerializeObject(updatedChart);

            var respObj       = SendUpdateRequest("api/WFCharts", sendBody);
            var updateContent = await respObj.Result.Content.ReadAsStringAsync();

            int returnedCode = (int)respObj.Result.StatusCode;

            Assert.True(returnedCode == 200, "Not returned Success from update attempt");
            WFChart updateReturnedChart = JsonConvert.DeserializeObject <WFChart>(updateContent);

            Assert.True(updateReturnedChart.ChartName == updatedChart.ChartName, "Update request returned mismatched ChartName");
            Assert.True(updateReturnedChart.ChartDescription == updatedChart.ChartDescription, "Update request returned mismatched ChartDescription");

            var restoreObj  = SendUpdateRequest("api/WFCharts", originalChartSerialization);
            int restoreCode = (int)restoreObj.Result.StatusCode;

            Assert.True(restoreCode == 200, "Chart was not restored to original state");
        }
コード例 #5
0
 public async Task <IActionResult> PostWFChartRoute([FromRoute] WFChart wfChart)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     return(await ProcessInsertUpdate(wfChart));
 }
コード例 #6
0
        public async Task ReturnSuccessReadingExistingChartSingleByName()
        {
            // Act
            var actual = await GetApiResponseString("api/WFCharts/TestChart");

            // Assert
            //string expected = "{\"chartId\":1,\"chartName\":\"TestChart\",\"chartDescription\":null}";
            WFChart expectedChart = new WFChart {
                ChartId = 1, ChartName = "TestChart", ChartDescription = ""
            };
            WFChart actualChart = JsonConvert.DeserializeObject <WFChart>(actual);

            Assert.Equal(expectedChart.ChartId, actualChart.ChartId);
            Assert.Equal(expectedChart.ChartName, actualChart.ChartName);
        }
コード例 #7
0
        public async Task <IActionResult> GetWFChart([FromRoute] string ChartName)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            WFChart wFChart = await _repository.Get(ChartName);

            if (wFChart == null)
            {
                return(NotFound(string.Format("Not found Chart Name '{0}'", ChartName)));
            }

            return(Ok(wFChart));
        }
コード例 #8
0
        private async Task <IActionResult> ProcessInsertUpdate(WFChart wfChart)
        {
            try
            {
                //Task<WFChart>
                WFChart resultChart = await _repository.Save(wfChart);

                var ret = Ok(resultChart);
                return(ret);
            }
            catch (Exception e)
            {
                var ret = BadRequest(string.Format("Problem on new chart creation: \"{0}\" " + e.Message, wfChart.ChartName));
                ret.StatusCode = (int)HttpStatusCode.Conflict;
                return(ret);
            }
        }