public async Task Delete_Product_ReturnId()
        {
            // Create testproduct
            var product = new Product {
                Description = "Testbeksriv", ImgSrc = "imgsrc", Name = "Test", Price = 2.00M
            };

            using (var client = new TestClientProvider().Client)
            {
                var json    = JsonHandler.Serialize <Product>(product);
                var content = new StringContent(json, Encoding.UTF8, "application/json");

                //add product
                var response = await client.PostAsync("/api/products/", content);

                var newProduct = await JsonHandler.Deserialize <Product>(response);

                //delete product
                var deleteresponse = await client.DeleteAsync($"/api/products/{newProduct.Id}");

                var deletedProduct = await JsonHandler.Deserialize <Product>(deleteresponse);

                Assert.NotEqual(Guid.Empty, deletedProduct.Id);
                Assert.Equal(newProduct.Id, deletedProduct.Id);
            }
        }
        public async Task Change_product_returns_updated_product()
        {
            // Create testproduct
            var product = new Product {
                Description = "Testbeksriv", ImgSrc = "imgsrc", Name = "Test", Price = 2.00M
            };

            using (var client = new TestClientProvider().Client)
            {
                var json    = JsonHandler.Serialize <Product>(product);
                var content = new StringContent(json, Encoding.UTF8, "application/json");

                var response = await client.PostAsync("/api/products/", content);

                var newProduct = await JsonHandler.Deserialize <Product>(response);

                //change products name
                newProduct.Name = "changednametest";

                json    = JsonHandler.Serialize <Product>(newProduct);
                content = new StringContent(json, Encoding.UTF8, "application/json");
                //put product
                response = await client.PutAsync($"/api/products/{newProduct.Id}", content);

                var updatedProduct = await JsonHandler.Deserialize <Product>(response);

                //delete product
                var deleteresponse = await client.DeleteAsync($"/api/products/{newProduct.Id}");

                Assert.NotNull(updatedProduct);
                Assert.Equal(newProduct.Name, updatedProduct.Name);
            }
        }
Esempio n. 3
0
        public async void Dispose()
        {
            using (var client = new TestClientProvider().Client)
            {
                var deleteResponse = await client.DeleteAsync($"/api/products/{product.Id}");

                deleteResponse.EnsureSuccessStatusCode();
            }
        }