public async void ShouldUpdateCartLineIfAlreadyExistsAndQuantityDecrementsByOne() { // https://localhost:5001/api/cartline/{orderId} HTTPPost // Initial data: {"ProductId":1,"Quantity":3,"OrderId":1} NumberOfRecords: 2 using (var client = new HttpClient()) { var productId = 1; var quantity = -1; var targetUrl = $"{ServiceAddress}{RootAddressCartLineController}/{_orderId}"; var response = await client.PostAsync(targetUrl, new StringContent("{" + $"\"ProductId\":{productId},\"Quantity\":{quantity},\"OrderId\":{_orderId}" + "}", Encoding.UTF8, "application/json")); Assert.True(response.IsSuccessStatusCode, response.ReasonPhrase); Assert.True(response.IsSuccessStatusCode, response.ReasonPhrase); } // validate units of the cart line List <CartLine> cartLines = await CartLineTestHelpers.GetCartLines(_orderId, ServiceAddress, "api/cartline/order"); Assert.Equal(2, cartLines.Count); var cartRecord = cartLines[cartLines.Count - 1]; Assert.Equal(2, cartRecord.Quantity); }
public async void ShouldRemoveRecordOnAddIfQuantityBecomesZero() { // https://localhost:5001/api/cartline/{orderId} HTTPPost // Initial data: {"ProductId":2,"Quantity":4,"OrderId":1} NumberOfRecords: 2 using (var client = new HttpClient()) { var quantity = -4; var targetUrl = $"{ServiceAddress}{RootAddressCartLineController}/{_orderId}"; var response = await client.PostAsync(targetUrl, new StringContent("{" + $"\"ProductId\":2,\"Quantity\":{quantity},\"OrderId\":{_orderId}" + "}", Encoding.UTF8, "application/json")); Assert.True(response.IsSuccessStatusCode, response.ReasonPhrase); } // validate the cart line was removed List <CartLine> cartLines = await CartLineTestHelpers.GetCartLines(_orderId, ServiceAddress, "api/cartline/order"); Assert.Single(cartLines); }
public async void ShouldAddNewProductToTheOrder() { // Add to Order: http://localhost:5001/api/cartline/{_orderId} HTTPPost // http://localhost:5001/api/cartline/1 {"ProductId":3,"Quantity":1,"OrderId":1} using (var client = new HttpClient()) { var targetUrl = $"{ServiceAddress}{RootAddressCartLineController}/{_orderId}"; var response = await client.PostAsync(targetUrl, new StringContent("{\"productId\":3,\"quantity\":1,\"orderId\":1}", Encoding.UTF8, "application/json")); Assert.True(response.IsSuccessStatusCode, response.ReasonPhrase); } // validate the cart was added List <CartLine> cartLines = await CartLineTestHelpers.GetCartLines(_orderId, ServiceAddress, "api/cartline/order"); Assert.Equal(3, cartLines.Count); var cartLine = cartLines[cartLines.Count - 1]; Assert.Equal(3, cartLine.ProductId); Assert.Equal(1, cartLine.Quantity); }