public async Task Test_Modify_Cohort() { // New last name to change to and test string newCohortName = "Cohort40"; using (var client = new APIClientProvider().Client) { Cohort modifiedCohort = new Cohort { Id = 8, Name = newCohortName }; var modifiedCohortAsJSON = JsonConvert.SerializeObject(modifiedCohort); var response = await client.PutAsync( "/api/cohort/8", new StringContent(modifiedCohortAsJSON, Encoding.UTF8, "application/json") ); string responseBody = await response.Content.ReadAsStringAsync(); Assert.Equal(HttpStatusCode.NoContent, response.StatusCode); var getCohort = await client.GetAsync("/api/cohort/8"); getCohort.EnsureSuccessStatusCode(); string getCohortBody = await getCohort.Content.ReadAsStringAsync(); Cohort newCohort = JsonConvert.DeserializeObject <Cohort>(getCohortBody); Assert.Equal(HttpStatusCode.OK, getCohort.StatusCode); Assert.Equal(newCohortName, newCohort.Name); } }
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); } }