public void ItemUpdateQuantityCanChangeStateToModified() { var cart = NewCart.CreateCartFromProductSelection("", null, 1, 1, 9.99m); cart.CartItems.First().UpdateQuantity(2); Assert.AreEqual(ObjectState.Modified, cart.CartItems.First().State); }
public void CanAddNewCartWithProductToCartsDbSet() { var cart = NewCart.CreateCartFromProductSelection(_theUri, null, 1, 1, 9.99m); _context.Carts.Add(cart); Assert.AreEqual(1, _context.Carts.Local.Count); }
private int SeedCartAndReturnId(WebSiteOrderData repo) { var cart = NewCart.CreateCartFromProductSelection(_theUri, null, 1, 1, 9.99m); var createdCart = repo.StoreCartWithInitialProduct(cart); return(createdCart.CartId); }
private RevisitedCart InitializeCart(int productId, int quantity, decimal displayedPrice, string sourceUrl, string memberCookie) { var cart = NewCart.CreateCartWithProduct(sourceUrl, memberCookie, productId, quantity, displayedPrice); return(_dao.StoreCartWithInitialProduct(cart)); }
public void CanStoreCartWithInitialProduct() { var cart = NewCart.CreateCartFromProductSelection(_theUri, null, 1, 1, 9.99m); var data = new WebSiteOrderData(_context, _refContext); var resultCart = data.StoreCartWithInitialProduct(cart); WriteLog(); Assert.AreNotEqual(0, resultCart.CartId); }
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 FixStateCanInterpretLocalState() { var cart = NewCart.CreateCartFromProductSelection(_theUri, null, 1, 1, 9.99m); cart.CartItems.First().UpdateQuantity(2); _context.Carts.Attach(cart); _context.FixState(); Assert.AreEqual(EntityState.Unchanged, _context.Entry(cart).State); Assert.AreEqual(EntityState.Modified, _context.Entry(cart.CartItems.First()).State); }
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); }
private void CheckForExistingCustomer(NewCart newCart) { if (newCart.CustomerCookie != null) { var customerId = _refContext.Customers.AsNoTracking() .Where(c => c.CustomerCookie == newCart.CustomerCookie) .Select(c => c.CustomerId).FirstOrDefault(); if (customerId > 0) { newCart.CustomerFound(customerId); } } }
public RevisitedCart StoreCartWithInitialProduct(NewCart newCart) { if (newCart.CartItems.Count != 1) { return(null); } CheckForExistingCustomer(newCart); _context.Carts.Add(newCart); _context.SaveChanges(); var cart = RevisitedCart.CreateWithItems(newCart.CartId, newCart.CartItems); cart.SetCookieData(newCart.CartCookie, newCart.Expires); return(cart); }
public async Task <IActionResult> AddNewCartDetail([FromBody] NewCart newCart) { try { await _repository.Cart.AddToCartAsync(newCart.CartId, newCart.ProductId); var shoppingCart = new ShoppingCart(await _repository.Cart.GetCartsByCartIdAsync(newCart.CartId)); return(Ok(shoppingCart)); } catch (Exception ex) { _logger.LogError($"Something went wrong inside AddToCart action: {ex.Message}"); return(StatusCode(500, "Internal server error")); } }
public void DeleteFromCart(CartItemModel RemoveItem) { List <CartItemModel> Cart = (List <CartItemModel>)View.Cart; List <CartItemModel> NewCart = null; long TotalPrice = 0; foreach (CartItemModel Item in Cart) { if (Item.ProductID != RemoveItem.ProductID) { if (NewCart == null) { NewCart = new List <CartItemModel>(); } NewCart.Add(Item); TotalPrice += Item.Price * Item.BuyQuantity; } } View.Cart = NewCart; View.TotalPrice = TotalPrice; }
public void CanCreateNewCartFromProductSelectionWithNoKnownCustomer() { var cart = NewCart.CreateCartFromProductSelection("http://thedatafarm.com", null, 1, 1, 9.99m); Assert.AreEqual(9.99m, cart.CartItems.Single().CurrentPrice); }
public RevisitedCart StoreCartWithInitialProduct(NewCart cart) { throw new NotImplementedException(); }