public async Task GetProductById_Returns_NotFound() { using (var client = new TestClientProvider().Client) { var response = await client.GetAsync("/api/products/getbyid?id=" + Guid.Empty); Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); } }
public async Task GetProductById_Returns_NotFound() { using (var client = new TestClientProvider().Client) { client.DefaultRequestHeaders.Add("ApiKey", "FishermansWebshopProductsApiKey"); var response = await client.GetAsync("/api/products/" + 999); Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); } }
public async Task GetAllProducts_Returns_Ok() { using (var client = new TestClientProvider().Client) { var response = await client.GetAsync("api/product/GetAllProducts"); response.EnsureSuccessStatusCode(); Assert.Equal(HttpStatusCode.OK, response.StatusCode); } }
public async Task DeleteProduct_Returns_NotFound() { using (var client = new TestClientProvider().Client) { client.DefaultRequestHeaders.Add("Api_Key", "MySceretApiKey"); var response = await client.DeleteAsync("/api/product/DeleteProduct?id=" + Guid.Empty); Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); } }
public async Task GetProductById_Returns_Found() { using (var client = new TestClientProvider().Client) { var response = await client.GetAsync("/api/products/getbyid?id=" + 1); string strResponse = await response.Content.ReadAsStringAsync(); Assert.False(string.IsNullOrWhiteSpace(strResponse)); } }
public async Task GetProductById_Returns_NotFound() { using (var client = new TestClientProvider().Client) { var response = await client.GetAsync("/api/products/getbyid?id=" + 0); string strResponse = await response.Content.ReadAsStringAsync(); Assert.Equal("", strResponse); } }
public async void CreateTestProduct_GetId_Returns_Ok() { using (var client = new TestClientProvider().Client) { client.DefaultRequestHeaders.Add("ApiKey", "FishermansWebshopProductsApiKey"); var productId = _fixture.Product.Id; var response = await client.GetAsync("/api/products/" + productId); Assert.Equal(HttpStatusCode.OK, response.StatusCode); } }
public async Task GetAllProducts_Returns_Ok() { using (var client = new TestClientProvider().Client) { client.DefaultRequestHeaders.Add("ApiKey", "FishermansWebshopProductsApiKey"); var response = await client.GetAsync("/api/products/"); response.EnsureSuccessStatusCode(); Assert.Equal(HttpStatusCode.OK, response.StatusCode); } }
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 void Dispose() { using (var client = new TestClientProvider().Client) { var deletedResponse = await client.DeleteAsync("/api/products/delete/" + Product.Id); using (var responseStream = await deletedResponse.Content.ReadAsStreamAsync()) { var deletedId = await JsonSerializer.DeserializeAsync <int>(responseStream, new JsonSerializerOptions() { PropertyNameCaseInsensitive = true }); } } }
public async Task GetAllProducts_Returns_AllProducts() { using (var client = new TestClientProvider().Client) { client.DefaultRequestHeaders.Add("ApiKey", "FishermansWebshopProductsApiKey"); var response = await client.GetAsync("/api/products"); var productResponse = await response.Content.ReadAsStringAsync(); var allProducts = JsonSerializer.Deserialize <IEnumerable <Product> >(productResponse); List <Product> actualProducts = new List <Product>(); foreach (var product in allProducts) { actualProducts.Add(product); } Assert.Equal(16, actualProducts.Count); } }
public async Task GetProductById_ReturnsProduct() { using (var client = new TestClientProvider().Client) { var productResponse = await client.GetAsync($"/api/products/getbyid?id={_fixture.product.Id}"); using (var responseStream = await productResponse.Content.ReadAsStreamAsync()) { var product = await JsonSerializer.DeserializeAsync <Product>(responseStream, new JsonSerializerOptions() { PropertyNameCaseInsensitive = true }); Assert.Equal(_fixture.product.Id, product.Id); } } }
public async Task GetProductById_Returns_Product() { using (var client = new TestClientProvider().Client) { var productResponse = await client.GetAsync($"/api/product/getbyid/{_fixture.product.Id}"); using (var responseStream = await productResponse.Content.ReadAsStreamAsync()) { var product = await JsonSerializer.DeserializeAsync <Product>(responseStream, new JsonSerializerOptions() { PropertyNameCaseInsensitive = true }); Assert.Equal(_fixture.product.Id, product.Id); } //var productsResponse = await client.GetAsync("/api/product/getall"); //IEnumerable<Product> products; //Guid testId; //using(var response = await productsResponse.Content.ReadAsStreamAsync()) //{ // products = await JsonSerializer.DeserializeAsync<IEnumerable<Product>>(response, // new JsonSerializerOptions()); //} //testId = products.ToList()[0].Id; //var productResponse = await client.GetAsync($"/api/product/getbyid?id={testId}"); //Product product; //Guid responseId; //using (var response = await productsResponse.Content.ReadAsStreamAsync()) //{ // product = await JsonSerializer.DeserializeAsync<Product>(response, // new JsonSerializerOptions()); //} //responseId = product.Id; } }
public async Task GetProductById_Returns_ImageURLFormat() { using (var client = new TestClientProvider().Client) { client.DefaultRequestHeaders.Add("ApiKey", "FishermansWebshopProductsApiKey"); var orderResponse = await client.GetAsync($"/api/products/{1}"); using (var responseStream = await orderResponse.Content.ReadAsStreamAsync()) { var product = await JsonSerializer.DeserializeAsync <Product>(responseStream, new JsonSerializerOptions() { PropertyNameCaseInsensitive = true }); var image = product.ImageURL; Assert.IsType <string>(image); } } }
public async Task GetProductById_Returns_Product() { using (var client = new TestClientProvider().Client) { client.DefaultRequestHeaders.Add("ApiKey", "FishermansWebshopProductsApiKey"); var productResponse = await client.GetAsync($"/api/products/{_fixture.Product.Id}"); using (var responseStream = await productResponse.Content.ReadAsStreamAsync()) { var product = await JsonSerializer.DeserializeAsync <Product>(responseStream, new JsonSerializerOptions() { PropertyNameCaseInsensitive = true }); var test = product.Id; Assert.Equal(_fixture.Product.Id, test); } } }
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 }); } } }