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);
            }
        }
Пример #3
0
        private async Task <Product> Initialize()
        {
            using (var client = new TestClientProvider().Client)
            {
                var testProduct = new Product
                {
                    Name        = "Testprodukt",
                    ImgSrc      = "https://www.w3schools.com/images/colorpicker.gif",
                    Description = "Testbeskrivning",
                    Price       = 98.00M
                };

                var payload  = new StringContent(JsonConvert.SerializeObject(testProduct), Encoding.UTF8, "application/json");
                var response = await client.PostAsync($"/api/products", payload);

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

                return(createdProduct);
            }
        }