public async Task Test_Modify_Product()
        {
            using (var client = new APIClientProvider().Client)
            {
                string newProductTitle       = "New Product v 2.0";
                string newProductDescription = "This is the most recent version of the New Product. It will change your life forever!";

                Product modifiedProduct = new Product
                {
                    ProductTypeId = 1,
                    CustomerId    = 1,
                    Price         = 13.99M,
                    Title         = newProductTitle,
                    Description   = newProductDescription,
                    Quantity      = 5
                };

                var newProductAsJSON = JsonConvert.SerializeObject(modifiedProduct);

                /*
                 *  ACT
                 */
                var response = await client.PutAsync("/api/products/1",
                                                     new StringContent(newProductAsJSON, Encoding.UTF8, "application/json"));

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

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

                /*
                 *  Get Section
                 */

                var getProduct = await client.GetAsync("/api/products/1");

                getProduct.EnsureSuccessStatusCode();

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

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

                Assert.Equal(HttpStatusCode.OK, getProduct.StatusCode);
                Assert.Equal(newProductTitle, modifiedProduct.Title);
                Assert.Equal(newProductDescription, modifiedProduct.Description);
            }
        }
示例#2
0
        public async Task Test_Get_Single_Order_With_Products()
        {
            using (var client = new APIClientProvider().Client)
            {
                var response = await client.GetAsync("/api/Order/2/?_include=products");


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

                var order = JsonConvert.DeserializeObject <Order>(responseBody);

                Assert.Equal(HttpStatusCode.OK, response.StatusCode);
                Assert.True(order.Products.Count > 0);
                Assert.Equal(21, order.Products[0].Quantity);
                Assert.Equal("Harry Potter and the Half-blood Prince", order.Products[0].Title);
            }
        }
示例#3
0
        public async Task Test_Get_Single_Department()
        {
            using (var department = new APIClientProvider().Client)
            {
                var response = await department.GetAsync("/api/Department/2");

                response.EnsureSuccessStatusCode();

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

                var departmentResponse = JsonConvert.DeserializeObject <Department>(responseBody);

                Assert.Equal(HttpStatusCode.OK, response.StatusCode);
                Assert.Equal("IT", departmentResponse.Name);
                Assert.NotNull(departmentResponse);
            }
        }
        public async Task Create_A_Computer()
        {
            using (var client = new APIClientProvider().Client)
            {
                /*
                 * ARRANGE
                 */
                Computer newComputer = new Computer()
                {
                    PurchaseDate     = new DateTime(2019, 11, 7),
                    DecommissionDate = null,
                    Make             = "Area 51M",
                    Manufacturer     = "Alienware",
                    EmployeeId       = 1
                };
                var computerAsJSON = JsonConvert.SerializeObject(newComputer);


                /*
                 *  ACT
                 */
                var response = await client.PostAsync(
                    "/api/computers",
                    new StringContent(computerAsJSON, Encoding.UTF8, "application/json"));


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

                var computer = JsonConvert.DeserializeObject <Computer>(responseBody);

                var getAllResponse = await client.GetAsync("/api/computers");


                string getAllResponseBody = await getAllResponse.Content.ReadAsStringAsync();

                var computers = JsonConvert.DeserializeObject <List <Computer> >(getAllResponseBody);

                /*
                 *  ASSERT
                 */
                Assert.Equal(HttpStatusCode.Created, response.StatusCode);
                //Check if the last item in the computers list has the same Id as the one we created
                Assert.True(computer.Id == computers[computers.Count - 1].Id);
            }
        }
        public async Task Test_Modify_PaymentType()
        {
            using (var client = new APIClientProvider().Client)
            {
                string newPaymentTypeAcctNumber = "9999888877776666";
                string newPaymentTypeName       = "BIGGER TEST";
                int    newCustomerId            = 2;

                PaymentType modifiedPaymentType = new PaymentType
                {
                    AcctNumber = newPaymentTypeAcctNumber,
                    Name       = newPaymentTypeName,
                    CustomerId = newCustomerId
                };

                var newPaymentTypeAsJSON = JsonConvert.SerializeObject(modifiedPaymentType);

                /*
                 *  ACT
                 */
                var response = await client.PutAsync("/api/paymentTypes/1",
                                                     new StringContent(newPaymentTypeAsJSON, Encoding.UTF8, "application/json"));

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

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

                /*
                 *  Get Section
                 */

                var getPaymentType = await client.GetAsync("/api/paymentTypes/1");

                getPaymentType.EnsureSuccessStatusCode();

                string getPaymentTypeBody = await getPaymentType.Content.ReadAsStringAsync();

                PaymentType paymentType = JsonConvert.DeserializeObject <PaymentType>(getPaymentTypeBody);

                Assert.Equal(HttpStatusCode.OK, getPaymentType.StatusCode);
                Assert.Equal(newPaymentTypeAcctNumber, paymentType.AcctNumber);
                Assert.Equal(newPaymentTypeName, paymentType.Name);
                Assert.Equal(newCustomerId, paymentType.CustomerId);
            }
        }
示例#6
0
        public async Task Test_Put_Employee()
        {
            //New first name to change
            string NewFirstName = "Hudson Derpy";

            using (var client = new APIClientProvider().Client)
            {
                //Put Section

                Employee modifiedEmployee = new Employee
                {
                    Id           = 1,
                    FirstName    = NewFirstName,
                    LastName     = "Patton",
                    DepartmentId = 4,
                    IsSupervisor = true,
                    StartDate    = DateTime.Now,
                };
                var modifiedEmployeeAsJSON = JsonConvert.SerializeObject(modifiedEmployee);

                var response = await client.PutAsync(
                    "api/employee/6",
                    new StringContent(modifiedEmployeeAsJSON, 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 getEmployee = await client.GetAsync("/api/employee/6");

                getEmployee.EnsureSuccessStatusCode();

                string getEmployeeBody = await getEmployee.Content.ReadAsStringAsync();

                Employee newEmployee = JsonConvert.DeserializeObject <Employee>(getEmployeeBody);

                Assert.Equal(HttpStatusCode.OK, getEmployee.StatusCode);
                Assert.Equal(NewFirstName, newEmployee.FirstName);
            }
        }
示例#7
0
        public async Task Test_Modify_Computer()
        {
            var purchased         = new DateTime(2015, 08, 11);
            var newDecommissioned = new DateTime(2016, 10, 22);

            using (var client = new APIClientProvider().Client)
            {
                /*
                 *  PUT
                 */

                Computer modifiedComputer = new Computer
                {
                    Id              = 2,
                    PurchaseDate    = purchased,
                    DecomissionDate = newDecommissioned,
                    Make            = "YRV - 483",
                    Manufacturer    = "Oyondu"
                };
                var modifiedComputerAsJSON = JsonConvert.SerializeObject(modifiedComputer);

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

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

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

                /*
                 *  GET
                 */
                var GetComputer = await client.GetAsync("/api/computers/2");

                GetComputer.EnsureSuccessStatusCode();

                string GetBody = await GetComputer.Content.ReadAsStringAsync();

                Computer NewComputer = JsonConvert.DeserializeObject <Computer>(GetBody);

                Assert.Equal(HttpStatusCode.OK, GetComputer.StatusCode);
                Assert.Equal(newDecommissioned, NewComputer.DecomissionDate);
            }
        }
示例#8
0
        public async Task Test_Modify_Customer()
        {
            // New first name to change to and test
            string newFirstName = "Jack";

            using (var client = new APIClientProvider().Client)
            {
                /*
                 *  PUT section
                 */
                Customer modifiedJack = new Customer
                {
                    FirstName      = newFirstName,
                    LastName       = "Styles",
                    CreationDate   = (new DateTime(2010, 8, 18)),
                    LastActiveDate = (new DateTime(2019, 8, 18))
                };
                var modifiedJackAsJSON = JsonConvert.SerializeObject(modifiedJack);

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

                getJack.EnsureSuccessStatusCode();

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

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

                Assert.Equal(HttpStatusCode.OK, getJack.StatusCode);
                Assert.Equal(newFirstName, newJack.FirstName);
            }
        }
        public async Task Test_Modify_Employee()
        {
            using (var client = new APIClientProvider().Client)
            {
                /*
                 *  PUT section
                 */
                Random   random           = new Random();
                int      randomNum        = random.Next(0, 100);
                string   newFirstName     = $"Andy {randomNum.ToString()}";
                Employee modifiedEmployee = new Employee()
                {
                    FirstName    = newFirstName,
                    LastName     = "Collins",
                    DepartmentId = 1,
                    IsSupervisor = true
                };
                var employeeAsJSON = JsonConvert.SerializeObject(modifiedEmployee);

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

                getEmployee.EnsureSuccessStatusCode();

                string getEmployeeBody = await getEmployee.Content.ReadAsStringAsync();

                var newEmployee = JsonConvert.DeserializeObject <Employee>(getEmployeeBody);


                Assert.Equal(HttpStatusCode.OK, getEmployee.StatusCode);
                Assert.Equal(newFirstName, newEmployee.FirstName);
            }
        }
示例#10
0
        public async Task Test_Get_Single_PaymentTypes()
        {
            using (var client = new APIClientProvider().Client)
            {
                var response = await client.GetAsync("/api/PaymentTypes/1");


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

                var paymentType = JsonConvert.DeserializeObject <PaymentType>(responseBody);

                Assert.Equal(HttpStatusCode.OK, response.StatusCode);
                Assert.Equal(34542, paymentType.AcctNumber);
                Assert.Equal("Visa", paymentType.Name);
                Assert.Equal(1, paymentType.CustomerId);
                Assert.NotNull(paymentType);
            }
        }
示例#11
0
        public async Task Test_Get_All_Order_Completed_true()
        {
            using (var client = new APIClientProvider().Client)
            {
                var response = await client.GetAsync("/api/Order?completed=true");


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

                var orders = JsonConvert.DeserializeObject <List <Order> >(responseBody);

                /*
                 *  ASSERT
                 */
                Assert.Equal(HttpStatusCode.OK, response.StatusCode);
                Assert.True(orders.Count > 0);
            }
        }
示例#12
0
        public async Task Test_Get_All_TrainingPrograms_Not_Completed()
        {
            using (var client = new APIClientProvider().Client)
            {
                var response = await client.GetAsync("/api/TrainingProgram?_completed=false");


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

                var trainingPrograms = JsonConvert.DeserializeObject <List <TrainingProgram> >(responseBody);

                /*
                 *  ASSERT
                 */
                Assert.Equal(HttpStatusCode.OK, response.StatusCode);
                Assert.True(trainingPrograms[0].StartDate >= DateTime.Now);
            }
        }
        public async Task Test_Get_Departments_By_ID_By_Budget()
        {
            using (var client = new APIClientProvider().Client)
            {
                var response = await client.GetAsync("api/Department/1?_filter=budget&_gt=300");

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


                var departments = JsonConvert.DeserializeObject <List <Department> >(responseBody);

                foreach (Department d in departments)
                {
                    Assert.Equal(HttpStatusCode.OK, response.StatusCode);
                    Assert.True(departments.Count > 0);
                }
            }
        }
        public async Task Test_Get_Employee()
        {
            using (var client = new APIClientProvider().Client)
            {
                // ARRANGE

                // ACT
                var response = await client.GetAsync("/api/employees/1");

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

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

                // ASSERT
                Assert.Equal(HttpStatusCode.OK, response.StatusCode);
                Assert.True(employee.Id == 1);
            }
        }
示例#15
0
        public async Task Test_Get_Single_Payment_Type()
        {
            using (var client = new APIClientProvider().Client)
            {
                var response = await client.GetAsync("/PaymentType/3");

                response.EnsureSuccessStatusCode();

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

                var paymentType = JsonConvert.DeserializeObject <PaymentType>(responseBody);

                Assert.Equal(HttpStatusCode.OK, response.StatusCode);
                Assert.Equal(2468, paymentType.AccountNumber);
                Assert.Equal("ConnorAccount3", paymentType.Name);
                Assert.NotNull(paymentType);
            }
        }
示例#16
0
        public async Task Test_Get_Single_Computer()
        {
            using (var client = new APIClientProvider().Client)
            {
                var response = await client.GetAsync("/Computers/1");

                response.EnsureSuccessStatusCode();

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

                var computer = JsonConvert.DeserializeObject <Computer>(responseBody);

                Assert.Equal(HttpStatusCode.OK, response.StatusCode);
                Assert.Equal(1, computer.Id);
                Assert.Equal("Inspiron", computer.Make);
                Assert.Equal("Dell", computer.Manufacturer);
            }
        }
        public async Task Test_Get_Single_Product()
        {
            using (var client = new APIClientProvider().Client)
            {
                var response = await client.GetAsync("api/products/1");

                response.EnsureSuccessStatusCode();

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

                var product = JsonConvert.DeserializeObject <Product>(responseBody);

                Assert.Equal(HttpStatusCode.OK, response.StatusCode);
                Assert.Equal("Happy-Shirt", product.Title);
                Assert.Equal("Tshirt", product.Description);
                Assert.NotNull(product);
            }
        }
示例#18
0
        public async Task Test_Get_All_ProductTypes()
        {
            using (var client = new APIClientProvider().Client)
            {
                /* ARRANGE */

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

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

                var typeList = JsonConvert.DeserializeObject <List <ProductType> >(responseBody);

                /* ASSERT */
                Assert.Equal(HttpStatusCode.OK, response.StatusCode);
                Assert.True(typeList.Count > 0);
            }
        }
示例#19
0
        public async Task Test_Get_All_Departments_with_Filter_Budget_and_employee()
        {
            using (var client = new APIClientProvider().Client)
            {
                var response = await client.GetAsync("/api/Department?_filter=budget&_gt=30000&_include=employees");


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

                var departments = JsonConvert.DeserializeObject <List <Department> >(responseBody);

                /*
                 *  ASSERT
                 */
                Assert.Equal(HttpStatusCode.OK, response.StatusCode);
                Assert.True(departments.Count > 0);
            }
        }
示例#20
0
        public async Task Test_Get_All_TrainingPrograms()
        {
            using (var client = new APIClientProvider().Client)
            {
                var response = await client.GetAsync("/api/TrainingProgram");


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

                var trainingPrograms = JsonConvert.DeserializeObject <List <TrainingProgram> >(responseBody);

                /*
                 *  ASSERT
                 */
                Assert.Equal(HttpStatusCode.OK, response.StatusCode);
                Assert.True(trainingPrograms.Count > 0);
            }
        }
        public async Task Test_Get_All_Products()
        {
            {
                using (var client = new APIClientProvider().Client)
                {
                    var response = await client.GetAsync("api/products");



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

                    var productList = JsonConvert.DeserializeObject <List <Product> >(responseBody);

                    Assert.Equal(HttpStatusCode.OK, response.StatusCode);
                    Assert.True(productList.Count > 0);
                }
            }
        }
        public async Task Modify_ProductType()
        {
            string NewName = "Food";

            using (var client = new APIClientProvider().Client)
            {
                /*
                 *  PUT
                 */
                ProductType modifiedGrocery = new ProductType
                {
                    Name = NewName
                };

                var modifiedGroceryAsJSON = JsonConvert.SerializeObject(modifiedGrocery);

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

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

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

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

                getGrocery.EnsureSuccessStatusCode();

                string getGroceryBody = await getGrocery.Content.ReadAsStringAsync();

                ProductType newGrocery = JsonConvert.DeserializeObject <ProductType>(getGroceryBody);

                /*
                 * ASSERT
                 */

                Assert.Equal(HttpStatusCode.OK, getGrocery.StatusCode);
                Assert.Equal(NewName, newGrocery.Name);
            }
        }
示例#23
0
        public async Task Test_Modify_PaymentType()
        {
            // New last name to change to and test
            string newAcctNumber = "000111";

            using (var client = new APIClientProvider().Client)
            {
                /*
                 *  PUT section
                 */
                PaymentType modifiedJoe = new PaymentType
                {
                    AcctNumber = newAcctNumber,
                    Name       = "Amex",
                    CustomerId = 1,
                };
                var modifiedJoeAsJSON = JsonConvert.SerializeObject(modifiedJoe);

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

                getJoe.EnsureSuccessStatusCode();

                string getJoeBody = await getJoe.Content.ReadAsStringAsync();

                PaymentType newJoe = JsonConvert.DeserializeObject <PaymentType>(getJoeBody);

                Assert.Equal(HttpStatusCode.OK, getJoe.StatusCode);
                Assert.Equal(newAcctNumber, newJoe.AcctNumber);
            }
        }
        public async Task Test_Modify_Order()
        {
            // New PaymentId
            int paymentId = 3;

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

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

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

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

                /*
                 *  GET section
                 */
                var getOrder = await client.GetAsync("/Order/4");

                getOrder.EnsureSuccessStatusCode();

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

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

                Assert.Equal(HttpStatusCode.OK, getOrder.StatusCode);
                Assert.Equal(1, newOrder.CustomerId);
                Assert.Equal(paymentId, newOrder.PaymentTypeId);
            }
        }
        public async Task Test_Modify_DepartmentId()
        {
            // New DepaertmentId
            int departmentId = 2;

            using (var client = new APIClientProvider().Client)
            {
                /*
                 *  PUT section
                 */
                Employee modifiedEmployee = new Employee
                {
                    FirstName    = "Warner",
                    LastName     = "Carpenter",
                    DepartmentId = departmentId,
                    IsSuperVisor = true
                };
                var modifiedEmployeeAsJSON = JsonConvert.SerializeObject(modifiedEmployee);

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

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

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

                /*
                 *  GET section
                 */
                var getEmployee = await client.GetAsync("/employees/1");

                getEmployee.EnsureSuccessStatusCode();

                string getEmployeeBody = await getEmployee.Content.ReadAsStringAsync();

                Employee newEmployee = JsonConvert.DeserializeObject <Employee>(getEmployeeBody);

                Assert.Equal(HttpStatusCode.OK, getEmployee.StatusCode);
                Assert.Equal(departmentId, newEmployee.DepartmentId);
            }
        }
        public async Task Test_Modify_Employee()
        {
            using (var client = new APIClientProvider().Client)
            {
                string newEmployeeFirstName = "Jenna";
                string newEmployeeLastName  = "Solis";

                Employee modifiedEmployee = new Employee
                {
                    FirstName    = newEmployeeFirstName,
                    LastName     = newEmployeeLastName,
                    DepartmentId = 1,
                    IsSuperVisor = false
                };

                var newEmployeeAsJSON = JsonConvert.SerializeObject(modifiedEmployee);

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

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

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

                /*
                 *  Get Section
                 */

                var getEmployee = await client.GetAsync("/api/employees/5");

                getEmployee.EnsureSuccessStatusCode();

                string getEmployeeBody = await getEmployee.Content.ReadAsStringAsync();

                Employee employee = JsonConvert.DeserializeObject <Employee>(getEmployeeBody);

                Assert.Equal(HttpStatusCode.OK, getEmployee.StatusCode);
                Assert.Equal(newEmployeeFirstName, employee.FirstName);
                Assert.Equal(newEmployeeLastName, employee.LastName);
            }
        }
示例#27
0
        public async Task Test_Modify_Payment()
        {
            using (var client = new APIClientProvider().Client)
            {
                /*
                 *  PUT section
                 */
                string newName = "AMEX";

                PaymentType modifiedPayment = new PaymentType
                {
                    Name       = newName,
                    AcctNumber = 1000,
                    CustomerId = 1
                };

                var modifiedPaymentAsJson = JsonConvert.SerializeObject(modifiedPayment);

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

                getPayment.EnsureSuccessStatusCode();

                string getPaymentBody = await getPayment.Content.ReadAsStringAsync();

                PaymentType newPayment = JsonConvert.DeserializeObject <PaymentType>(getPaymentBody);

                Assert.Equal(HttpStatusCode.OK, getPayment.StatusCode);
                Assert.Equal(newName, newPayment.Name);
            }
        }
示例#28
0
        public async Task Test_Modify_Customer()
        {
            using (var client = new APIClientProvider().Client)
            {
                string newCustomerFirstName = "Jenna";
                string newCustomerLastName  = "Solis";

                Customer modifiedCustomer = new Customer
                {
                    FirstName      = newCustomerFirstName,
                    LastName       = newCustomerLastName,
                    CreationDate   = DateTime.Now,
                    LastActiveDate = DateTime.Now
                };

                var newCustomerAsJSON = JsonConvert.SerializeObject(modifiedCustomer);

                /*
                 *  ACT
                 */
                var response = await client.PutAsync("/api/customers/6",
                                                     new StringContent(newCustomerAsJSON, Encoding.UTF8, "application/json"));

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

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

                /*
                 *  Get Section
                 */

                var getCustomer = await client.GetAsync("/api/customers/6");

                getCustomer.EnsureSuccessStatusCode();

                string getCustomerBody = await getCustomer.Content.ReadAsStringAsync();

                Customer customer = JsonConvert.DeserializeObject <Customer>(getCustomerBody);

                Assert.Equal(HttpStatusCode.OK, getCustomer.StatusCode);
                Assert.Equal(newCustomerFirstName, customer.FirstName);
                Assert.Equal(newCustomerLastName, customer.LastName);
            }
        }
示例#29
0
        public async Task Test_Modify_Order()
        {
            // New last name to change to and test
            int newPaymentTypeId = 1;

            using (var client = new APIClientProvider().Client)
            {
                /*
                 *  PUT section
                 */
                Order modifiedOrder = new Order
                {
                    CustomerId    = 1,
                    PaymentTypeId = newPaymentTypeId,
                    Status        = "In Progress"
                };
                var modifiedOrderAsJSON = JsonConvert.SerializeObject(modifiedOrder);

                var response = await client.PutAsync(
                    "/api/orders/1",
                    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 getModifiedOrder = await client.GetAsync("/api/orders/1");

                getModifiedOrder.EnsureSuccessStatusCode();

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

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

                Assert.Equal(HttpStatusCode.OK, getModifiedOrder.StatusCode);
                Assert.Equal(newPaymentTypeId, newOrder.PaymentTypeId);
            }
        }
示例#30
0
        public async Task Test_Modify_PaymentType()
        {
            string newAcctName = "New Acct Name For Test";
            int    newAcctNum  = 12345;

            using (var client = new APIClientProvider().Client)
            {
                /*
                 *  PUT section
                 */
                PaymentType modifiedPaymentType = new PaymentType
                {
                    Name          = newAcctName,
                    AccountNumber = newAcctNum,
                    CustomerId    = 1
                };
                var modifiedPaymentTypeAsJSON = JsonConvert.SerializeObject(modifiedPaymentType);

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

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

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

                /*
                 *  GET section
                 */
                var getPaymentType = await client.GetAsync("/PaymentType/4");

                getPaymentType.EnsureSuccessStatusCode();

                string getPaymentTypeBody = await getPaymentType.Content.ReadAsStringAsync();

                PaymentType newPaymentType = JsonConvert.DeserializeObject <PaymentType>(getPaymentTypeBody);

                Assert.Equal(HttpStatusCode.OK, getPaymentType.StatusCode);
                Assert.Equal(newAcctName, newPaymentType.Name);
                Assert.Equal(newAcctNum, newPaymentType.AccountNumber);
            }
        }