Beispiel #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);
            }
        }
Beispiel #2
0
        public async Task CanGetOpenCarts()
        {
            DbContextOptions <ReFreshDbContext> options = new DbContextOptionsBuilder <ReFreshDbContext>().UseInMemoryDatabase("GetLastTen").Options;

            using (ReFreshDbContext context = new ReFreshDbContext(options))
            {
                CartManagementService cms   = new CartManagementService(context);
                List <Cart>           carts = new List <Cart>();
                for (int i = 1; i <= 5; i++)
                {
                    await cms.CreateCartAsync($"test{i}");

                    carts.Add(await cms.GetCartAsync($"test{i}"));
                }
                for (int i = 6; i <= 10; i++)
                {
                    await cms.CreateCartAsync($"test{i}");

                    Cart cart = await cms.GetCartAsync($"test{i}");

                    await cms.CloseCartAsync(cart);

                    carts.Add(await cms.GetCartAsync($"test{i}"));
                }

                var result = await cms.GetOpenCarts();

                Assert.Equal(carts, result);
            }
        }
Beispiel #3
0
        public async Task CanGetCart()
        {
            DbContextOptions <ReFreshDbContext> options = new DbContextOptionsBuilder <ReFreshDbContext>().UseInMemoryDatabase("GetCartAsync").Options;

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

                var result = await cms.GetCartAsync("test");

                Assert.Equal("test", result.UserName);
            }
        }
Beispiel #4
0
        public async Task CanCreateCart()
        {
            DbContextOptions <ReFreshDbContext> options = new DbContextOptionsBuilder <ReFreshDbContext>().UseInMemoryDatabase("CreateCartAsync").Options;

            using (ReFreshDbContext context = new ReFreshDbContext(options))
            {
                var now = DateTime.Now;

                CartManagementService cms = new CartManagementService(context);
                await cms.CreateCartAsync("test");

                var result = context.Carts.FirstOrDefaultAsync(pr => pr.UserName == "test");

                Assert.Equal("test", result.Result.UserName);
            }
        }
Beispiel #5
0
        public async Task CanCloseCart()
        {
            DbContextOptions <ReFreshDbContext> options = new DbContextOptionsBuilder <ReFreshDbContext>().UseInMemoryDatabase("CloseCartAsync").Options;

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

                var testCart = await context.Carts.FirstOrDefaultAsync(pr => pr.UserName == "test cart");

                await cms.CloseCartAsync(testCart);

                var result = await context.Carts.FirstOrDefaultAsync(pr => pr.UserName == "test cart");

                Assert.NotNull(result.Completed);
            }
        }
        public async void TestReadCart()
        {
            DbContextOptions <CreaturesDbcontext> options = new DbContextOptionsBuilder <CreaturesDbcontext>().UseInMemoryDatabase("ReadCart").Options;

            using (CreaturesDbcontext context = new CreaturesDbcontext(options))
            {
                Cart testCart4 = new Cart();
                testCart4.ID     = 1;
                testCart4.UserID = "aUserID";

                CartManagementService cartService = new CartManagementService(context);

                await cartService.Create(testCart4);

                var cart2Answer = await cartService.GetCart("aUserID");

                Assert.Equal(testCart4, cart2Answer);
            }
        }
        public async void TestCreateCart()
        {
            DbContextOptions <CreaturesDbcontext> options = new DbContextOptionsBuilder <CreaturesDbcontext>().UseInMemoryDatabase("CreateCart").Options;

            using (CreaturesDbcontext context = new CreaturesDbcontext(options))
            {
                Cart testCart3 = new Cart();
                testCart3.ID     = 1;
                testCart3.UserID = "aUserID";

                CartManagementService cartService = new CartManagementService(context);

                await cartService.Create(testCart3);

                var cart1Answer = context.Carts.FirstOrDefault(c => c.ID == testCart3.ID);

                Assert.Equal(testCart3, cart1Answer);
            }
        }
Beispiel #8
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);
            }
        }
Beispiel #9
0
        public async Task CanGetCartByID()
        {
            DbContextOptions <ReFreshDbContext> options = new DbContextOptionsBuilder <ReFreshDbContext>().UseInMemoryDatabase("GetCartByID").Options;

            using (ReFreshDbContext context = new ReFreshDbContext(options))
            {
                CartManagementService cms = new CartManagementService(context);
                Cart cart = new Cart()
                {
                    UserName  = "******",
                    Completed = null
                };
                await context.Carts.AddAsync(cart);

                await context.SaveChangesAsync();

                var result = await cms.GetCartByIdAsync(cart.ID);

                Assert.Equal("test", result.UserName);
            }
        }
Beispiel #10
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));
            }
        }