private RevisitedCart AddItemToCart(int productId, int quantity,
                                            decimal displayedPrice, int cartId)
        {
            var cart = _siteOrderData.RetrieveCart(cartId);
            var item = cart.InsertNewCartItem(productId, quantity, displayedPrice);

            _siteOrderData.StoreNewCartItem(item);
            return(cart);
        }
        public void CanUpdateCartItems()
        {
            //Arrange
            var goodId = _context.Carts.Where(c => c.CartItems.Any())
                         .Select(c => c.CartId)
                         .FirstOrDefault();
            var data1              = new WebSiteOrderData(new ShoppingCartContext(), _refContext);
            var existingCart       = data1.RetrieveCart(goodId);
            var lineItemCount      = existingCart.CartItems.Count();
            var firstItem          = existingCart.CartItems.First();
            var originalTotalItems = existingCart.TotalItems;
            var originalQuantity   = firstItem.Quantity;

            existingCart.CartItems.First().UpdateQuantity(originalQuantity + 1);
            existingCart.InsertNewCartItem(1, 1, new decimal(100));
            //Act
            var data2 = new WebSiteOrderData(new ShoppingCartContext(), _refContext);

            data2.UpdateItemsForExistingCart(existingCart);
            //Assert
            var data3             = new WebSiteOrderData(new ShoppingCartContext(), _refContext);
            var existingCartAgain = data3.RetrieveCart(goodId);

            Assert.AreEqual(lineItemCount + 1, existingCartAgain.CartItems.Count());
            Assert.AreEqual(originalTotalItems + 2, existingCartAgain.TotalItems);
        }
Exemplo n.º 3
0
        public void CanRetrieveCartFromRepoUsingCartId()
        {
            //note if you want to dropcreate the db do it before context creation
            var repo = new WebSiteOrderData(_context, _refContext);
            var id   = SeedCartAndReturnId(repo);

            Debug.WriteLine($"Stored Cart Id from database {id}");
            Assert.AreEqual(id, repo.RetrieveCart(id).CartId);
        }
Exemplo n.º 4
0
        public void CanRetrieveCartAndItemsUsingCartCookieMocked()
        {
            var cart = NewCart.CreateCartFromProductSelection(_theUri, null, 1, 1, 9.99m);

            _cartsInMemory.Add(cart);
            var storedCartCookie = cart.CartCookie;
            var repo             = new WebSiteOrderData(_scMockingContext, _refMockingContext);

            Assert.AreEqual(1, repo.RetrieveCart(storedCartCookie).CartItems.Count());
        }
        public void CanRetrieveCartFromRepoUsingCartId()
        {
            //Arrange
            var cart        = NewCart.CreateCartFromProductSelection(_theUri, null, 1, 1, 9.99m);
            var data        = new WebSiteOrderData(_context, _refContext);
            var createdCart = data.StoreCartWithInitialProduct(cart);

            Debug.WriteLine($"Stored Cart Id from database {createdCart.CartId}");
            //Act (retrieve) and Assert
            Assert.AreEqual(createdCart.CartId, data.RetrieveCart(cart.CartId).CartId);
        }