Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
0
 public bool CheckOut(int userId)
 {
     return(repo.CheckOut(userId));
 }