public async void ShouldRemoveRecordOnAddIfQuantityBecomesZero() { // Add to Cart: http://localhost:61855/api/shoppingcart/{customerId} HTTPPost // Note: ProductId and Quantity in the body {"ProductId":22,"Quantity":2} // Content - Type:application / json using (var client = new HttpClient()) { var productId = _productId; var quantity = -1; var targetUrl = $"{ServiceAddress}{RootAddress}/{_customerId}"; var response = await client.PostAsync(targetUrl, new StringContent("{" + $"\"ProductId\":{productId},\"Quantity\":{quantity}" + "}", Encoding.UTF8, "application/json")); Assert.True(response.IsSuccessStatusCode); Assert.Equal(targetUrl.ToUpper(), response.Headers.Location.AbsoluteUri.ToUpper()); } // validate the cart was added var cartRecordsWithProductDetails = await ShoppingCartTestHelpers.GetCart(_customerId, ServiceAddress, RootAddress); Assert.Equal(0, cartRecordsWithProductDetails.Count); }
public async void ShouldAddRecordToTheCart() { // Add to Cart: http://localhost:55882/api/shoppingcartrecord/{customerId} HTTPPost // Note: ProductId and Quantity in the body // http://localhost:55882/api/shoppingcartrecord/1 {"ProductId":22,"Quantity":2,"CustomerId":1} // Content - Type:application / json using (var client = new HttpClient()) { var productId = 2; var quantity = 1; //var request = new HttpRequestMessage( // HttpMethod.Post, // $"{_serviceAddress}{_rootAddress}{_customerId}") //{ // Content = new StringContent("{" + $"\"ProductId\":{productId},\"Quantity\":{quantity}" + "}", Encoding.UTF8, "application/json") //}; //var response = await client.SendAsync(request); var targetUrl = $"{ServiceAddress}{RootAddress}/{_customerId}"; var response = await client.PostAsync(targetUrl, new StringContent("{" + $"\"ProductId\":{productId},\"Quantity\":{quantity},\"CustomerId\":{_customerId}" + "}", Encoding.UTF8, "application/json")); Assert.True(response.IsSuccessStatusCode, response.ReasonPhrase); Assert.Equal($"{ServiceAddress}api/shoppingcart/{_customerId}".ToUpper(), response.Headers.Location.AbsoluteUri.ToUpper()); } // validate the cart was added CartWithCustomerInfo cartWithCustomerInfo = await ShoppingCartTestHelpers.GetCart(_customerId, ServiceAddress, "api/shoppingcart"); Assert.Equal(2, cartWithCustomerInfo.CartRecords.Count); var cartRecord = cartWithCustomerInfo.CartRecords[cartWithCustomerInfo.CartRecords.Count - 1]; Assert.Equal(2, cartRecord.Id); Assert.Equal("Munitions", cartRecord.CategoryName); Assert.Equal(1, cartRecord.Quantity); }