public async Task TestGetStudentsWithExercise() { using (var client = new APIClientProvider().Client) { // Arrange // Act var response = await client.GetAsync("/api/student?include=exercise"); string responseBody = await response.Content.ReadAsStringAsync(); var studentList = JsonConvert.DeserializeObject <List <Student> >(responseBody); // Assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.True(studentList.Count > 0); } }
public async Task Test_Get_Single_Student() { using (var client = new APIClientProvider().Client) { var response = await client.GetAsync("/student/1"); response.EnsureSuccessStatusCode(); string responseBody = await response.Content.ReadAsStringAsync(); var student = JsonConvert.DeserializeObject <Student>(responseBody); Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.Equal("Kate", student.FirstName); Assert.Equal("Williams", student.LastName); Assert.NotNull(student); } }
public async Task Test_Modify_Student() { // New last name to change to and test string newLastName = "Williams"; using (var client = new APIClientProvider().Client) { /* * PUT section */ Student modifiedKate = new Student { FirstName = "Kate", LastName = newLastName, CohortId = 1, SlackHandle = "@katerebekah" }; var modifiedKateAsJSON = JsonConvert.SerializeObject(modifiedKate); var response = await client.PutAsync( "/api/students/1", new StringContent(modifiedKateAsJSON, Encoding.UTF8, "application/json") ); response.EnsureSuccessStatusCode(); string responseBody = await response.Content.ReadAsStringAsync(); Assert.Equal(HttpStatusCode.NoContent, response.StatusCode); /* * GET section */ var getKate = await client.GetAsync("/api/students/1"); getKate.EnsureSuccessStatusCode(); string getKateBody = await getKate.Content.ReadAsStringAsync(); Student newKate = JsonConvert.DeserializeObject <Student>(getKateBody); Assert.Equal(HttpStatusCode.OK, getKate.StatusCode); Assert.Equal(newLastName, newKate.LastName); } }
public async Task Test_Modify_Student() { // New last name to change to and test string newStudentSlackHandle = "@annette2"; using (var client = new APIClientProvider().Client) { /* * PUT section */ Student modifiedStudent = new Student { FirstName = "Annette", LastName = "Browning", SlackHandle = newStudentSlackHandle, CohortId = 2 }; var modifiedStudentAsJSON = JsonConvert.SerializeObject(modifiedStudent); var response = await client.PutAsync( "/api/student/15", new StringContent(modifiedStudentAsJSON, 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 getStudent = await client.GetAsync("/api/student/15"); getStudent.EnsureSuccessStatusCode(); string getStudentBody = await getStudent.Content.ReadAsStringAsync(); Student newStudent = JsonConvert.DeserializeObject <Student>(getStudentBody); Assert.Equal(HttpStatusCode.OK, getStudent.StatusCode); Assert.Equal(newStudentSlackHandle, newStudent.SlackHandle); } }
public async Task Test_Modify_Exercise() { // New label name to change to and test string newLanguage = "Angular"; using (var client = new APIClientProvider().Client) { /* * PUT section */ Exercise modifiedKennel = new Exercise { Label = "Kennel", Language = newLanguage, }; var modifiedKennelAsJSON = JsonConvert.SerializeObject(modifiedKennel); var response = await client.PutAsync( "/api/exercise/9", new StringContent(modifiedKennelAsJSON, 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 getKennel = await client.GetAsync("/api/exercise/9"); getKennel.EnsureSuccessStatusCode(); string getKennelBody = await getKennel.Content.ReadAsStringAsync(); Exercise newKennel = JsonConvert.DeserializeObject <Exercise>(getKennelBody); Assert.Equal(HttpStatusCode.OK, getKennel.StatusCode); Assert.Equal(newLanguage, newKennel.Language); } }
public async Task Test_Modify_Exercise() { // New last name to change to and test string newExerciseName = "Trestlebridge Farms"; using (var client = new APIClientProvider().Client) { /* * PUT section */ Exercise modifiedExercise = new Exercise { ExerciseName = newExerciseName, ProgrammingLanguage = "C#" }; var modifiedExerciseAsJSON = JsonConvert.SerializeObject(modifiedExercise); var response = await client.PutAsync( "/api/exercise/4005", new StringContent(modifiedExerciseAsJSON, 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 getExercise = await client.GetAsync("/api/exercise/4005"); getExercise.EnsureSuccessStatusCode(); string getExerciseBody = await getExercise.Content.ReadAsStringAsync(); Exercise newExercise = JsonConvert.DeserializeObject <Exercise>(getExerciseBody); Assert.Equal(HttpStatusCode.OK, getExercise.StatusCode); Assert.Equal(newExerciseName, newExercise.ExerciseName); } }
public async Task Test_Get_Single_Cohort() { using (HttpClient client = new APIClientProvider().Client) { Cohort newCohort = await createCohortTest(client); HttpResponseMessage response = await client.GetAsync($"api/cohort/{newCohort.Id}"); response.EnsureSuccessStatusCode(); string responseBody = await response.Content.ReadAsStringAsync(); Cohort cohort = JsonConvert.DeserializeObject <Cohort>(responseBody); Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.Equal("Test", newCohort.Name); deleteTest(newCohort, client); } }
public async Task TestGetStudent() { using (var client = new APIClientProvider().Client) { // Arrange // Act var response = await client.GetAsync("/api/student/1"); string responseBody = await response.Content.ReadAsStringAsync(); var student = JsonConvert.DeserializeObject <Student>(responseBody); // Assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.True(student != null); Assert.True(student.FirstName.Length > 0); Assert.True(student.LastName.Length > 0); } }
public async Task TestPutInstructor() { // new SlackHandle to change to and test string slackHandle = "@MarkZ"; using (var client = new APIClientProvider().Client) { // PUT section Instructor updatedInstructor = new Instructor { FirstName = "Mark", LastName = "Zuckerberg", CohortId = 3, Specialty = "Wearing hoodies", SlackHandle = slackHandle }; var modifiedInstructorAsJSON = JsonConvert.SerializeObject(updatedInstructor); var response = await client.PutAsync("api/instructor/11", new StringContent(modifiedInstructorAsJSON, Encoding.UTF8, "application/json")); string responseBody = await response.Content.ReadAsStringAsync(); Assert.Equal(HttpStatusCode.OK, response.StatusCode); // GET section - verify that the PUT operation was successful var getInstructor = await client.GetAsync("/api/instructor/11"); getInstructor.EnsureSuccessStatusCode(); string getInstructorBody = await getInstructor.Content.ReadAsStringAsync(); Instructor newInstructor = JsonConvert.DeserializeObject <Instructor>(getInstructorBody); Assert.Equal(HttpStatusCode.OK, getInstructor.StatusCode); Assert.Equal(slackHandle, newInstructor.SlackHandle); } }
public async Task TestPutStudent() { // new FirstName to change to and test string FirstName = "Joseph"; using (var client = new APIClientProvider().Client) { // PUT section Student updatedStudent = new Student { FirstName = FirstName, LastName = "Snyder", SlackHandle = "JoeS", CohortId = 2 }; var modifiedStudentAsJSON = JsonConvert.SerializeObject(updatedStudent); var response = await client.PutAsync( "api/student/7", new StringContent(modifiedStudentAsJSON, Encoding.UTF8, "application/json")); string responseBody = await response.Content.ReadAsStringAsync(); Assert.Equal(HttpStatusCode.OK, response.StatusCode); // GET section - verify that the PUT operation was successful var getStudent = await client.GetAsync("/api/student/7"); getStudent.EnsureSuccessStatusCode(); string getStudentBody = await getStudent.Content.ReadAsStringAsync(); Student newStudent = JsonConvert.DeserializeObject <Student>(getStudentBody); Assert.Equal(HttpStatusCode.OK, getStudent.StatusCode); Assert.Equal(FirstName, newStudent.FirstName); } }
public async Task Test_Modify_Student() { int newCohortId = 1; using (var client = new APIClientProvider().Client) { Student modifiedJim = new Student { FirstName = "Michael", LastName = "Stiles", SlackHandle = "@michaelstiles", CohortId = newCohortId }; var modifiedJimAsJSON = JsonConvert.SerializeObject(modifiedJim); var response = await client.PutAsync( "/api/students/1", new StringContent(modifiedJimAsJSON, Encoding.UTF8, "application/json") ); string responseBody = await response.Content.ReadAsStringAsync(); Assert.Equal(HttpStatusCode.NoContent, response.StatusCode); var getJim = await client.GetAsync("/api/students/1"); getJim.EnsureSuccessStatusCode(); string getJimBody = await getJim.Content.ReadAsStringAsync(); Student newJim = JsonConvert.DeserializeObject <Student>(getJimBody); Assert.Equal(HttpStatusCode.OK, getJim.StatusCode); Assert.Equal(newCohortId, newJim.CohortId); } }
public async Task TestGetExercisesWithQIncludeStudents() { using (var client = new APIClientProvider().Client) { // Arrange // Act var response = await client.GetAsync("api/exercise?q=javascript&include=student"); string responseBody = await response.Content.ReadAsStringAsync(); try { List <Exercise> exerciseList = JsonConvert.DeserializeObject <List <Exercise> >(responseBody); } catch { Exercise exercise = JsonConvert.DeserializeObject <Exercise>(responseBody); } // Assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); } }
public async Task TestGetInstructorsWithQ() { using (var client = new APIClientProvider().Client) { // Arrange // Act var response = await client.GetAsync("/api/instructor?q=Bryan"); string responseBody = await response.Content.ReadAsStringAsync(); try { List <Instructor> instructorList = JsonConvert.DeserializeObject <List <Instructor> >(responseBody); } catch { var instructor = JsonConvert.DeserializeObject <Instructor>(responseBody); } // Assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); } }
public async Task TestGetCohortsWithQ() { using (var client = new APIClientProvider().Client) { // Arrange // Act var response = await client.GetAsync("/api/cohort?q=Day 34"); string responseBody = await response.Content.ReadAsStringAsync(); try { List <Cohort> cohortList = JsonConvert.DeserializeObject <List <Cohort> >(responseBody); } catch { var cohort = JsonConvert.DeserializeObject <Cohort>(responseBody); } // Assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); } }
public async Task Test_Get_All_Students() { // Use the http client using (HttpClient client = new APIClientProvider().Client) { // Call the route to get all our students; wait for a response object HttpResponseMessage response = await client.GetAsync("api/students"); response.EnsureSuccessStatusCode(); // Read the response body as JSON string responseBody = await response.Content.ReadAsStringAsync(); // Convert the JSON to a list of student instances List <Student> studentList = JsonConvert.DeserializeObject <List <Student> >(responseBody); // Did we get back a 200 OK status code? Assert.Equal(HttpStatusCode.OK, response.StatusCode); // Are there any students in the list? Assert.True(studentList.Count > 0); } }