Esempio n. 1
0
        public async Task Test_Put_Cohort()
        {
            string name = "Cohort 101";

            using (var client = new APIClientProvider().Client)
            {
                Cohort modifiedCohort = new Cohort
                {
                    Name = name
                };
                var cohortJson = JsonConvert.SerializeObject(modifiedCohort);

                var response = await client.PutAsync(
                    "/api/cohorts/4",
                    new StringContent(cohortJson, Encoding.UTF8, "application/json")
                    );

                string responseBody = await response.Content.ReadAsStringAsync();

                Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);

                var getCohort = await client.GetAsync("/api/cohorts/4");

                getCohort.EnsureSuccessStatusCode();

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

                Cohort newCohort = JsonConvert.DeserializeObject <Cohort>(getCohortBody);

                Assert.Equal(HttpStatusCode.OK, getCohort.StatusCode);
                Assert.Equal(name, newCohort.Name);
            }
        }
Esempio n. 2
0
        public async Task Test_Put_Exercise()
        {
            string name = "Back-end Final Project";

            using (var client = new APIClientProvider().Client)
            {
                Exercise modifiedExercise = new Exercise
                {
                    Name     = name,
                    Language = "C#"
                };
                var exerciseJson = JsonConvert.SerializeObject(modifiedExercise);

                var response = await client.PutAsync(
                    "/api/exercises/7",
                    new StringContent(exerciseJson, Encoding.UTF8, "application/json")
                    );

                string responseBody = await response.Content.ReadAsStringAsync();

                Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);

                var getExercise = await client.GetAsync("/api/exercises/7");

                getExercise.EnsureSuccessStatusCode();

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

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

                Assert.Equal(HttpStatusCode.OK, getExercise.StatusCode);
                Assert.Equal(name, newExercise.Name);
            }
        }
Esempio n. 3
0
        public async Task Test_Put_Instructor()
        {
            string newFirstName = "Andrew";

            using (var client = new APIClientProvider().Client)
            {
                Instructor modifiedInstructor = new Instructor
                {
                    FirstName   = newFirstName,
                    LastName    = "Collins",
                    SlackHandle = "acollins",
                    CohortId    = 1
                };
                var instructorJson = JsonConvert.SerializeObject(modifiedInstructor);

                var response = await client.PutAsync(
                    "/api/instructors/1",
                    new StringContent(instructorJson, Encoding.UTF8, "application/json")
                    );

                string responseBody = await response.Content.ReadAsStringAsync();

                Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);

                var getInstructor = await client.GetAsync("/api/instructors/1");

                getInstructor.EnsureSuccessStatusCode();

                string getInstructorBody = await getInstructor.Content.ReadAsStringAsync();

                Student newInstructor = JsonConvert.DeserializeObject <Student>(getInstructorBody);

                Assert.Equal(HttpStatusCode.OK, getInstructor.StatusCode);
                Assert.Equal(newFirstName, newInstructor.FirstName);
            }
        }
        public async Task Test_Put_Student()
        {
            string newFirstName = "Bob";

            using (var client = new APIClientProvider().Client)
            {
                Student modifiedStudent = new Student
                {
                    FirstName   = newFirstName,
                    LastName    = "Bryant",
                    SlackHandle = "colebryant",
                    CohortId    = 1
                };
                var studentJson = JsonConvert.SerializeObject(modifiedStudent);

                var response = await client.PutAsync(
                    "/api/students/1",
                    new StringContent(studentJson, Encoding.UTF8, "application/json")
                    );

                string responseBody = await response.Content.ReadAsStringAsync();

                Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);

                var getStudent = await client.GetAsync("/api/students/1");

                getStudent.EnsureSuccessStatusCode();

                string getStudentBody = await getStudent.Content.ReadAsStringAsync();

                Student newStudent = JsonConvert.DeserializeObject <Student>(getStudentBody);

                Assert.Equal(HttpStatusCode.OK, getStudent.StatusCode);
                Assert.Equal(newFirstName, newStudent.FirstName);
            }
        }