Exemplo n.º 1
0
        public void AddItemToCartShouldAddItemIfNotExists()
        {
            Product prod = new Product {
                ProductName = "testprod", ProductPrice = 1
            };
            Location loc = new Location {
                LocationName = "testloc", LocationAddress = "asdf"
            };
            User user = new User {
                UserName = "******", isManager = false
            };

            using (var ctx = new StoreContext(options))
            {
                StoreRepoDB repo = new StoreRepoDB(ctx);
                ctx.Products.Add(prod);
                ctx.Locations.Add(loc);
                ctx.Users.Add(user);
                ctx.SaveChanges();
                Order cart = new Order {
                    UserId = user.UserId, CheckoutTimestamp = null
                };
                ctx.SaveChanges();
                repo.AddItemToCart(user.UserId, prod.ProductId, loc.LocationId, 5, true);
                ctx.SaveChanges();
            }
            using (var assertCtx = new StoreContext(options))
            {
                StoreRepoDB repo = new StoreRepoDB(assertCtx);
                var         cart = assertCtx.Orders.Include(order => order.orderItems).FirstOrDefault(order => order.UserId == user.UserId && order.CheckoutTimestamp == null);
                Assert.NotNull(cart);
                Assert.Single(cart.orderItems);
                Assert.Equal(5, cart.orderItems[0].Quantity);
            }
        }
Exemplo n.º 2
0
 public bool AddItemToCart(int userId, int productId, int locationId, int n)
 {
     if (!repo.SetLocationInventory(productId, locationId, -n, true))
     {
         return(false);
     }
     return(repo.AddItemToCart(userId, productId, locationId, n, true));
 }
Exemplo n.º 3
0
        public void CheckOutShouldApplyTimestamp()
        {
            Product prod = new Product {
                ProductName = "testprod", ProductPrice = 1
            };
            Location loc = new Location {
                LocationName = "testloc", LocationAddress = "asdf"
            };
            User user = new User {
                UserName = "******", isManager = false
            };
            DateTime before = DateTime.Now;

            using (var ctx = new StoreContext(options))
            {
                StoreRepoDB repo = new StoreRepoDB(ctx);
                ctx.Products.Add(prod);
                ctx.Locations.Add(loc);
                ctx.Users.Add(user);
                ctx.SaveChanges();
                Order cart = new Order {
                    UserId = user.UserId, CheckoutTimestamp = null
                };
                ctx.SaveChanges();
                repo.AddItemToCart(user.UserId, prod.ProductId, loc.LocationId, 5, true);
                ctx.SaveChanges();
                repo.CheckOut(user.UserId);
                ctx.SaveChanges();
            }
            using (var assertCtx = new StoreContext(options))
            {
                StoreRepoDB repo = new StoreRepoDB(assertCtx);
                var         cart = assertCtx.Orders.Include(order => order.orderItems).FirstOrDefault(order => order.UserId == user.UserId);
                Assert.NotNull(cart);
                Assert.NotNull(cart.CheckoutTimestamp);
                DateTime after = DateTime.Now;
                Assert.True(before <= cart.CheckoutTimestamp);
                Assert.True(cart.CheckoutTimestamp <= after);
            }
        }