public static void ValidDELETECategoryRequest(string Endpoint, int Id) { string JSONPayload = "{\"id\":0,\"name\":\"Engineering\"}"; var REST = new RESTClient(BaseURL); REST.AddNewCategory(Endpoint, JSONPayload); var APIValidresponse = REST.DeleteEntry(Endpoint + Id); //Check response status code Assert.AreEqual(204, (int)APIValidresponse.StatusCode, "Status Code 204 Expected."); //check response headers Assert.AreEqual("application/json", APIValidresponse.ContentType, "Response content-type Header error"); //Check response body Assert.IsEmpty(APIValidresponse.Content, "Response body is empty"); //Check category no longer available var APIResponse = REST.GetCategoryList(Endpoint); var CategoriesList = JsonConvert.DeserializeObject <List <ListOfCategories> >(APIResponse.Content); for (int i = 0; i < CategoriesList.Count; i++) { if (CategoriesList[i].Name == "Engineering") { Assert.Fail("Deleted category can still be viewed"); } } }
public static void ValidPOSTNewCategoryRequest(string Endpoint, string Category) { string JSONPayload = "{\"id\":0,\"name\":\"" + Category + "\"}"; var REST = new RESTClient(BaseURL); var APIResponse = REST.AddNewCategory(Endpoint, JSONPayload); //Check stats code response Assert.AreEqual(201, (int)APIResponse.StatusCode, "Status Code 201 Expected."); //checked REST response headers Assert.AreEqual("application/json", APIResponse.ContentType, "Response content-type Header error"); //Check new category added var ListResponse = REST.GetCategoryList(Endpoint); var CategoriesList = JsonConvert.DeserializeObject <List <ListOfCategories> >(ListResponse.Content); int LastEntry = CategoriesList.Count; Assert.That(CategoriesList[LastEntry - 1].Name, Is.EqualTo("Engineering"), "Name attribute value differs from expected"); }