public async Task Update_Product()
        {
            using (var client = new APIClientProvider().Client)
            {
                Product newTestingProduct = await CreateDummyProduct();

                string newTitle = "Testing Test API";
                newTestingProduct.Title = newTitle;

                string testingProductAsJson = JsonConvert.SerializeObject(newTestingProduct);

                var response = await client.PutAsync(
                    $"{url}/{newTestingProduct.Id}",
                    new StringContent(testingProductAsJson, Encoding.UTF8, "application/json"));

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

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

                var getModifiedProduct = await client.GetAsync($"{url}/{newTestingProduct.Id}");

                getModifiedProduct.EnsureSuccessStatusCode();

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

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

                Assert.Equal(HttpStatusCode.OK, getModifiedProduct.StatusCode);
                Assert.Equal(newTitle, newlyEditedProduct.Title);

                await deleteDummyProduct(newlyEditedProduct);
            }
        }
        public async Task Test_Modify_PaymentType()
        {
            // We're going to change a paymentType's name! This is their new name.
            string newName = "cool payment type";

            using (HttpClient client = new APIClientProvider().Client)
            {
                // Create a new paymentType
                PaymentType newPaymentType = await createPaymentType(client);

                // Change their first name
                newPaymentType.Name = newName;

                // Convert them to JSON
                string modifiedPaymentTypeAsJSON = JsonConvert.SerializeObject(newPaymentType);

                // Make a PUT request with the new info
                HttpResponseMessage response = await client.PutAsync(
                    $"api/paymentType/{newPaymentType.Id}",
                    new StringContent(modifiedPaymentTypeAsJSON, Encoding.UTF8, "application/json")
                    );


                response.EnsureSuccessStatusCode();

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

                // We should have gotten a no content status code
                Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);

                /*
                 *  GET section
                 */
                // Try to GET the paymentType we just edited
                HttpResponseMessage getPaymentType = await client.GetAsync($"api/paymentType/{newPaymentType.Id}");

                getPaymentType.EnsureSuccessStatusCode();

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

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

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

                // Make sure the name was in fact updated
                Assert.Equal(newName, modifiedPaymentType.Name);

                // Clean up after ourselves- delete it
                deletePaymentType(modifiedPaymentType, client);
            }
        }
        public async Task Update_Order()
        {
            using (var client = new APIClientProvider().Client)
            {
                // Create a dummy order
                Order newOrder = await CreateDummyOrder();

                // Make a new title and assign it to our dummy order
                int newCustomerId = 1;
                newOrder.customerId = newCustomerId;

                // Convert it to JSON
                string modifiedOrderAsJSON = JsonConvert.SerializeObject(newOrder);

                // Try to PUT the newly edited order
                var response = await client.PutAsync(
                    $"{url}/{newOrder.id}",
                    new StringContent(modifiedOrderAsJSON, 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 order back from the database after the PUT
                var getModifiedOrder = await client.GetAsync($"{url}/{newOrder.id}");

                getModifiedOrder.EnsureSuccessStatusCode();

                // Convert it to JSON
                string getOrderBody = await getModifiedOrder.Content.ReadAsStringAsync();

                // Convert it from JSON to C#
                Order newlyEditedOrder = JsonConvert.DeserializeObject <Order>(getOrderBody);

                // Make sure the title was modified correctly
                Assert.Equal(HttpStatusCode.OK, getModifiedOrder.StatusCode);
                Assert.Equal(newCustomerId, newlyEditedOrder.customerId);

                // Clean up after yourself
                await deleteDummyOrder(newlyEditedOrder);
            }
        }
Exemplo n.º 4
0
        public async Task Update_Product()
        {
            using (var client = new APIClientProvider().Client)
            {
                // Create a dummy coffee
                Product newAbramsTank = await CreateDummyProduct();

                // Make a new title and assign it to our dummy coffee
                string newTitle = "HUGE FLIPPIN TANK OMG";
                newAbramsTank.Title = newTitle;

                // Convert it to JSON
                string modifiedAbramsTankAsJSON = JsonConvert.SerializeObject(newAbramsTank);

                // Try to PUT the newly edited coffee
                var response = await client.PutAsync(
                    $"{url}/{newAbramsTank.Id}",
                    new StringContent(modifiedAbramsTankAsJSON, 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 getModifiedProduct = await client.GetAsync($"{url}/{newAbramsTank.Id}");

                getModifiedProduct.EnsureSuccessStatusCode();

                // Convert it to JSON
                string getProductBody = await getModifiedProduct.Content.ReadAsStringAsync();

                // Convert it from JSON to C#
                Product newlyEditedProduct = JsonConvert.DeserializeObject <Product>(getProductBody);

                // Make sure the title was modified correctly
                Assert.Equal(HttpStatusCode.OK, getModifiedProduct.StatusCode);
                Assert.Equal(newTitle, newlyEditedProduct.Title);

                // Clean up after yourself
                await deleteDummyProduct(newlyEditedProduct);
            }
        }
        public async Task Update_PaymentType()
        {
            using (var client = new APIClientProvider().Client)
            {
                // Create a dummy paymentType
                PaymentType newPayment = await CreateDummyPaymentType();

                // Make a new acctNumber and assign it to our dummy paymentType
                String newName = "Bogdonny";
                newPayment.Name = newName;

                // Convert it to JSON
                string modifiedPaymentAsJSON = JsonConvert.SerializeObject(newPayment);

                // Try to PUT the newly edited paymentType
                var response = await client.PutAsync(
                    $"{url}/{newPayment.Id}",
                    new StringContent(modifiedPaymentAsJSON, 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 getModifiedPaymentType = await client.GetAsync($"{url}/{newPayment.Id}");

                getModifiedPaymentType.EnsureSuccessStatusCode();

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

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

                // Make sure the Name was modified correctly
                Assert.Equal(HttpStatusCode.OK, getModifiedPaymentType.StatusCode);
                Assert.Equal(newName, newlyEditedPaymentType.Name);

                // Clean up after yourself
                await deleteDummyPaymentType(newlyEditedPaymentType);
            }
        }
Exemplo n.º 6
0
        public async Task Update_Department()
        {
            using (var client = new APIClientProvider().Client)
            {
                // Create a dummy
                Department deptType = await CreateDummyDepartment();

                // Make a new title and assign it to our dummy
                string newName = "dept";
                deptType.name = newName;

                // Convert it to JSON
                string modifiedDeptAsJSON = JsonConvert.SerializeObject(deptType);

                // Try to PUT the newly edited
                var response = await client.PutAsync(
                    $"{url}/{deptType.id}",
                    new StringContent(modifiedDeptAsJSON, 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 item back from the database after the PUT
                var getModifiedDept = await client.GetAsync($"{url}/{deptType.id}");

                getModifiedDept.EnsureSuccessStatusCode();

                // Convert it to JSON
                string getDepartmentBody = await getModifiedDept.Content.ReadAsStringAsync();

                // Convert it from JSON to C#
                Department newlyEditedDept = JsonConvert.DeserializeObject <Department>(getDepartmentBody);

                // Make sure the title was modified correctly
                Assert.Equal(HttpStatusCode.OK, getModifiedDept.StatusCode);
                Assert.Equal(newName, newlyEditedDept.name);

                // Clean up after yourself
                await deleteDummyDepartment(newlyEditedDept);
            }
        }
Exemplo n.º 7
0
        public async Task Update_ProductType()
        {
            using (var client = new APIClientProvider().Client)
            {
                ///         // Create dummy ProductType
                ProductType newProductType = await CreateDummyProductType();

                ///         // Create a new name and assign it to dummy ProductType
                string newName = "stinky gouda ";
                newProductType.Name = newName;

                ///         // Convert to JSON
                string modifiedProductTypeAsJSON = JsonConvert.SerializeObject(newProductType);

                ///         // PUT
                var response = await client.PutAsync(
                    $"{url}/{newProductType.Id}",
                    new StringContent(modifiedProductTypeAsJSON, Encoding.UTF8, "application/json")
                    );

                ///         // Confirm PUT
                string responseBody = await response.Content.ReadAsStringAsync();

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

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

                getModifiedProductType.EnsureSuccessStatusCode();

                ///         // Convert it to JSON
                string getProductTypeBody = await getModifiedProductType.Content.ReadAsStringAsync();

                ///         // Convert it from JSON to C#
                ProductType newEditProductType = JsonConvert.DeserializeObject <ProductType>(getProductTypeBody);

                ///         // Confirms that the productType name has been edited
                Assert.Equal(HttpStatusCode.OK, getModifiedProductType.StatusCode);
                Assert.Equal(newName, newEditProductType.Name);

                ///         // Clean up
                await deleteDummyProductType(newEditProductType);
            }
        }
        public async Task Update_Customer()
        {
            using (var client = new APIClientProvider().Client)
            {
                // Create a dummy Customer
                Customer newTestyTesterson = await CreateDummyCustomer();

                // Make a new title and assign it to our dummy Customer
                string newName = "TESTERGLARPLEGLORP";
                newTestyTesterson.FirstName = newName;
                // Convert it to JSON
                string modifiedTestyTestersonAsJSON = JsonConvert.SerializeObject(newTestyTesterson);
                // Try to PUT the newly edited Customer
                var response = await client.PutAsync(
                    $"{url}/{newTestyTesterson.Id}",
                    new StringContent(modifiedTestyTestersonAsJSON, 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 Customer back from the database after the PUT
                var getModifiedCustomer = await client.GetAsync($"{url}/{newTestyTesterson.Id}");

                getModifiedCustomer.EnsureSuccessStatusCode();
                // Convert it to JSON
                string getCustomerBody = await getModifiedCustomer.Content.ReadAsStringAsync();

                // Convert it from JSON to C#
                Customer newlyEditedCustomer = JsonConvert.DeserializeObject <Customer>(getCustomerBody);
                // Make sure the title was modified correctly
                Assert.Equal(HttpStatusCode.OK, getModifiedCustomer.StatusCode);
                Assert.Equal(newName, newlyEditedCustomer.FirstName);
                // Clean up after yourself
                await DeleteDummyCustomer(newlyEditedCustomer);
            }
        }