public async Task GetShoppingCartItemsByUserId_ReturnsNotFound() { using (var client = new TestClientProvider().Client) { // Provide userid for user that has no shoppingcart (user does not exist) var response = await client.GetAsync("ShoppingCartService/ShoppingCart/GetShoppingCartItemsByUserId/0000-0000-0000-0000-0000"); Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); } }
public async Task GetShoppingCartItemsByUserId_ReturnsOK() { using (var client = new TestClientProvider().Client) { /* The used userid should be created in Web/Data/ApplicationDbInitializer and a shopping cart * for the user should be created in ShoppingCartService/Data/Context/ShoppingCartDbContext */ var response = await client.GetAsync("ShoppingCartService/ShoppingCart/GetShoppingCartItemsByUserId/d28888e9-2ba9-473a-a40f-e38cb54f9b35"); response.EnsureSuccessStatusCode(); Assert.Equal(HttpStatusCode.OK, response.StatusCode); } }
public async Task AddItemToShoppingCart_ReturnsBadRequest() { var item = new ShoppingCartItemDto { }; using (var client = new TestClientProvider().Client) { var request = new HttpRequestMessage(HttpMethod.Post, $"ShoppingCartService/ShoppingCart/AddItemToShoppingCart"); var orderJson = JsonSerializer.Serialize(item); request.Content = new StringContent(orderJson, Encoding.UTF8, "application/json"); request.Headers.Add("User-Agent", "AvcPgm.ShoppingCartService.Test"); var response = await client.SendAsync(request); Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); } }
public async Task AddItemToShoppingCart_ReturnsOK() { var item = new ShoppingCartItemDto { UserId = "d28888e9-2ba9-473a-a40f-e38cb54f9b35", CatalogItemId = Guid.Parse("90d6da79-e0e2-4ba8-bf61-2d94d90df801"), Amount = 1 }; using (var client = new TestClientProvider().Client) { var request = new HttpRequestMessage(HttpMethod.Post, $"ShoppingCartService/ShoppingCart/AddItemToShoppingCart"); var orderJson = JsonSerializer.Serialize(item); request.Content = new StringContent(orderJson, Encoding.UTF8, "application/json"); request.Headers.Add("User-Agent", "AvcPgm.ShoppingCartService.Test"); var response = await client.SendAsync(request); Assert.Equal(HttpStatusCode.OK, response.StatusCode); } }