private async Task <Product> Initialize() { using (var client = new TestClientProvider().Client) { var payload = JsonSerializer.Serialize( new Product() { productName = "Test Product", description = "Duis aliquam convallis nunc. Proin at turpis a pede posuere nonummy. Integer non velit.\n\nDonec diam neque, vestibulum eget, vulputate ut, ultrices vel, augue. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Donec pharetra, magna vestibulum aliquet ultrices, erat tortor sollicitudin mi, sit amet lobortis sapien sapien non mi. Integer ac neque.", color = "Crimson", publishDate = Convert.ToDateTime("2019-07-07T22:17:03Z"), price = 200, photo = "material_1.jpg" } ); HttpContent content = new StringContent(payload, Encoding.UTF8, "application/json"); var response = await client.PostAsync($"/api/product/create", content); using (var responseStream = await response.Content.ReadAsStreamAsync()) { var createProduct = await JsonSerializer.DeserializeAsync <Product>(responseStream, new JsonSerializerOptions() { PropertyNameCaseInsensitive = true }); return(createProduct); } } }
private async Task <Product> Initialize() { using (var client = new TestClientProvider().Client) { var payload = JsonSerializer.Serialize( new Product() { Name = "Test product", Description = "Bla bla bla", Price = 99.00M, ImageURL = "https://www.sportfiskeprylar.se/bilder/artiklar/zoom/SHADOWKIT2_1.jpg" }); HttpContent content = new StringContent(payload, Encoding.UTF8, "application/json"); var response = await client.PostAsync($"/api/products/create", content); using (var responseStream = await response.Content.ReadAsStreamAsync()) { var createdProduct = await JsonSerializer.DeserializeAsync <Product>(responseStream, new JsonSerializerOptions() { PropertyNameCaseInsensitive = true }); return(createdProduct); } } }
private async Task <Product> Initialize() { using (var client = new TestClientProvider().Client) { var payload = JsonSerializer.Serialize( new Product() { Description = "Testproduktbeskrivning", Name = "Testprodukt", Price = 123.45M, ImageUrl = "/images/Dunlop.jpg" }); HttpContent content = new StringContent(payload, Encoding.UTF8, "application/json"); var response = await client.PostAsync($"/api/products/create", content); using (var responseStream = await response.Content.ReadAsStreamAsync()) { var createdProduct = await JsonSerializer.DeserializeAsync <Product>(responseStream, new JsonSerializerOptions() { PropertyNameCaseInsensitive = true }); return(createdProduct); } } }
private async Task <Product> Initialize() { using (var client = new TestClientProvider().Client) { var payload = JsonSerializer.Serialize( new Product { Name = "TestProduct", Price = 99M, ImgUrl = "https://testpicture.com", InStock = false } ); HttpContent content = new StringContent(payload, Encoding.UTF8, "application/json"); var response = await client.PostAsync("/api/product/create", content); using (var responseStreame = await response.Content.ReadAsStreamAsync()) { var createdProduct = await JsonSerializer.DeserializeAsync <Product>(responseStreame, new JsonSerializerOptions()); return(createdProduct); } } }
public async Task CreateProduct_Returns_Created_Product() { using (var client = new TestClientProvider().Client) { client.DefaultRequestHeaders.Add("Api_Key", "MySceretApiKey"); Guid productid = Guid.Empty; var payload = JsonSerializer.Serialize( new Product() { productName = "Test Product", description = "Duis aliquam convallis nunc. Proin at turpis a pede posuere nonummy. Integer non velit.\n\nDonec diam neque, vestibulum eget, vulputate ut, ultrices vel, augue. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Donec pharetra, magna vestibulum aliquet ultrices, erat tortor sollicitudin mi, sit amet lobortis sapien sapien non mi. Integer ac neque.", color = "Crimson", publishDate = Convert.ToDateTime("2019-07-07T22:17:03Z"), price = 200, photo = "material_1.jpg" } ); HttpContent content = new StringContent(payload, Encoding.UTF8, "application/json"); var response = await client.PostAsync($"/api/product/Create", content); using (var responseStream = await response.Content.ReadAsStreamAsync()) { var product = await JsonSerializer.DeserializeAsync <Product>(responseStream, new JsonSerializerOptions() { PropertyNameCaseInsensitive = true }); productid = product.id; Assert.NotNull(product); Assert.NotEqual <Guid>(Guid.Empty, productid); } var deleteResponse = await client.DeleteAsync($"/api/product/DeleteProduct?id={productid}"); using (var deleteStream = await deleteResponse.Content.ReadAsStreamAsync()) { var deletedid = await JsonSerializer.DeserializeAsync <Guid>(deleteStream, new JsonSerializerOptions() { PropertyNameCaseInsensitive = true }); } } }
public async Task DeleteProduct_ReturnsDeleted_Id() { using (var client = new TestClientProvider().Client) { Guid productId = Guid.Empty; // Skapa en produkt var payload = JsonSerializer.Serialize( new Product() { Description = "Testproduktbeskrivning", Name = "Testprodukt", Price = 123.45M, ImageUrl = "/images/Babolat.jpg" }); HttpContent content = new StringContent(payload, Encoding.UTF8, "application/json"); var createResponse = await client.PostAsync($"/api/products/create", content); using (var responseStream = await createResponse.Content.ReadAsStreamAsync()) { var product = await JsonSerializer.DeserializeAsync <Product>(responseStream, new JsonSerializerOptions() { PropertyNameCaseInsensitive = true }); productId = product.Id; } // Radera produkten var deleteResponse = await client.DeleteAsync($"/api/products/delete?id={productId}"); using (var responseStream = await deleteResponse.Content.ReadAsStreamAsync()) { var deletedId = await JsonSerializer.DeserializeAsync <Guid>(responseStream, new JsonSerializerOptions() { PropertyNameCaseInsensitive = true }); Assert.Equal(productId, deletedId); } } }
public async Task CreateProduct_Returns_BadRequest() { Guid productid = Guid.Empty; using (var client = new TestClientProvider().Client) { client.DefaultRequestHeaders.Add("Api_Key", "MySceretApiKey"); var payload = JsonSerializer.Serialize( new Product() { }); HttpContent content = new StringContent(payload, Encoding.UTF8, "application/json"); var response = await client.PostAsync($"/api/product/Create", content); using (var responseStream = await response.Content.ReadAsStreamAsync()) { var product = await JsonSerializer.DeserializeAsync <Product>(responseStream, new JsonSerializerOptions() { PropertyNameCaseInsensitive = true }); productid = product.id; Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); } var deleteResponse = await client.DeleteAsync($"/api/product/DeleteProduct?id={productid}"); using (var deleteStream = await deleteResponse.Content.ReadAsStreamAsync()) { var deletedid = await JsonSerializer.DeserializeAsync <Guid>(deleteStream, new JsonSerializerOptions() { PropertyNameCaseInsensitive = true }); } } }