public void InitializeCartWithKnownCustomerStoresValueInCustomerId()
        {
            //will add mocking later ...

            using (var separateContext = new OrderSystemContext()) {
                if (!separateContext.Customers.Any(c => c.CustomerCookie == "CustomerCookieABCDE"))
                {
                    separateContext.Customers.Add(new Customer
                    {
                        CustomerCookie = "CustomerCookieABCDE",
                        DateOfBirth    = DateTime.Now,
                        FirstName      = "Julie",
                        LastName       = "Lerman"
                    });
                    separateContext.SaveChanges();
                }
            }
            var service = new WebSiteOrderingService(new WebSiteOrderData(_context));

            SetupLogging();
            RevisitedCart cart = service.ItemSelected(1, 1, 9.99m, theUri, "CustomerCookieABCDE", 0);

            WriteLog();
            Assert.AreNotEqual(0, _context.Carts.Find(cart.CartId).CustomerId);
        }
        public void CanInsertItemIntoEmptyRevisitedCart()
        {
            var cart = RevisitedCart.Create(1);

            cart.InsertNewCartItem(1, 1, 9.99m);
            Assert.AreEqual(1, cart.CartItems.Count());
        }
        public void CanCreateRevisitedCartWithExistingItems()
        {
            var cart = RevisitedCart.CreateWithItems(1, new List <CartItem> {
                CartItem.Create(1, 1, 9.99m, 1)
            });

            Assert.AreEqual(1, cart.CartItems.Count());
            Assert.AreEqual(9.99m, cart.CartItems.Single().CurrentPrice);
        }
        public void InitializeCartWithUnknownCustomerStoresZeroInCustomerId()
        {
            //will add mocking later ...
            var service = new WebSiteOrderingService(new WebSiteOrderData(_context));

            SetupLogging();
            RevisitedCart cart = service.ItemSelected(1, 1, 9.99m, theUri, null, 0);

            WriteLog();
            Assert.AreEqual(0, _context.Carts.Find(cart.CartId).CustomerId);
        }
 public void UpdateItemsForExistingCart(RevisitedCart cart)
 {
     _context.Configuration.AutoDetectChangesEnabled = false;
     foreach (var item in cart.CartItems)
     {
         _context.CartItems.Attach(item);
     }
     _context.ChangeTracker.DetectChanges();
     _context.FixState();
     _context.SaveChanges();
 }
        public RevisitedCart RetrieveCart(int cartId)
        {
            var cart = _context.Carts.AsNoTracking().Where(c => c.CartId == cartId).
                       Select(c => new { c.CartId, c.CartItems }).SingleOrDefault();

            if (cart != null)
            {
                return(RevisitedCart.CreateWithItems(cart.CartId, cart.CartItems));
            }
            return(RevisitedCart.Create(cartId));
        }
示例#7
0
        public void InitializeCartWithKnownCustomerStoresValueInCustomerId()
        {
            //will add mocking later ...


            var service = new WebSiteOrderingService(new WebSiteOrderData(_context, new ReferenceContext()));

            SetupLogging();
            RevisitedCart cart = service.ItemSelected(1, 1, 9.99m, theUri, "CustomerCookieABCDE", 0);

            WriteLog();
            Assert.AreNotEqual(0, _context.Carts.Find(cart.CartId).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 void InitializeCartWithKnownCustomerStoresValueInCustomerId()
        {
            //will add mocking later ...
            //this action begs for an external service or message queue to see if
            //CustomerCookieABCDE exists in test database
            //removed the code that inserted the data into the database
            var service = new WebSiteOrderingService(new WebSiteOrderData(_context, _refContext));

            SetupLogging();
            RevisitedCart cart = service.ItemSelected(1, 1, 9.99m, theUri, "CustomerCookieABCDE", 0);

            WriteLog();
            Assert.AreNotEqual(0, _context.Carts.Find(cart.CartId).CustomerId);
        }
        public void CanCreateRevisitedCartWithNoItems()
        {
            var cart = RevisitedCart.Create(1);

            Assert.AreEqual(1, cart.CartId);
        }