Exemple #1
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);
            }
        }
Exemple #2
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);
            }
        }