Beispiel #1
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);
            }
        }