public async Task Test_Get_All_Students() { using (var client = new APIClientProvider().Client) { var response = await client.GetAsync("/api/students"); string responseBody = await response.Content.ReadAsStringAsync(); var studentList = JsonConvert.DeserializeObject <List <Student> >(responseBody); Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.True(studentList.Count > 0); } }
public async Task Test_Get_All_Cohorts() { using (HttpClient client = new APIClientProvider().Client) { HttpResponseMessage response = await client.GetAsync("api/cohort"); response.EnsureSuccessStatusCode(); string responseBody = await response.Content.ReadAsStringAsync(); List <Cohort> cohortList = JsonConvert.DeserializeObject <List <Cohort> >(responseBody); Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.True(cohortList.Count > 0); } }
public async Task Test_Get_Single_Student() { using (var client = new APIClientProvider().Client) { var response = await client.GetAsync("/api/students/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); } }
public async Task Test_Create_And_Delete_Student() { using (var client = new APIClientProvider().Client) { // Create a new David Student newDavid = await createDavid(client); // Make sure his info checks out Assert.Equal("David", newDavid.FirstName); Assert.Equal("Bird", newDavid.LastName); Assert.Equal("@david", newDavid.SlackHandle); // Clean up after ourselves - delete David! deleteDavid(newDavid, client); } }
public async Task Test_Create_And_Delete_Exercise() { using (var client = new APIClientProvider().Client) { // Create a new David Exercise newChickenMonkey = await createChickenMonkey(client); // Make sure his info checks out Assert.Equal("Chicken Monkey", newChickenMonkey.Name); Assert.Equal("Javascript", newChickenMonkey.Language); // Clean up after ourselves - delete David! deleteChickenMonkey(newChickenMonkey, client); } }
public async Task TestGetCohorts() { using (var client = new APIClientProvider().Client) { // Arrange // Act var response = await client.GetAsync("/api/cohort"); string responseBody = await response.Content.ReadAsStringAsync(); var cohortList = JsonConvert.DeserializeObject <List <Cohort> >(responseBody); // Assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.True(cohortList.Count > 0); } }
public async Task TestDeleteCohort() { using (var client = new APIClientProvider().Client) { int deleteId = 7; // Act var response = await client.DeleteAsync($"/api/cohort/{deleteId}"); string responseBody = await response.Content.ReadAsStringAsync(); var cohort = JsonConvert.DeserializeObject <Cohort>(responseBody); // Assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); } }
public async Task TestGetInstructor() { using (var client = new APIClientProvider().Client) { // Arrange // Act var response = await client.GetAsync("api/instructor/1"); string responseBody = await response.Content.ReadAsStringAsync(); var instructor = JsonConvert.DeserializeObject <Instructor>(responseBody); // Assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); //Assert.True(instructorList.Count > 0); } }
public async Task TestDeleteExercise() { using (var client = new APIClientProvider().Client) { int deleteId = 15; //id of exercise to delete // Act var response2 = await client.DeleteAsync($"/api/exercise/{deleteId}"); string responseBody2 = await response2.Content.ReadAsStringAsync(); Exercise exercise = JsonConvert.DeserializeObject <Exercise>(responseBody2); // Assert Assert.Equal(HttpStatusCode.OK, response2.StatusCode); } }
public async Task TestGetExercisesIncludeStudents() { using (var client = new APIClientProvider().Client) { // Arrange // Act var response = await client.GetAsync("/api/exercise?include=student"); string responseBody = await response.Content.ReadAsStringAsync(); List <Exercise> exerciseList = JsonConvert.DeserializeObject <List <Exercise> >(responseBody); // Assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.True(exerciseList.Count > 0); } }
public async Task TestGetExercise() { using (var client = new APIClientProvider().Client) { // Arrange // Act var response = await client.GetAsync("api/exercise/1"); string responseBody = await response.Content.ReadAsStringAsync(); var exercise = JsonConvert.DeserializeObject <Exercise>(responseBody); // Assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.Equal("Chicken Monkey", exercise.Name); } }
public async Task Test_Get_Single_Student() { using (var client = new APIClientProvider().Client) { var response = await client.GetAsync("/student/1"); 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-Spradlin", student.LastName); Assert.NotNull(student); } }
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_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_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 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 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 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 Test_Create_And_Delete_Student() { using (var client = new APIClientProvider().Client) { Student helen = new Student { FirstName = "Helen", LastName = "Chalmers", CohortId = 1, SlackHandle = "Helen Chalmers" }; var helenAsJSON = JsonConvert.SerializeObject(helen); var response = await client.PostAsync( "/api/students", new StringContent(helenAsJSON, Encoding.UTF8, "application/json") ); response.EnsureSuccessStatusCode(); string responseBody = await response.Content.ReadAsStringAsync(); var newHelen = JsonConvert.DeserializeObject <Student>(responseBody); Assert.Equal(HttpStatusCode.Created, response.StatusCode); Assert.Equal("Helen", newHelen.FirstName); Assert.Equal("Chalmers", newHelen.LastName); Assert.Equal("Helen Chalmers", newHelen.SlackHandle); var deleteResponse = await client.DeleteAsync($"/api/students/{newHelen.Id}"); deleteResponse.EnsureSuccessStatusCode(); Assert.Equal(HttpStatusCode.NoContent, deleteResponse.StatusCode); } }
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 TestGetStudentsWithQIncludeExercise() { using (var client = new APIClientProvider().Client) { // Arrange // Act var response = await client.GetAsync("/api/student?q=joseph&include=exercise"); string responseBody = await response.Content.ReadAsStringAsync(); try { var student = JsonConvert.DeserializeObject <Student>(responseBody); } catch { List <Student> studentList = JsonConvert.DeserializeObject <List <Student> >(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 TestPostStudent() { using (var client = new APIClientProvider().Client) { // Arrange // construct a new student object to be sent to the API Student newStudent = new Student { FirstName = "Aaron", LastName = "Rodgers", SlackHandle = "AaronR", CohortId = 1, Exercises = new List <Exercise>() }; // Serialize the C# object into a JSON string var newStudentAsJSON = JsonConvert.SerializeObject(newStudent); // Act // Use the client to send the request and store the response var response = await client.PostAsync("api/student", new StringContent(newStudentAsJSON, Encoding.UTF8, "application/json")); // Store the JSON body of the response string responseBody = await response.Content.ReadAsStringAsync(); // Deserialize the JSON into an instance of a Student var newStudentInstance = JsonConvert.DeserializeObject <Student>(responseBody); // Assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.Equal("Aaron", newStudentInstance.FirstName); Assert.Equal("Rodgers", newStudentInstance.LastName); Assert.Equal("AaronR", newStudentInstance.SlackHandle); Assert.Equal(1, newStudentInstance.CohortId); } }
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); } }