public async Task Get_All_Products()
        {
            using (var client = new APIClientProvider().Client)
            {
                HttpResponseMessage response = await client.GetAsync(url);

                response.EnsureSuccessStatusCode();

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

                List <Product> products = JsonConvert.DeserializeObject <List <Product> >(responseBody);
                Assert.Equal(HttpStatusCode.OK, response.StatusCode);
                Assert.True(products.Count > 0);
            }
        }
        public async Task Test_Create_Department()
        {
            using (var client = new APIClientProvider().Client)
            {
                // Create a new Department
                Department newDepartment = await createDepartment(client);

                // Make sure the info checks out
                Assert.Equal("Test Department", newDepartment.Name);



                // Clean up after ourselves - delete Department!
                deleteDepartment(newDepartment, client);
            }
        }
        public async Task Test_Create_And_Delete_PaymentType()
        {
            using (var client = new APIClientProvider().Client)
            {
                // Create a new PaymentType
                PaymentType newPaymentType = await createPaymentType(client);

                // Make sure the info checks out
                Assert.Equal("Test Payment Type", newPaymentType.Name);



                // Clean up after ourselves - delete PaymentType!
                deletePaymentType(newPaymentType, client);
            }
        }
        public async Task Delete_PaymentType()
        {
            // Create a new paymentType in the db
            PaymentType newPayment = await CreateDummyPaymentType();

            // Delete it
            await deleteDummyPaymentType(newPayment);

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

                // Make sure it's really gone
                Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
            }
        }
Exemplo n.º 5
0
        public async Task Delete_ProductType()
        {
            ///     // Create a new ProductType in the DB
            ProductType newProductType = await CreateDummyProductType();

            ///     // Delete ProductType
            await deleteDummyProductType(newProductType);

            using (var client = new APIClientProvider().Client)
            {
                ///         // Retrieve
                HttpResponseMessage response = await client.GetAsync($"{url}{newProductType.Id}");

                ///         // Confirm Deletion
                Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
            }
        }
        public async Task Delete_Customer()
        {
            // 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 Customer in the db
            Customer newTestyTesterson = await CreateDummyCustomer();

            // Delete it
            await DeleteDummyCustomer(newTestyTesterson);

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

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

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

                // Convert from JSON to C#
                List <Customer> Customers = JsonConvert.DeserializeObject <List <Customer> >(responseBody);
                // Make sure we got back a 200 OK Status and that there are more than 0 Customers in our database
                Assert.Equal(HttpStatusCode.OK, response.StatusCode);
                Assert.True(Customers.Count > 0);
            }
        }
        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);
            }
        }
        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.º 10
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);
            }
        }
Exemplo n.º 11
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.º 12
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 Get_One_ProductType()
        {
            using (HttpClient client = new APIClientProvider().Client)
            {
                ProductType newTestingProductType = await CreateDummyProductType();

                HttpResponseMessage response = await client.GetAsync($"{url}/{newTestingProductType.Id}");

                response.EnsureSuccessStatusCode();

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

                ProductType productTypeFromDB = JsonConvert.DeserializeObject <ProductType>(responseBody);

                Assert.Equal(HttpStatusCode.OK, response.StatusCode);
                Assert.Equal(dummyProductType.Name, productTypeFromDB.Name);

                await deleteDummyProductType(productTypeFromDB);
            }
        }
        //Method for Creating a Dummy Product
        public async Task <Product> CreateDummyProduct()
        {
            using (var client = new APIClientProvider().Client)
            {
                //Turn the String into Json
                string testingProductAsJson  = JsonConvert.SerializeObject(dummyProduct);
                HttpResponseMessage response = await client.PostAsync(
                    url,
                    new StringContent(testingProductAsJson, Encoding.UTF8, "application/json")
                    );

                //Store the Json body of the Response
                string responseBody = await response.Content.ReadAsStringAsync();

                //Turn the information that is Json into an instance of an Product
                Product newlyCreatedProduct = JsonConvert.DeserializeObject <Product>(responseBody);

                return(newlyCreatedProduct);
            }
        }
        public async Task <Customer> CreateDummyCustomer()
        {
            using (var client = new APIClientProvider().Client)
            {
                // Serialize the C# object into a JSON string
                string testCustomerAsJSON = JsonConvert.SerializeObject(dummyCustomer);
                // Use the client to send the request and store the response
                HttpResponseMessage response = await client.PostAsync(
                    url,
                    new StringContent(testCustomerAsJSON, Encoding.UTF8, "application/json")
                    );

                // Store the JSON body of the response
                string responseBody = await response.Content.ReadAsStringAsync();

                // Deserialize the JSON into an instance of Customer
                Customer newlyCreatedCustomer = JsonConvert.DeserializeObject <Customer>(responseBody);
                return(newlyCreatedCustomer);
            }
        }
Exemplo n.º 16
0
        public async Task Get_All_ProductType()
        {
            using (var client = new APIClientProvider().Client)
            {
                ///         // Retrieve from /api/ProductTypes
                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);

                ///         // 200 OK Status - Confirm count of productTypes are more than zero.
                Assert.Equal(HttpStatusCode.OK, response.StatusCode);
                Assert.True(productTypes.Count > 0);
            }
        }
Exemplo n.º 17
0
        public async Task Create_Product()
        {
            using (var client = new APIClientProvider().Client)
            {
                // Create a new coffee in the db
                Product newAbramsTank = await CreateDummyProduct();

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

                response.EnsureSuccessStatusCode();

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

                // Turn the JSON into C#
                Product newProduct = JsonConvert.DeserializeObject <Product>(responseBody);

                // Make sure it's really there
                Assert.Equal(HttpStatusCode.OK, response.StatusCode);
                Assert.Equal(dummyProduct.ProductTypeId, newProduct.ProductTypeId);
                Assert.Equal(dummyProduct.CustomerId, newProduct.CustomerId);
                Assert.Equal(dummyProduct.Price, newProduct.Price);
                Assert.Equal(dummyProduct.Title, newProduct.Title);
                Assert.Equal(dummyProduct.Description, newProduct.Description);
                Assert.Equal(dummyProduct.Quantity, newProduct.Quantity);
                Assert.Equal(dummyProduct.Archived, newProduct.Archived);


                //    ProductTypeId = 1,
                //CustomerId = 2,
                //Price = 30.00M,
                //Title = "Abrams Tanks",
                //Description = "Destructive machines of ultimate destruction.",
                //Quantity = 500,
                //Archived = false

                // Clean up after ourselves
                await deleteDummyProduct(newProduct);
            }
        }
        public async Task <PaymentType> CreateDummyPaymentType()
        {
            using (var client = new APIClientProvider().Client)
            {
                // Serialize the C# object into a JSON string
                string PaymentAsJSON = JsonConvert.SerializeObject(dummyPaymentType);


                // Use the client to send the request and store the response
                HttpResponseMessage response = await client.PostAsync(
                    url,
                    new StringContent(PaymentAsJSON, Encoding.UTF8, "application/json")
                    );

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

                PaymentType newlyCreatedPaymentType = JsonConvert.DeserializeObject <PaymentType>(responseBody);

                return(newlyCreatedPaymentType);
            }
        }
        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);
            }
        }
        public async Task Test_Get_All_Departments_Filter_by_Budget()
        {
            // Use the http client
            using (HttpClient client = new APIClientProvider().Client)
            {
                // Call the route to get all our departments; wait for a response object
                HttpResponseMessage response = await client.GetAsync("api/department?_filter=budget&_gt>60000");

                // Make sure that a response comes back at all
                response.EnsureSuccessStatusCode();

                // Read the response body as JSON
                string responseBody = await response.Content.ReadAsStringAsync();

                // Convert the JSON to a list of department instances
                List <Department> departmentList = JsonConvert.DeserializeObject <List <Department> >(responseBody);

                // Did we get back a 200 OK status code?
                Assert.Equal(HttpStatusCode.OK, response.StatusCode);

                // Are there any departments in the list?
                Assert.True(departmentList.Count > 0);
            }
        }
        public async Task Get_Single_Product()
        {
            using (HttpClient client = new APIClientProvider().Client)
            {
                Product newTestingProduct = await CreateDummyProduct();

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

                response.EnsureSuccessStatusCode();

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

                Product productFromDB = JsonConvert.DeserializeObject <Product>(responseBody);

                Assert.Equal(HttpStatusCode.OK, response.StatusCode);
                Assert.Equal(dummyProduct.ProductTypeId, productFromDB.ProductTypeId);
                Assert.Equal(dummyProduct.CustomerId, productFromDB.CustomerId);
                Assert.Equal(dummyProduct.Price, productFromDB.Price);
                Assert.Equal(dummyProduct.Description, productFromDB.Description);
                Assert.Equal(dummyProduct.Quantity, productFromDB.Quantity);

                await deleteDummyProduct(productFromDB);
            }
        }
        public async Task Test_Get_All_PaymentTypes()
        {
            // Use the http client
            using (HttpClient client = new APIClientProvider().Client)
            {
                // Call the route to get all our paymentTypes; wait for a response object
                HttpResponseMessage response = await client.GetAsync("api/paymentType");

                // Make sure that a response comes back at all
                response.EnsureSuccessStatusCode();

                // Read the response body as JSON
                string responseBody = await response.Content.ReadAsStringAsync();

                // Convert the JSON to a list of paymentType instances
                List <PaymentType> paymentTypeList = JsonConvert.DeserializeObject <List <PaymentType> >(responseBody);

                // Did we get back a 200 OK status code?
                Assert.Equal(HttpStatusCode.OK, response.StatusCode);

                // Are there any paymentTypes in the list?
                Assert.True(paymentTypeList.Count > 0);
            }
        }
        public async Task Get_Single_Customer()
        {
            using (HttpClient client = new APIClientProvider().Client)
            {
                // Create a dummy Customer
                Customer newTestyTesterson = await CreateDummyCustomer();

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

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

                // Turn the JSON into C#
                Customer TestyTestersonFromDB = JsonConvert.DeserializeObject <Customer>(responseBody);
                // Did we get back what we expected to get back?
                Assert.Equal(HttpStatusCode.OK, response.StatusCode);
                Assert.Equal(newTestyTesterson.FirstName, TestyTestersonFromDB.FirstName);
                Assert.Equal(newTestyTesterson.LastName, TestyTestersonFromDB.LastName);
                // Clean up after ourselves-- delete the dummy Customer we just created
                await DeleteDummyCustomer(TestyTestersonFromDB);
            }
        }
        public async Task Create_Customer()
        {
            using (var client = new APIClientProvider().Client)
            {
                // Create a new Customer in the db
                Customer newlyCreatedCustomer = await CreateDummyCustomer();

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

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

                // Turn the JSON into C#
                Customer newCustomer = JsonConvert.DeserializeObject <Customer>(responseBody);
                // Make sure it's really there
                Assert.Equal(HttpStatusCode.OK, response.StatusCode);
                Assert.Equal(dummyCustomer.FirstName, newCustomer.FirstName);
                Assert.Equal(dummyCustomer.LastName, newCustomer.LastName);
                // Clean up after ourselves
                await DeleteDummyCustomer(newCustomer);
            }
        }