public async void ShouldNotFailIfBadCustomerId() { //Get Cart: http://localhost:7940/api/shoppingcart/{customerId} CartWithCustomerInfo cartWithCustomerInfo = await ShoppingCartTestHelpers.GetCart(100, ServiceAddress, RootAddress); Assert.Empty(cartWithCustomerInfo.CartRecords); }
public async void ShouldNotFailIfBadCustomerId() { //Get Cart: http://localhost:40001/api/shoppingcart/{customerId} var cartRecordsWithProductDetails = await ShoppingCartTestHelpers.GetCart(100, ServiceAddress, RootAddress); Assert.Equal(0, cartRecordsWithProductDetails.Count); }
public async void ShouldUpdateCartRecordOnAddIfAlreadyExists() { // Add to Cart: http://localhost:55882/api/shoppingcartrecord/{customerId} HTTPPost // http://localhost:55882/api/shoppingcartrecord/1 {"ProductId":22,"Quantity":2,"CustomerId":1} // Content - Type:application / json using (var client = new HttpClient()) { var productId = _productId; var quantity = 3; 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.Single(cartWithCustomerInfo.CartRecords); var cartRecord = cartWithCustomerInfo.CartRecords[cartWithCustomerInfo.CartRecords.Count - 1]; Assert.Equal(_productId, cartRecord.ProductId); Assert.Equal("Travel", cartRecord.CategoryName); Assert.Equal(4, cartRecord.Quantity); }
public async void ShouldUpdateCartRecordOnAddIfAlreadyExists() { // Add to Cart: http://localhost:40001/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 = 3; 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 cartRecordWithProductInfos = await ShoppingCartTestHelpers.GetCart(_customerId, ServiceAddress, RootAddress); Assert.Equal(1, cartRecordWithProductInfos.Count); var cartRecord = cartRecordWithProductInfos[cartRecordWithProductInfos.Count - 1]; Assert.Equal(_productId, cartRecord.ProductId); Assert.Equal("Travel", cartRecord.CategoryName); Assert.Equal(4, cartRecord.Quantity); }
public async void ShouldReturnCustomersCart() { //Get Cart: http://localhost:40001/api/shoppingcart/{customerId} var cartRecordsWithProductDetails = await ShoppingCartTestHelpers.GetCart(_customerId, ServiceAddress, RootAddress); Assert.Equal(1, cartRecordsWithProductDetails.Count); Assert.Equal(_productId, cartRecordsWithProductDetails[0].ProductId); Assert.Equal("Travel", cartRecordsWithProductDetails[0].CategoryName); }
public async void ShouldReturnCustomersCart() { //Get Cart: http://localhost:7940/api/shoppingcart/{customerId} CartWithCustomerInfo cartWithCustomerInfo = await ShoppingCartTestHelpers.GetCart(_customerId, ServiceAddress, RootAddress); Assert.Single(cartWithCustomerInfo.CartRecords); Assert.Equal(_productId, cartWithCustomerInfo.CartRecords[0].ProductId); Assert.Equal("Travel", cartWithCustomerInfo.CartRecords[0].CategoryName); }
public async void ShouldDeleteRecordInTheCart() { // Remove Cart Item: http://localhost:7940/api/shoppingcart/{id} HTTPDelete // http://localhost:7940/api/shoppingcart/1 var cartRecord = await ShoppingCartTestHelpers.GetCartItem(_cartRecordId, ServiceAddress, RootAddress); //throw new Exception($"{cartRecord.Quantity}"); using (var client = new HttpClient()) { var targetUrl = $"{ServiceAddress}{RootAddress}/{cartRecord.Id}"; //throw new Exception(targetUrl); var response = await client.DeleteAsJsonAsync(targetUrl, cartRecord); Assert.True(response.IsSuccessStatusCode, response.ReasonPhrase); } // validate the cart item was updated CartWithCustomerInfo cartWithCustomerInfo = await ShoppingCartTestHelpers.GetCart(_customerId, ServiceAddress, "api/shoppingcart"); Assert.Empty(cartWithCustomerInfo.CartRecords); }
public async void ShouldDeleteRecordInTheCart() { // Remove Cart Item: http://localhost:61855/api/shoppingcart/{customerId}/{id}/{TimeStamp} HTTPDelete // http://localhost:61855/api/shoppingcart/1/2/AAAAAAAA1Uc= var cartRecord = await ShoppingCartTestHelpers.GetCartItem(_customerId, _productId, ServiceAddress, RootAddress); //throw new Exception($"{cartRecord.Quantity}"); var timeStampString = JsonConvert.SerializeObject(cartRecord.TimeStamp); using (var client = new HttpClient()) { var targetUrl = $"{ServiceAddress}{RootAddress}/{_customerId}/0/{timeStampString.Replace("\"", "")}"; //throw new Exception(targetUrl); var response = await client.DeleteAsync(targetUrl); //throw new Exception(response.StatusCode.ToString()); Assert.True(response.IsSuccessStatusCode); } // validate the cart item was updated var cart = await ShoppingCartTestHelpers.GetCart(_customerId, ServiceAddress, RootAddress); Assert.Equal(0, cart.Count); }
public async void ShouldRemoveRecordOnAddIfQuantityBecomesZero() { // Add to Cart: http://localhost:7940/api/shoppingcartrecord/{customerId} HTTPPost // http://localhost:7940/api/shoppingcartrecord/1 {"ProductId":22,"Quantity":2,"CustomerId":1} // 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},\"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.Empty(cartWithCustomerInfo.CartRecords); }
public async void ShouldRemoveRecordOnAddIfQuantityBecomesLessThanZero() { // Add to Cart: http://localhost:40001/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 = -10; 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); }