Example #1
0
        public async Task Test_Modify_Product()
        {
            string newDescription = "Adorable Fluffy Kitteh";

            using (var client = new APIClientProvider().Client)
            {
                var productGetAgain = await client.GetAsync("api/product");

                string productGetResponseBody = await productGetAgain.Content.ReadAsStringAsync();

                //HMN: Use a get to retrieve the products again and translate to a string

                var productList = JsonConvert.DeserializeObject <List <Product> >(productGetResponseBody);
                Assert.Equal(HttpStatusCode.OK, productGetAgain.StatusCode);

                var productObject = productList[0];
                var originalProductDescription = JsonConvert.SerializeObject(productObject.Description);
                productObject.Description = "Adorable Fluffy Kitteh";
                //Grabs the product object, serializes it, and stores it in a variable called originalProductPrice where the parameter of the serialized object is the object with its new value. The productObject.Price (the parameter of originalProductPrice) is changed and passed in.

                var editedProductAsJson = JsonConvert.SerializeObject(productObject);
                var response            = await client.PutAsync($"api/product/{productObject.Id}", new StringContent(editedProductAsJson, Encoding.UTF8, "application/json"));

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

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

                var getProduct = await client.GetAsync($"/api/product/{productObject.Id}");

                getProduct.EnsureSuccessStatusCode();

                string getProductBody = await getProduct.Content.ReadAsStringAsync();

                Product newProduct = JsonConvert.DeserializeObject <Product>(getProductBody);

                Assert.Equal(HttpStatusCode.OK, getProduct.StatusCode);
                Assert.Equal(newDescription, newProduct.Description);

                newProduct.Description = originalProductDescription;
                var returnEditedProductToOriginalProduct = JsonConvert.SerializeObject(newProduct);

                var putEditedProductToOriginalProduct = await client.PutAsync($"api/product/{newProduct.Id}",
                                                                              new StringContent(returnEditedProductToOriginalProduct, Encoding.UTF8, "application/json"));

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

                Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            }
        }
Example #2
0
        public async Task Test_Modify_PaymentType()
        {
            string newName = "Black Card";

            using (var client = new APIClientProvider().Client)
            {
                PaymentType modifiedPaymentType = new PaymentType
                {
                    Name       = newName,
                    AcctNumber = 555555555,
                    CustomerId = 1
                };
                var modifiedPaymentTypeAsJSON = JsonConvert.SerializeObject(modifiedPaymentType);

                var response = await client.PutAsync(
                    "/api/paymenttype/2",
                    new StringContent(modifiedPaymentTypeAsJSON, Encoding.UTF8, "application/json")
                    );

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

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

                var getBlackCard = await client.GetAsync("/api/paymenttype/2");

                getBlackCard.EnsureSuccessStatusCode();

                string getBlackCardBody = await getBlackCard.Content.ReadAsStringAsync();

                PaymentType newBlackCard = JsonConvert.DeserializeObject <PaymentType>(getBlackCardBody);

                Assert.Equal(HttpStatusCode.OK, getBlackCard.StatusCode);
                Assert.Equal(newName, newBlackCard.Name);
            }
        }
Example #3
0
        public async Task Test_Edit_Computer()
        {
            using (var client = new APIClientProvider().Client)
            {
                string   newMake  = "XPS 13";
                Computer computer = new Computer
                {
                    PurchaseDate    = new DateTime(1999, 2, 16),
                    DecomissionDate = new DateTime(1994, 5, 26),
                    Make            = newMake,
                    Manufacturer    = "Dell"
                };

                var modifiedComputerAsJSON = JsonConvert.SerializeObject(computer);

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

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

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

                var getmax = await client.GetAsync("/api/Computer");

                getmax.EnsureSuccessStatusCode();

                string getBody = await getmax.Content.ReadAsStringAsync();

                var newMaxAttendees = JsonConvert.DeserializeObject <List <Computer> >(getBody);
                Assert.Equal(HttpStatusCode.OK, getmax.StatusCode);
                Assert.Equal(newMake, newMaxAttendees[0].Make);
            }
        }
        public async Task Test_Modify_ProductType()
        {
            string newName = "Bouncy Balls";

            using (var client = new APIClientProvider().Client)
            {
                ProductType modifiedProductType = new ProductType
                {
                    Name = newName
                };
                var modifiedProductTypeAsJSON = JsonConvert.SerializeObject(modifiedProductType);

                var response = await client.PutAsync(
                    "/api/producttype/2",
                    new StringContent(modifiedProductTypeAsJSON, Encoding.UTF8, "application/json")
                    );

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

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

                var getBouncyBalls = await client.GetAsync("/api/producttype/2");

                getBouncyBalls.EnsureSuccessStatusCode();

                string getBouncyBallsBody = await getBouncyBalls.Content.ReadAsStringAsync();

                ProductType newBouncyBall = JsonConvert.DeserializeObject <ProductType>(getBouncyBallsBody);

                Assert.Equal(HttpStatusCode.OK, getBouncyBalls.StatusCode);
                Assert.Equal(newName, newBouncyBall.Name);
            }
        }
        public async Task Test_Modify_Department()
        {
            string newName = "Bubblegum";

            using (var client = new APIClientProvider().Client)
            {
                Department modifiedDepartment = new Department
                {
                    Id     = 1,
                    Name   = newName,
                    Budget = 10000
                };
                var modifiedDepartmentAsJSON = JsonConvert.SerializeObject(modifiedDepartment);

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

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

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

                var getCandy = await client.GetAsync("/api/department/1");

                getCandy.EnsureSuccessStatusCode();

                string getCandyBody = await getCandy.Content.ReadAsStringAsync();

                Dictionary <int, Department> newCandy = JsonConvert.DeserializeObject <Dictionary <int, Department> >(getCandyBody);

                Assert.Equal(HttpStatusCode.OK, getCandy.StatusCode);
                Assert.Equal(newName, newCandy[1].Name);
            }
        }
Example #6
0
        public async Task Test_Modify_Employee()
        {
            string NewLastName = "Hibs";

            using (var client = new APIClientProvider().Client)
            {
                /*
                 *  ARRANGE
                 * [{"id":3,"departmentId":0,"firstName":"Single","lastName":"Quotes","isSupervisor":true,"trainingPrograms":[]},
                 */
                Employee ModifiedJosh = new Employee
                {
                    DepartmentId = 1,
                    FirstName    = "Josh",
                    LastName     = NewLastName,
                    IsSupervisor = true
                };

                var ModifiedJoshAsJSON = JsonConvert.SerializeObject(ModifiedJosh);

                /*
                 *  ACT
                 */
                var response = await client.PutAsync("/api/employees/1006",
                                                     new StringContent(ModifiedJoshAsJSON, Encoding.UTF8, "application/json")
                                                     );


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

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

                /* getsection
                 */

                var getJosh = await client.GetAsync("/api/employees/1006");

                getJosh.EnsureSuccessStatusCode();

                string getJoshBody = await getJosh.Content.ReadAsStringAsync();

                Employee newJosh = JsonConvert.DeserializeObject <Employee>(getJoshBody);

                /*
                 *  ASSERT
                 */
                Assert.Equal(HttpStatusCode.OK, getJosh.StatusCode);
                Assert.Equal(NewLastName, newJosh.LastName);
            }
        }
        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);
            }
        }
Example #8
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);
            }
        }
Example #9
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);
            }
        }
        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);
            }
        }
Example #13
0
        public async Task Edit_Coffee()
        {
            using (var client = new APIClientProvider().Client)
            {
                // Arrange
                Coffee editedCoffee = new Coffee()
                {
                    Title    = "EDITED COFFEE",
                    BeanType = "New Bean Type"
                };
                // Act
                string jsonCoffee            = JsonConvert.SerializeObject(editedCoffee);
                HttpResponseMessage response = await client.PutAsync($"/api/coffees/{fixture.TestCoffee.Id}",
                                                                     new StringContent(jsonCoffee, Encoding.UTF8, "application/json"));

                // Assert
                Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);
            }
        }
Example #14
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);
            }
        }