public async void ShouldUpdateRecordInTheCart()
        {
            //Change Cart Item(Quantity): http://localhost:55882/api/shoppingcart/{customerId}/{shoppingCartRecordId} HTTPPut
            //Note: Id, CustomerId, ProductId, TimeStamp, DateCreated, & Quantity in  body
            //{ "Id":1,"CustomerId":1,"ProductId":33,"Quantity":2, "TimeStamp":"AAAAAAAA86s=", "DateCreated":"1/20/2016"}
            var cartRecord = await ShoppingCartTestHelpers.GetCartItem(_cartRecordId, ServiceAddress, RootAddress);

            cartRecord.Quantity = 5;
            var json = JsonConvert.SerializeObject(cartRecord);

            using (var client = new HttpClient())
            {
                var targetUrl = $"{ServiceAddress}{RootAddress}/{cartRecord.Id}";
                //throw new Exception($"{targetUrl}:{json}");
                var response = await client.PutAsync(targetUrl,
                                                     new StringContent(json, Encoding.UTF8, "application/json"));

                if (!response.IsSuccessStatusCode)
                {
                    throw new Exception(response.StatusCode.ToString());
                }
                //Assert.True(response.IsSuccessStatusCode);
                Assert.Equal($"{ServiceAddress}api/shoppingcartrecord/{_customerId}".ToUpper(),
                             response.Headers.Location.AbsoluteUri.ToUpper());
            }
            // validate the cart item was updated
            var updatedCartRecord = await ShoppingCartTestHelpers.GetCartItem(_cartRecordId, ServiceAddress, RootAddress);

            Assert.Equal(5, updatedCartRecord.Quantity);
        }
Пример #2
0
        public async void ShouldNotDeleteMissingRecord()
        {
            // Remove Cart Item: http://localhost:7940/api/shoppingcart/{id} HTTPDelete
            // http://localhost:7940/api/shoppingcart/1
            var cartRecord = await ShoppingCartTestHelpers.GetCartItem(_cartRecordId, ServiceAddress, RootAddress);

            using (var client = new HttpClient())
            {
                var targetUrl = $"{ServiceAddress}{RootAddress}/100";
                var response  = await client.DeleteAsJsonAsync(targetUrl, cartRecord);

                Assert.False(response.IsSuccessStatusCode);
                Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
            }
        }
        public async void ShouldNotDeleteMissingRecord()
        {
            // 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);

            var timeStampString = JsonConvert.SerializeObject(cartRecord.TimeStamp);

            using (var client = new HttpClient())
            {
                var targetUrl = $"{ServiceAddress}{RootAddress}/{_customerId}/100/{timeStampString}";
                var response  = await client.DeleteAsync(targetUrl);

                Assert.False(response.IsSuccessStatusCode);
                var message = await response.Content.ReadAsStringAsync();

                var messageObject = JsonConvert.DeserializeObject <ErrorMessage>(message);
                Assert.Equal("Concurrency Issue.", messageObject.Error);
            }
        }
Пример #4
0
        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 ShouldRemoveRecordOnUpdateIfQuantityBecomesLessThanZero()
        {
            var cartRecord = await ShoppingCartTestHelpers.GetCartItem(_cartRecordId, ServiceAddress, RootAddress);

            cartRecord.Quantity = -10;
            var json = JsonConvert.SerializeObject(cartRecord);

            using (var client = new HttpClient())
            {
                var targetUrl = $"{ServiceAddress}{RootAddress}/{cartRecord.Id}";
                var response  = await client.PutAsync(targetUrl,
                                                      new StringContent(json, Encoding.UTF8, "application/json"));

                Assert.True(response.IsSuccessStatusCode);
                Assert.Equal($"{ServiceAddress}api/shoppingcartrecord/{_customerId}".ToUpper(),
                             response.Headers.Location.AbsoluteUri.ToUpper());
            }
            // validate the cart record was removed
            var cartItem = await ShoppingCartTestHelpers.GetCartItem(_cartRecordId, ServiceAddress, RootAddress);

            Assert.Null(cartItem);
        }
        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);
        }