Esempio n. 1
0
        public async Task Update_Exercise()
        {
            using (var client = new APIClientProvider().Client)
            {
                // Create a dummy coffee
                Exercise moosehead = await CreateDummyExercise();

                // Make a new title and assign it to our dummy coffee
                string newName = "Moosehead";
                moosehead.Name = newName;

                // Convert it to JSON
                string modifiedmooseheadAsJSON = JsonConvert.SerializeObject(moosehead);

                // Try to PUT the newly edited coffee
                var response = await client.PutAsync(
                    $"{url}/{moosehead.Id}",
                    new StringContent(modifiedmooseheadAsJSON, Encoding.UTF8, "application/json")
                    );

                // See what comes back from the PUT. Is it a 204?
                string responseBody = await response.Content.ReadAsStringAsync();

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

                // Get the edited coffee back from the database after the PUT
                var getModifiedExercise = await client.GetAsync($"{url}/{moosehead.Id}");

                getModifiedExercise.EnsureSuccessStatusCode();

                // Convert it to JSON
                string getExerciseBody = await getModifiedExercise.Content.ReadAsStringAsync();

                // Convert it from JSON to C#
                Exercise newlyEditedExercise = JsonConvert.DeserializeObject <Exercise>(getExerciseBody);

                // Make sure the title was modified correctly
                Assert.Equal(HttpStatusCode.OK, getModifiedExercise.StatusCode);
                Assert.Equal(newName, newlyEditedExercise.Name);

                // Clean up after yourself
                await deleteDummyExercise(newlyEditedExercise);
            }
        }
Esempio n. 2
0
        public async Task Update_Instructor()
        {
            using (var client = new APIClientProvider().Client)
            {
                // Create a dummy coffee
                Instructor newLancePenn = await CreateDummyInstructor();

                // Make a new title and assign it to our dummy coffee
                string newLastName = "Pennington";
                newLancePenn.LastName = newLastName;

                // Convert it to JSON
                string modifiedLancePennAsJSON = JsonConvert.SerializeObject(newLancePenn);

                // Try to PUT the newly edited coffee
                var response = await client.PutAsync(
                    $"{url}/{newLancePenn.Id}",
                    new StringContent(modifiedLancePennAsJSON, Encoding.UTF8, "application/json")
                    );

                // See what comes back from the PUT. Is it a 204?
                string responseBody = await response.Content.ReadAsStringAsync();

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

                // Get the edited coffee back from the database after the PUT
                var getModifiedInstructor = await client.GetAsync($"{url}/{newLancePenn.Id}");

                getModifiedInstructor.EnsureSuccessStatusCode();

                // Convert it to JSON
                string getInstructorBody = await getModifiedInstructor.Content.ReadAsStringAsync();

                // Convert it from JSON to C#
                Instructor newlyEditedInstructor = JsonConvert.DeserializeObject <Instructor>(getInstructorBody);

                // Make sure the title was modified correctly
                Assert.Equal(HttpStatusCode.OK, getModifiedInstructor.StatusCode);
                Assert.Equal(newLastName, newlyEditedInstructor.LastName);

                // Clean up after yourself
                await deleteDummyInstructor(newlyEditedInstructor);
            }
        }