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