示例#1
0
        public async Task CanUpdateOrderInCart()
        {
            DbContextOptions <ReFreshDbContext> options = new DbContextOptionsBuilder <ReFreshDbContext>().UseInMemoryDatabase("UpdateOrderInCart").Options;

            using (ReFreshDbContext context = new ReFreshDbContext(options))
            {
                CartManagementService cms = new CartManagementService(context);
                await cms.CreateCartAsync("test");

                Order order = new Order();
                order.CartID    = 1;
                order.ProductID = 1;
                order.Qty       = 5;
                order.ExtPrice  = 25;
                await cms.AddOrderToCart(order);

                order.ExtPrice = 30;

                await cms.UpdateOrderInCart(order);

                var result = await context.Orders.FirstOrDefaultAsync(o => o.CartID == 1 && o.ProductID == 1);

                Assert.Equal(30, result.ExtPrice);
            }
        }
示例#2
0
        public async Task CanGetOrderByCK()
        {
            DbContextOptions <ReFreshDbContext> options = new DbContextOptionsBuilder <ReFreshDbContext>().UseInMemoryDatabase("GetOrderByCK").Options;

            using (ReFreshDbContext context = new ReFreshDbContext(options))
            {
                CartManagementService cms = new CartManagementService(context);
                await cms.CreateCartAsync("test");

                Order order = new Order();
                order.CartID    = 1;
                order.ProductID = 1;
                order.Qty       = 5;
                order.ExtPrice  = 25;
                await cms.AddOrderToCart(order);

                var result = await cms.GetOrderByCK(1, 1);

                Assert.Equal(25, result.ExtPrice);
            }
        }
示例#3
0
        public async Task CanDeleteOrderFromCart()
        {
            DbContextOptions <ReFreshDbContext> options = new DbContextOptionsBuilder <ReFreshDbContext>().UseInMemoryDatabase("RemoveOrderFromCart").Options;

            using (ReFreshDbContext context = new ReFreshDbContext(options))
            {
                CartManagementService cms = new CartManagementService(context);
                var query = await cms.CreateCartAsync("test");

                Order order = new Order();
                order.CartID    = 1;
                order.ProductID = 1;
                order.Qty       = 5;
                order.ExtPrice  = 25;
                await cms.AddOrderToCart(order);

                await cms.DeleteOrderFromCart("test", 1);

                Assert.Null(await context.Orders.FirstOrDefaultAsync(o => o.CartID == 1 && o.ProductID == 1));
            }
        }