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 GetProductById_Returns_OK() { using (var client = new TestClientProvider().Client) { client.DefaultRequestHeaders.Add("ApiKey", "FishermansWebshopProductsApiKey"); var response = await client.GetAsync("/api/products/" + 1); response.EnsureSuccessStatusCode(); Assert.Equal(HttpStatusCode.OK, 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_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); } } }