コード例 #1
0
        public async void Dispose()
        {
            using (var client = new TestClientProvider().Client)
            {
                var deleteResponse = await client.DeleteAsync($"/api/products/{product.Id}");

                deleteResponse.EnsureSuccessStatusCode();
            }
        }
コード例 #2
0
        public async Task GetRandomGuid_Returns_NOTFOUND()
        {
            using (var client = new TestClientProvider().Client)
            {
                Guid guid     = Guid.NewGuid();
                var  response = await client.GetAsync($"/api/products/{guid}");

                Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
            }
        }
コード例 #3
0
        public async Task GetProductById_Returns_ProductId()
        {
            using (var client = new TestClientProvider().Client)
            {
                var productsResponse = await client.GetAsync($"/api/products/{_fixture.product.Id}");

                using (var responseStream = await productsResponse.Content.ReadAsStreamAsync())
                {
                    var product = await System.Text.Json.JsonSerializer.DeserializeAsync <Product>(responseStream,
                                                                                                   new JsonSerializerOptions()
                    {
                        PropertyNameCaseInsensitive = true
                    });

                    Assert.Equal(_fixture.product.Id, product.Id);
                }
            }
        }
コード例 #4
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);
            }
        }
コード例 #5
0
        public async Task Add_New_Product_Returns_CreatedProduct()
        {
            // 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);

                Assert.NotNull(newProduct);
                Assert.NotEqual(Guid.Empty, newProduct.Id);

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