Ejemplo n.º 1
0
        public async void ShouldEditCustomerProfile()
        {
            using (var client = new HttpClient())
            {
                await AccountTestHelpers.LoginAsAdmin(ServiceAddress, $"api/account/login", client);

                //var user2 = await AdminTestHelpers.GetUser("user", ServiceAddress, RootAddress, client);
                //Assert.Equal("*****@*****.**", user2.Email);
                var targetUrl = $"{ServiceAddress}{RootAddressAdminController}/User";
                var response  = await client.PostAsync(targetUrl,
                                                       new StringContent("{\"name\":\"user\",\"password\":\"password\",\"email\":\"newemail\"}",
                                                                         Encoding.UTF8, "application/json"));

                Assert.True(response.IsSuccessStatusCode, response.ReasonPhrase);
                //Validate new password
                var user = await AdminTestHelpers.GetUser("user", ServiceAddress, RootAddressAdminController, client);

                Assert.Equal("newemail", user.Email);
                var responseDefault = await client.PostAsync(targetUrl,
                                                             new StringContent("{\"name\":\"user\",\"password\":\"password\",\"email\":\"[email protected]\"}",
                                                                               Encoding.UTF8, "application/json"));

                Assert.True(responseDefault.IsSuccessStatusCode, response.ReasonPhrase);
                await AccountTestHelpers.Logout(ServiceAddress, $"api/account/logout", client);
            }
        }
Ejemplo n.º 2
0
        public async void ShouldAddProduct()
        {
            using (var client = new HttpClient())
            {
                await AccountTestHelpers.LoginAsAdmin(ServiceAddress, $"api/account/login", client);

                var targetUrl = $"{ServiceAddress}{RootAddressProductController}";
                //Añade nuevo producto de Supplier y Categoria existentes
                //POST
                //https://
                var response = await client.PostAsync(targetUrl,
                                                      new StringContent(
                                                          "{\"Name\":\"Product1\",\"CategoryId\":1,\"Description\":\"Description1\",\"Price\":11.0,\"SupplierId\":1}",
                                                          Encoding.UTF8, "application/json"));

                Assert.True(response.IsSuccessStatusCode, response.ReasonPhrase);
                List <Product> products =
                    await ProductTestHelpers.GetProducts(ServiceAddress, RootAddressProductController);

                // validate the product was added
                Assert.Equal(4, products.Count);
                var product = products[products.Count - 1];
                Assert.Equal(4, product.Id);
                Assert.Equal("Product1", product.Name);
                await AccountTestHelpers.Logout(ServiceAddress, $"api/account/logout", client);
            }
        }
Ejemplo n.º 3
0
        public async void ShouldUpdateProduct()
        {
            //Change Product(Price): http://localhost:5001/api/shoppingcart/{customerId}/{productId} HTTPPut
            using (var client = new HttpClient())
            {
                await AccountTestHelpers.LoginAsAdmin(ServiceAddress, $"api/account/login", client);

                var product = await ProductTestHelpers.GetProduct(_productId, ServiceAddress, RootAddressProductController);

                product.Price = 44;
                var json = JsonConvert.SerializeObject(product);
                //Actualiza producto
                //Name = "ReplaceProduct"
                // PUT https://localhost:5001/api/products/1
                var targetUrl = $"{ServiceAddress}{RootAddressProductController}/{_productId}";
                var response  = await client.PutAsync(targetUrl, new StringContent(json, Encoding.UTF8, "application/json"));

                if (!response.IsSuccessStatusCode)
                {
                    throw new Exception(response.StatusCode.ToString());
                }

                Assert.True(response.IsSuccessStatusCode);
                // validate product was updated
                var updatedProduct =
                    await ProductTestHelpers.GetProduct(_productId, ServiceAddress, RootAddressProductController);

                Assert.Equal(44, updatedProduct.Price);
                await AccountTestHelpers.Logout(ServiceAddress, $"api/account/logout", client);
            }
        }
Ejemplo n.º 4
0
        public async void ShouldSearchUser()
        {
            using (var client = new HttpClient())
            {
                await AccountTestHelpers.LoginAsAdmin(ServiceAddress, $"api/account/login", client);

                var response = await client.GetAsync($"{ServiceAddress}{RootAddressAdminController}/user");

                Assert.True(response.IsSuccessStatusCode);
                await AccountTestHelpers.Logout(ServiceAddress, $"api/account/logout", client);
            }
        }
Ejemplo n.º 5
0
        public async void ShouldDoLogout()
        {
            using (var client = new HttpClient())
            {
                await AccountTestHelpers.LoginAsUser(ServiceAddress, $"api/account/login", client);

                var targetLogout   = $"{ServiceAddress}{RootAddressAccountController}/logout";
                var responseLogOut = await client.PostAsync(targetLogout, null);

                Assert.True(responseLogOut.IsSuccessStatusCode, responseLogOut.ReasonPhrase);
            }
        }
        public async void ShouldNotSearchForAUserNameAsUserIsNotAnAdministrator()
        {
            using (var client = new HttpClient())
            {
                await AccountTestHelpers.LoginAsUser(ServiceAddress, $"api/account/login", client);

                var response = await client.GetAsync($"{ServiceAddress}{RootAddressAdminController}/search/user");

                Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
                //Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
                await AccountTestHelpers.Logout(ServiceAddress, $"api/account/logout", client);
            }
        }
        public async void ShouldNotFindAnOrderThatHasAnInvalidId()
        {
            using (var client = new HttpClient())
            {
                await AccountTestHelpers.LoginAsAdmin(ServiceAddress, $"api/account/login", client);

                var response = await client.GetAsync($"{ServiceAddress}{RootAddressOrderController}/5");

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

                await AccountTestHelpers.Logout(ServiceAddress, $"api/account/logout", client);
            }
        }
        public async void ShouldNotFindAnyUserThatMatchesANonExistingUserName()
        {
            using (var client = new HttpClient())
            {
                await AccountTestHelpers.LoginAsAdmin(ServiceAddress, $"api/account/login", client);

                var response = await client.GetAsync($"{ServiceAddress}{RootAddressAdminController}/search/nonuser");

                Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
                //Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
                await AccountTestHelpers.Logout(ServiceAddress, $"api/account/logout", client);
            }
        }
        public async void ShouldSearchForAUserName()
        {
            using (var client = new HttpClient())
            {
                await AccountTestHelpers.LoginAsAdmin(ServiceAddress, $"api/account/login", client);

                var response = await client.GetAsync($"{ServiceAddress}{RootAddressAdminController}/search/user");

                Assert.True(response.IsSuccessStatusCode, response.ReasonPhrase);
                var jsonResponse = await response.Content.ReadAsStringAsync();

                var user = JsonConvert.DeserializeObject <AppUser>(jsonResponse);
                Assert.Equal("*****@*****.**", user.Email);
                await AccountTestHelpers.Logout(ServiceAddress, $"api/account/logout", client);
            }
        }
        public async void ShouldFindAnOrderAsAdministrator()
        {
            using (var client = new HttpClient())
            {
                await AccountTestHelpers.LoginAsAdmin(ServiceAddress, $"api/account/login", client);

                var response = await client.GetAsync($"{ServiceAddress}{RootAddressOrderController}/1");

                Assert.True(response.IsSuccessStatusCode, response.ReasonPhrase);
                var jsonResponse = await response.Content.ReadAsStringAsync();

                var order = JsonConvert.DeserializeObject <Order>(jsonResponse);
                Assert.Equal(1, order.Id);
                await AccountTestHelpers.Logout(ServiceAddress, $"api/account/logout", client);
            }
        }
Ejemplo n.º 11
0
        public async void ShouldGetOrder()
        {
            using (var client = new HttpClient())
            {
                await AccountTestHelpers.LoginAsAdmin(ServiceAddress, $"api/account/login", client);

                var response = await client.GetAsync($"{ServiceAddress}{RootAddressOrderController}/{_orderId}");

                Assert.True(response.IsSuccessStatusCode);
                var jsonResponse = await response.Content.ReadAsStringAsync();

                var order = JsonConvert.DeserializeObject <Order>(jsonResponse);
                Assert.Equal("NameCustomer2", order.Name);
                await AccountTestHelpers.Logout(ServiceAddress, $"api/account/logout", client);
            }
        }
Ejemplo n.º 12
0
        public async void ShouldNotEditCustomerProfileWithIncompleteData()
        {
            using (var client = new HttpClient())
            {
                await AccountTestHelpers.LoginAsAdmin(ServiceAddress, $"api/account/login", client);

                var targetUrl = $"{ServiceAddress}{RootAddressAdminController}/User";
                var response  = await client.PostAsync(targetUrl,
                                                       new StringContent("{\"name\":\"user\"}",
                                                                         Encoding.UTF8, "application/json"));

                Assert.False(response.IsSuccessStatusCode, response.ReasonPhrase);
                Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
                await AccountTestHelpers.Logout(ServiceAddress, $"api/account/logout", client);
            }
        }
Ejemplo n.º 13
0
        public async void ShouldDeleteOrder()
        {
            using (var client = new HttpClient())
            {
                await AccountTestHelpers.LoginAsAdmin(ServiceAddress, $"api/account/login", client);

                var targetUrl = $"{ServiceAddress}{RootAddressOrderController}/{_orderId}";
                var response  = await client.DeleteAsync(targetUrl);

                Assert.True(response.IsSuccessStatusCode, response.ReasonPhrase);
                List <Order> orders =
                    await OrderTestHelpers.GetOrders(ServiceAddress, RootAddressProductController, client);

                Assert.Single(orders);
                await AccountTestHelpers.Logout(ServiceAddress, $"api/account/logout", client);
            }
        }
Ejemplo n.º 14
0
        public async void ShouldGetOrdersForCurrentCustomer()
        {
            using (var client = new HttpClient())
            {
                await AccountTestHelpers.LoginAsUser(ServiceAddress, $"api/account/login", client);

                await OrderTestHelpers.Create3OrdersForCurrentUser(ServiceAddress, "api/orders/user", client);

                var response = await client.GetAsync($"{ServiceAddress}api/orders/user");

                Assert.True(response.IsSuccessStatusCode);
                var jsonResponse = await response.Content.ReadAsStringAsync();

                var orders = JsonConvert.DeserializeObject <List <Order> >(jsonResponse);
                Assert.Equal(3, orders.Count);
                await AccountTestHelpers.Logout(ServiceAddress, $"api/account/logout", client);
            }
        }
        public async void ShouldCalculateTotalOfOrder()
        {
            using (var client = new HttpClient())
            {
                await AccountTestHelpers.LoginAsUser(ServiceAddress, $"api/account/login", client);

                object data = new Order
                {
                    Name      = "NameCustomer1",
                    Address   = "AddressCustomer1",
                    Shipped   = false,
                    CartLines = new List <CartLine>
                    {
                        new CartLine
                        {
                            ProductId = 1,
                            Quantity  = 1,
                        },
                        new CartLine
                        {
                            ProductId = 2,
                            Quantity  = 1,
                        }
                    },
                    PaymentNavigation = new Payment()
                    {
                        CardNumber       = "111",
                        CardExpiry       = "222",
                        CardSecurityCode = "333"
                    }
                };
                var myContent = JsonConvert.SerializeObject(data);
                var targetUrl = $"{ServiceAddress}api/orders";
                var response  = await client.PostAsync(targetUrl, new StringContent(myContent, Encoding.UTF8, "application/json"));

                Assert.True(response.IsSuccessStatusCode, response.ReasonPhrase);
                // validate the order was added
                List <Order> orders = await OrderTestHelpers.GetOrders(ServiceAddress, $"api/orders", client);

                var order = orders[orders.Count - 1];
                Assert.Equal(323.95M, order.Total);
                await AccountTestHelpers.Logout(ServiceAddress, $"api/account/logout", client);
            }
        }
Ejemplo n.º 16
0
        public async void ShouldMarkAnOrderAsShipped()
        {
            using (var client = new HttpClient())
            {
                await AccountTestHelpers.LoginAsAdmin(ServiceAddress, $"api/account/login", client);

                var order = await OrderTestHelpers.GetOrder(_orderId, ServiceAddress, RootAddressOrderController,
                                                            client);

                var targetUrl = $"{ServiceAddress}{RootAddressOrderController}/shipped/{_orderId}";
                var response  = await client.PostAsync(targetUrl, null);

                Assert.True(response.IsSuccessStatusCode, response.ReasonPhrase);
                var updatedOrder =
                    await OrderTestHelpers.GetOrder(_orderId, ServiceAddress, RootAddressOrderController, client);

                Assert.True(updatedOrder.Shipped);
                await AccountTestHelpers.Logout(ServiceAddress, $"api/account/logout", client);
            }
        }
Ejemplo n.º 17
0
        public async void ShouldDeleteProduct()
        {
            using (var client = new HttpClient())
            {
                await AccountTestHelpers.LoginAsAdmin(ServiceAddress, $"api/account/login", client);

                var product =
                    await ProductTestHelpers.GetProduct(_productId, ServiceAddress, RootAddressProductController);

                var targetUrl = $"{ServiceAddress}{RootAddressProductController}/{_orderId}";
                var response  = await client.DeleteAsJsonAsync(targetUrl, product);

                Assert.True(response.IsSuccessStatusCode, response.ReasonPhrase);
                List <Product> products =
                    await ProductTestHelpers.GetProducts(ServiceAddress, RootAddressProductController);

                Assert.Equal(2, products.Count);
                await AccountTestHelpers.Logout(ServiceAddress, $"api/account/logout", client);
            }
        }
        public async void ShouldNotPlaceOrderWhenIsMissingData()
        {
            using (var client = new HttpClient())
            {
                await AccountTestHelpers.LoginAsUser(ServiceAddress, $"api/account/login", client);

                object data = new Order
                {
                    Name      = "NameCustomer1",
                    Shipped   = false,
                    CartLines = new List <CartLine>
                    {
                        new CartLine
                        {
                            ProductId = 1,
                            Quantity  = 1,
                        },
                        new CartLine
                        {
                            ProductId = 2,
                            Quantity  = 1,
                        }
                    },
                    PaymentNavigation = new Payment()
                    {
                        CardNumber       = "111",
                        CardExpiry       = "222",
                        CardSecurityCode = "333"
                    }
                };
                var myContent = JsonConvert.SerializeObject(data);
                var targetUrl = $"{ServiceAddress}{RootAddressOrderController}";
                var response  = await client.PostAsync(targetUrl, new StringContent(myContent, Encoding.UTF8, "application/json"));

                Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
                await AccountTestHelpers.Logout(ServiceAddress, $"api/account/logout", client);
            }
        }
Ejemplo n.º 19
0
        public async void ShouldUpdateAnOrder()
        {
            using (var client = new HttpClient())
            {
                await AccountTestHelpers.LoginAsAdmin(ServiceAddress, $"api/account/login", client);

                var order = await OrderTestHelpers.GetOrder(_orderId, ServiceAddress, RootAddressOrderController,
                                                            client);

                order.Address = "newAddress";
                var json      = JsonConvert.SerializeObject(order);
                var targetUrl = $"{ServiceAddress}{RootAddressOrderController}/{_orderId}";
                var response  = await client.PutAsync(targetUrl,
                                                      new StringContent(json, Encoding.UTF8, "application/json"));

                Assert.True(response.IsSuccessStatusCode, response.ReasonPhrase);
                var updatedOrder =
                    await OrderTestHelpers.GetOrder(_orderId, ServiceAddress, RootAddressOrderController, client);

                Assert.Equal("newAddress", updatedOrder.Address);
                await AccountTestHelpers.Logout(ServiceAddress, $"api/account/logout", client);
            }
        }
Ejemplo n.º 20
0
        public async void ShouldDeleteAndCreateCustomer()
        {
            // Remove User: https://localhost:5001/api/admin/{id} HTTPDelete
            // https://localhost:5001/api/admin/user
            using (var client = new HttpClient())
            {
                await AccountTestHelpers.LoginAsAdmin(ServiceAddress, $"api/account/login", client);

                //Delete user
                var targetUrl = $"{ServiceAddress}{RootAddressAdminController}/User";
                var response  = await client.DeleteAsync(targetUrl);

                Assert.True(response.IsSuccessStatusCode, response.ReasonPhrase);
                //Create user
                var targetUrl2      = $"{ServiceAddress}{RootAddressAdminController}";
                var responseDefault = await client.PostAsync(targetUrl2,
                                                             new StringContent("{\"name\":\"user\",\"password\":\"password\",\"email\":\"[email protected]\"}",
                                                                               Encoding.UTF8, "application/json"));

                Assert.True(responseDefault.IsSuccessStatusCode, responseDefault.ReasonPhrase);
                await AccountTestHelpers.Logout(ServiceAddress, $"api/account/logout", client);
            }
        }
Ejemplo n.º 21
0
        public async void ShouldTestRoles()
        {
            using (var client = new HttpClient())
            {
                {
                    await AccountTestHelpers.LoginAsAdmin(ServiceAddress, $"api/account/login", client);

                    //Test: CreateUser AdminController
                    //Create user
                    var targetUrl1 = $"{ServiceAddress}{RootAddressAdminController}/create";
                    var response1  = await client.PostAsync(targetUrl1,
                                                            new StringContent(
                                                                "{\"name\":\"user2\",\"password\":\"password\",\"email\":\"[email protected]\"}",
                                                                Encoding.UTF8, "application/json"));

                    Assert.True(response1.IsSuccessStatusCode, response1.ReasonPhrase);

                    //Test: CreateRole RoleAdminController
                    //Create new role
                    var targetUrl2 = $"{ServiceAddress}{RootAddressRoleAdminController}/create?name=users2";
                    var response2  = await client.PostAsync(targetUrl2, null);

                    Assert.True(response2.IsSuccessStatusCode, response2.ReasonPhrase);

                    //Test: EditUsersForRole(post) RoleAdminController
                    //Add a user to a role
                    object data = new RoleModification()
                    {
                        RoleName = "users2",
                        IdsToAdd = new string[]
                        {
                            "user2"
                        }
                    };
                    var myContent  = JsonConvert.SerializeObject(data);
                    var targetUrl3 = $"{ServiceAddress}{RootAddressRoleAdminController}";
                    var response3  = await client.PostAsync(targetUrl3,
                                                            new StringContent(myContent, Encoding.UTF8, "application/json"));

                    Assert.True(response3.IsSuccessStatusCode, response3.ReasonPhrase);

                    //Test: ViewUsersForRole(id)(get) RoleAdminController
                    //Return users for a role
                    var response4 = await client.GetAsync($"{ServiceAddress}{RootAddressRoleAdminController}/users2");

                    Assert.True(response4.IsSuccessStatusCode, response4.ReasonPhrase);

                    //Test: EditUsersForRole(post) RoleAdminController
                    //Delete a user from a role
                    object data2 = new RoleModification()
                    {
                        RoleName    = "users2",
                        IdsToDelete = new string[]
                        {
                            "user2"
                        }
                    };
                    var myContent2 = JsonConvert.SerializeObject(data2);
                    var targetUrl5 = $"{ServiceAddress}{RootAddressRoleAdminController}";
                    var response5  = await client.PostAsync(targetUrl5,
                                                            new StringContent(myContent2, Encoding.UTF8, "application/json"));

                    Assert.True(response5.IsSuccessStatusCode, response5.ReasonPhrase);

                    //Test: Delete RoleAdminController
                    //Delete a role
                    var targetUrl6 = $"{ServiceAddress}{RootAddressRoleAdminController}?id=users2";
                    var response6  = await client.DeleteAsync(targetUrl6);

                    Assert.True(response6.IsSuccessStatusCode, response6.ReasonPhrase);

                    //Test: DeleteRole(id) AdminController
                    //Delete user
                    var targetUrl = $"{ServiceAddress}{RootAddressAdminController}/user2";
                    var response  = await client.DeleteAsync(targetUrl);

                    Assert.True(response.IsSuccessStatusCode, response.ReasonPhrase);

                    await AccountTestHelpers.Logout(ServiceAddress, $"api/account/logout", client);
                }
            }
        }