public async Task Test_Modify_Student()
        {
            // New last name to change to and test
            string newLastName = "Bookerton";

            using (var client = new APIClientProvider().Client)
            {
                /*
                 *  PUT section
                 */
                Student modifiedFreddy = new Student
                {
                    StuFirstName   = "Freddy",
                    StuLastName    = newLastName,
                    StuSlackHandle = "@fullhousefreddy",
                    CohortId       = 1,
                    InstructorId   = 2
                };
                var modifiedFreddyAsJSON = JsonConvert.SerializeObject(modifiedFreddy);

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

                getFreddy.EnsureSuccessStatusCode();

                string getFreddyBody = await getFreddy.Content.ReadAsStringAsync();

                Student newFreddy = JsonConvert.DeserializeObject <Student>(getFreddyBody);

                Assert.Equal(HttpStatusCode.OK, getFreddy.StatusCode);
                Assert.Equal(newLastName, newFreddy.StuLastName);
            }
        }
示例#2
0
        public async Task Test_Modify_Student()
        {
            // New last name to change to and test
            int newCohortId = 2;

            using (var client = new APIClientProvider().Client)
            {
                /*
                 *  PUT section
                 */
                Student modifiedHarry = new Student
                {
                    FirstName   = "Harry",
                    LastName    = "Harrison",
                    CohortId    = newCohortId,
                    SlackHandle = "slack1"
                };
                var modifiedHarryAsJSON = JsonConvert.SerializeObject(modifiedHarry);

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

                getHarry.EnsureSuccessStatusCode();

                string getHarryBody = await getHarry.Content.ReadAsStringAsync();

                Student newHarry = JsonConvert.DeserializeObject <Student>(getHarryBody);

                Assert.Equal(HttpStatusCode.OK, getHarry.StatusCode);
                Assert.Equal(newCohortId, newHarry.CohortId);
            }
        }
示例#3
0
        public async Task Test_Modify_Animal()
        {
            // New last name to change to and test
            int newAge = 5;

            using (var client = new APIClientProvider().Client)
            {
                /*
                 *  PUT section
                 */
                Animal modifiedJack = new Animal
                {
                    Name     = "Jack",
                    Breed    = "Cocker Spaniel",
                    Age      = newAge,
                    HasShots = true
                };
                var modifiedJackAsJSON = JsonConvert.SerializeObject(modifiedJack);

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

                getJack.EnsureSuccessStatusCode();

                string getJackBody = await getJack.Content.ReadAsStringAsync();

                Animal newJack = JsonConvert.DeserializeObject <Animal>(getJackBody);

                Assert.Equal(HttpStatusCode.OK, getJack.StatusCode);
                Assert.Equal(newAge, newJack.Age);
            }
        }
示例#4
0
        public async Task Test_Delete_Student()
        {
            using (var client = new APIClientProvider().Client)
            {
                var response = await client.DeleteAsync("/api/student/3");

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


                var getDeletedStudent = await client.GetAsync("/api/student/3");

                getDeletedStudent.EnsureSuccessStatusCode();



                Assert.Equal(HttpStatusCode.NoContent, getDeletedStudent.StatusCode);
            }
        }
        public async Task Delete_ProductType()
        {
            // Note: with many of these methods, I'm creating dummy data and then testing to see if I can delete it. I'd rather do that for now than delete something else I (or a user) created in the database, but it's not essential-- we could test deleting anything
            // Create a new coffee in the db
            ProductType newTestType = await CreateDummyProductType();

            // Delete it
            await deleteDummyProductType(newTestType);

            using (var client = new APIClientProvider().Client)
            {
                // Try to get it again
                HttpResponseMessage response = await client.GetAsync($"{url}{newTestType.Id}");

                // Make sure it's really gone
                Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
            }
        }
        public async Task Get_All_ProductType()
        {
            using (var client = new APIClientProvider().Client)
            {
                // Try to get all of the ProductTypes from /api/ProductType
                HttpResponseMessage response = await client.GetAsync(url);

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

                // Convert from JSON to C#
                List <ProductType> producttypes = JsonConvert.DeserializeObject <List <ProductType> >(responseBody);
                // Make sure we got back a 200 OK Status and that there are more than 0 ProductTypes in our database
                Assert.Equal(HttpStatusCode.OK, response.StatusCode);
                Assert.True(producttypes.Count > 0);
            }
        }
        public async Task Test_Modify_Animal()
        {
            // New eating habit value to change to and test
            string NewEatingHabit = "Herbivore";

            using (var client = new APIClientProvider().Client)
            {
                /*
                 *  PUT section
                 */
                Animal ModifiedButter = new Animal
                {
                    Name        = "Butter",
                    Species     = "Northwest African Cheetah",
                    EatingHabit = NewEatingHabit,
                    Legs        = 4,
                    ZooId       = 2
                };
                var ModifiedButterAsJSON = JsonConvert.SerializeObject(ModifiedButter);

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

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

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

                /*
                 *  GET section
                 */
                var GetButter = await client.GetAsync("/api/animals/1");

                GetButter.EnsureSuccessStatusCode();

                string GetButterBody = await GetButter.Content.ReadAsStringAsync();

                Animal NewButter = JsonConvert.DeserializeObject <Animal>(GetButterBody);

                Assert.Equal(HttpStatusCode.OK, GetButter.StatusCode);
                Assert.Equal(NewEatingHabit, NewButter.EatingHabit);
            }
        }
        public async Task Test_Modify_Employee()
        {
            // New last name to change to and test
            string newLastName = "Spalding";

            using (var client = new APIClientProvider().Client)
            {
                /*
                 *  PUT section
                 */
                Employee modifiedKate = new Employee
                {
                    FirstName    = "Kate",
                    LastName     = newLastName,
                    DepartmentId = 2,
                    IsSuperVisor = true
                };
                var modifiedKateAsJSON = JsonConvert.SerializeObject(modifiedKate);

                var response = await client.PutAsync(
                    "api/Employee/2",
                    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/Employee/2");

                getKate.EnsureSuccessStatusCode();

                string getKateBody = await getKate.Content.ReadAsStringAsync();

                Employee newKate = JsonConvert.DeserializeObject <Employee>(getKateBody);

                Assert.Equal(HttpStatusCode.OK, getKate.StatusCode);
                Assert.Equal(newLastName, newKate.LastName);
            }
        }
        public async Task Update_PaymentType()
        {
            using (var client = new APIClientProvider().Client)
            {
                // Create a dummy PaymentType
                PaymentType newBitCash = await CreateDummyPaymentType();

                // Make a new accctNumber and assign it to our dummy PaymentType
                int newAcctNumber = 822;
                newBitCash.AcctNumber = newAcctNumber;

                // Convert it to JSON
                string modifiedBitCashAsJSON = JsonConvert.SerializeObject(newBitCash);

                // Try to PUT the newly edited PaymentType
                var response = await client.PutAsync(
                    $"{url}/{newBitCash.Id}",
                    new StringContent(modifiedBitCashAsJSON, 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 PaymentType back from the database after the PUT
                var getModifiedBitCash = await client.GetAsync($"{url}/{newBitCash.Id}");

                getModifiedBitCash.EnsureSuccessStatusCode();

                // Convert it to JSON
                string getPaymentTypeBody = await getModifiedBitCash.Content.ReadAsStringAsync();

                // Convert it from JSON to C#
                PaymentType newlyEditedPaymentType = JsonConvert.DeserializeObject <PaymentType>(getPaymentTypeBody);

                // Make sure the acctNumber was modified correctly
                Assert.Equal(HttpStatusCode.OK, getModifiedBitCash.StatusCode);
                Assert.Equal(newAcctNumber, newlyEditedPaymentType.AcctNumber);

                // Clean up after yourself
                await deleteDummyPaymentType(newlyEditedPaymentType);
            }
        }
示例#10
0
        public async Task Test_Get_NonExitant_Animal_Fails()
        {
            using (var client = new APIClientProvider().Client)
            {
                /*
                 *  ARRANGE
                 */

                /*
                 *  ACT
                 */
                var response = await client.GetAsync("/api/animals/999999999");

                /*
                 *  ASSERT
                 */
                Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
            }
        }
示例#11
0
        public async Task Test_Get_Single_Employee()
        {
            using (var client = new APIClientProvider().Client)
            {
                var response = await client.GetAsync("api/employees/1009");


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

                var employee = JsonConvert.DeserializeObject <Employee>(responseBody);

                Assert.Equal(HttpStatusCode.OK, response.StatusCode);
                Assert.Equal(0, employee.DepartmentId);
                Assert.Equal("Josh", employee.FirstName);
                Assert.Equal("Hibray", employee.LastName);
                Assert.True(employee.IsSupervisor);
                Assert.NotNull(employee);
            }
        }
示例#12
0
        public async Task Test_Modify_Order()
        {
            // New last name to change to and test
            int newPaymentId = 3;

            using (var client = new APIClientProvider().Client)
            {
                /*
                 *  PUT section
                 */
                Order modifiedOrder = new Order
                {
                    CustomerId    = 2,
                    PaymentTypeId = newPaymentId
                };
                var modifiedOrderAsJSON = JsonConvert.SerializeObject(modifiedOrder);

                var response = await client.PutAsync(
                    "/api/order/11",
                    new StringContent(modifiedOrderAsJSON, 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 getOrder = await client.GetAsync("/api/order/11");

                getOrder.EnsureSuccessStatusCode();

                string getOrderBody = await getOrder.Content.ReadAsStringAsync();

                Order newOrder = JsonConvert.DeserializeObject <Order>(getOrderBody);

                Assert.Equal(HttpStatusCode.OK, getOrder.StatusCode);
                Assert.Equal(newPaymentId, newOrder.PaymentTypeId);
            }
        }
        public async Task Update_Computer()
        {
            using (var client = new APIClientProvider().Client)
            {
                // Create a dummy Computer
                Computer newDell = await CreateDummyComputer();

                // Make a new Manufacturer and assign it to our dummy Computer
                string newManufacturer = "Dell";
                newDell.Manufacturer = newManufacturer;
                // Convert it to JSON
                string modifiedDellAsJSON = JsonConvert.SerializeObject(newDell);
                // Try to PUT the newly edited Computer
                var response = await client.PutAsync(
                    $"{url}/{newDell.Id}",
                    new StringContent(modifiedDellAsJSON, 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 Computer back from the database after the PUT
                var getModifiedDell = await client.GetAsync($"{url}/{newDell.Id}");

                getModifiedDell.EnsureSuccessStatusCode();
                // Convert it to JSON
                string getComputerBody = await getModifiedDell.Content.ReadAsStringAsync();

                // Convert it from JSON to C#
                Computer newlyEditedComputer = JsonConvert.DeserializeObject <Computer>(getComputerBody);
                // Make sure the acctNumber was modified correctly
                Assert.Equal(HttpStatusCode.OK, getModifiedDell.StatusCode);
                Assert.Equal(newManufacturer, newlyEditedComputer.Manufacturer);
                // Clean up after yourself
                await deleteDummyComputer(newlyEditedComputer);
            }
        }
        public async Task Create_ProductType()
        {
            using (var client = new APIClientProvider().Client)
            {
                // Create a new ProductType in the db
                ProductType newTestType = await CreateDummyProductType();

                // Try to get it again
                HttpResponseMessage response = await client.GetAsync($"{url}/{newTestType.Id}");

                response.EnsureSuccessStatusCode();
                // Turn the response into JSON
                string responseBody = await response.Content.ReadAsStringAsync();

                // Turn the JSON into C#
                ProductType newProductType = JsonConvert.DeserializeObject <ProductType>(responseBody);
                // Make sure it's really there
                Assert.Equal(HttpStatusCode.OK, response.StatusCode);
                Assert.Equal(dummyProductType.Name, newProductType.Name);
                Assert.Equal(dummyProductType.Archived, newProductType.Archived);
                // Clean up after ourselves
                await deleteDummyProductType(newProductType);
            }
        }
        public async Task Get_Single_ProductType()
        {
            using (HttpClient client = new APIClientProvider().Client)
            {
                // Create a dummy coffee
                ProductType newTestType = await CreateDummyProductType();

                // Try to get it
                HttpResponseMessage response = await client.GetAsync($"{url}/{newTestType.Id}");

                response.EnsureSuccessStatusCode();
                // Turn the response into JSON
                string responseBody = await response.Content.ReadAsStringAsync();

                // Turn the JSON into C#
                ProductType TestTypeFromDB = JsonConvert.DeserializeObject <ProductType>(responseBody);
                // Did we get back what we expected to get back?
                Assert.Equal(HttpStatusCode.OK, response.StatusCode);
                Assert.Equal(dummyProductType.Name, newTestType.Name);
                Assert.Equal(dummyProductType.Archived, newTestType.Archived);
                // Clean up after ourselves-- delete the dummy coffee we just created
                await deleteDummyProductType(TestTypeFromDB);
            }
        }