public async Task TestPutExercise()
        {
            using (var client = new APIClientProvider().Client)
            {
                // PUT section
                Exercise updatedExercise = new Exercise
                {
                    Name     = "Chicken Monkey",
                    Language = "JavaScript"
                };

                var modifiedExerciseAsJSON = JsonConvert.SerializeObject(updatedExercise);

                var response = await client.PutAsync("api/exercise/1",
                                                     new StringContent(modifiedExerciseAsJSON, 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 getExercise = await client.GetAsync("api/exercise/1");

                getExercise.EnsureSuccessStatusCode();

                string getExerciseBody = await getExercise.Content.ReadAsStringAsync();

                Exercise newExercise = JsonConvert.DeserializeObject <Exercise>(getExerciseBody);

                Assert.Equal(HttpStatusCode.OK, getExercise.StatusCode);
                Assert.Equal("JavaScript", updatedExercise.Language);
            }
        }
Esempio n. 2
0
        public async Task TestPutCohort()
        {
            // new Name to change to and test
            string name = "Day 33";

            using (var client = new APIClientProvider().Client)
            {
                // PUT section
                Cohort updatedCohort = new Cohort
                {
                    Name = name
                };

                var modifiedCohortAsJSON = JsonConvert.SerializeObject(updatedCohort);
                var response             = await client.PutAsync(
                    "api/cohort/1",
                    new StringContent(modifiedCohortAsJSON, 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 getCohort = await client.GetAsync("/api/cohort/1");

                getCohort.EnsureSuccessStatusCode();
                string getCohortBody = await getCohort.Content.ReadAsStringAsync();

                var cohortList = JsonConvert.DeserializeObject <List <Cohort> >(getCohortBody);

                Assert.Equal(HttpStatusCode.OK, getCohort.StatusCode);
                Assert.Equal(name, cohortList[0].Name);
            }
        }
        public async Task Test_Modify_Student()
        {
            // We're going to change a student's name! This is their new name.
            string newFirstName = "Super cool dude";

            using (HttpClient client = new APIClientProvider().Client)
            {
                // Create a new student
                Student newDavid = await createDavid(client);

                // Change their first name
                newDavid.FirstName = newFirstName;

                // Convert them to JSON
                string modifiedDavidAsJSON = JsonConvert.SerializeObject(newDavid);

                // Make a PUT request with the new info
                HttpResponseMessage response = await client.PutAsync(
                    $"api/students/{newDavid.Id}",
                    new StringContent(modifiedDavidAsJSON, Encoding.UTF8, "application/json")
                    );


                response.EnsureSuccessStatusCode();

                // Convert the response to JSON
                string responseBody = await response.Content.ReadAsStringAsync();

                // We should have gotten a no content status code
                Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);

                /*
                 *  GET section
                 */
                // Try to GET the student we just edited
                HttpResponseMessage getDavid = await client.GetAsync($"api/students/{newDavid.Id}");

                getDavid.EnsureSuccessStatusCode();

                string getDavidBody = await getDavid.Content.ReadAsStringAsync();

                Student modifiedDavid = JsonConvert.DeserializeObject <Student>(getDavidBody);

                Assert.Equal(HttpStatusCode.OK, getDavid.StatusCode);

                // Make sure his name was in fact updated
                Assert.Equal(newFirstName, modifiedDavid.FirstName);

                // Clean up after ourselves- delete him
                deleteDavid(modifiedDavid, client);
            }
        }
Esempio n. 4
0
        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);
            }
        }
Esempio n. 7
0
        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);
            }
        }
Esempio n. 8
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);
            }
        }
Esempio n. 9
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);
            }
        }
Esempio n. 10
0
        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);
            }
        }