public async Task Test_Delete_Student() { using (var client = new APIClientProvider().Client) { var response = await client.DeleteAsync("/api/student/9"); string responseBody = await response.Content.ReadAsStringAsync(); var Student = JsonConvert.DeserializeObject <Student>(responseBody); /* * ASSERT */ Assert.Equal(HttpStatusCode.OK, response.StatusCode); } }
public async Task Test_Modify_Student() { // New last name to change to and test string newLastName = "SoFly"; using (var client = new APIClientProvider().Client) { /* * PUT section */ Student modifiedAllison = new Student { FirstName = "Allison", LastName = newLastName, SlackHandle = "alpal26", CohortId = 3 }; var modifiedJAllisonAsJSON = JsonConvert.SerializeObject(modifiedAllison); var response = await client.PutAsync( "/api/student/9", new StringContent(modifiedJAllisonAsJSON, Encoding.UTF8, "application/json") ); string responseBody = await response.Content.ReadAsStringAsync(); Assert.Equal(HttpStatusCode.NoContent, response.StatusCode); /* * GET section * Verify that the PUT operation was successful */ var getAllison = await client.GetAsync("/api/student/9"); getAllison.EnsureSuccessStatusCode(); string getAllisonBody = await getAllison.Content.ReadAsStringAsync(); Student newAllison = JsonConvert.DeserializeObject <Student>(getAllisonBody); Assert.Equal(HttpStatusCode.OK, getAllison.StatusCode); Assert.Equal(newLastName, newAllison.LastName); } }
public async Task Test_Insert_A_Cohort() { using (var client = new APIClientProvider().Client) { Cohort Cohort32 = new Cohort { Name = "Cohort32" }; var Cohort32AsJSON = JsonConvert.SerializeObject(Cohort32); var response = await client.PostAsync( "/api/cohort", new StringContent(Cohort32AsJSON, Encoding.UTF8, "application/json") ); string responseBody = await response.Content.ReadAsStringAsync(); var newCohort32 = JsonConvert.DeserializeObject <Cohort>(responseBody); Assert.Equal(HttpStatusCode.Created, response.StatusCode); Assert.Equal("Cohort32", newCohort32.Name); } }