Exemplo n.º 1
0
        public void CreateCartShouldMakeNewOrder()
        {
            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.Users.Add(user);
                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.Null(cart);
                var newCart = repo.createCart(user.UserId);
                Assert.NotNull(newCart);
                Assert.Equal(user.UserId, newCart.UserId);
            }
        }
Exemplo n.º 2
0
        public Order GetCart(int userId)
        {
            List <Order> orders = repo.GetOrders(order => order.UserId == userId && order.CheckoutTimestamp == null);

            if (orders.Count == 0)
            {
                return(repo.createCart(userId));
            }
            foreach (OrderItem oi in orders[0].orderItems)
            {
                oi.Product  = repo.GetProductById(oi.ProductId);
                oi.Location = repo.GetLocationById(oi.LocationId);
            }
            return(orders[0]);
        }