예제 #1
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);
            }
        }
예제 #2
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);
            }
        }
예제 #3
0
        public async Task UpdateAsync()
        {
            DbContextOptions <ReFreshDbContext> options = new DbContextOptionsBuilder <ReFreshDbContext>().UseInMemoryDatabase("UpdateProduct").Options;

            using (ReFreshDbContext context = new ReFreshDbContext(options))
            {
                Product testProduct = new Product();
                testProduct.ID          = 1;
                testProduct.Sku         = 1;
                testProduct.Name        = "Test Product";
                testProduct.Price       = 5;
                testProduct.Description = "This is a test";
                testProduct.Image       = "https://image-url.com";

                InventoryManagementService ims = new InventoryManagementService(context);
                await ims.CreateAsync(testProduct);

                Product updateProduct = testProduct;
                updateProduct.Name = "Update Product";

                await ims.UpdateAsync(updateProduct);

                Product p = await ims.GetOneByIdAsync(testProduct.ID);

                Assert.True(p.Name == "Update Product");
            }
        }
예제 #4
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);
            }
        }
예제 #5
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);
            }
        }
예제 #6
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);
            }
        }
예제 #7
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);
            }
        }
예제 #8
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);
            }
        }
예제 #9
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));
            }
        }
예제 #10
0
        public async Task DeleteAsync()
        {
            DbContextOptions <ReFreshDbContext> options = new DbContextOptionsBuilder <ReFreshDbContext>().UseInMemoryDatabase("DeleteProduct").Options;

            using (ReFreshDbContext context = new ReFreshDbContext(options))
            {
                Product testProduct = new Product();
                testProduct.Sku         = 1;
                testProduct.Name        = "Test Product";
                testProduct.Price       = 5;
                testProduct.Description = "This is a test";
                testProduct.Image       = "https://image-url.com";

                InventoryManagementService ims = new InventoryManagementService(context);
                await ims.CreateAsync(testProduct);

                await ims.DeleteAsync(testProduct.ID);

                await Assert.ThrowsAsync <ArgumentNullException> (() => ims.DeleteAsync(testProduct.ID));
            }
        }
예제 #11
0
        public async Task CreateAsync()
        {
            DbContextOptions <ReFreshDbContext> options = new DbContextOptionsBuilder <ReFreshDbContext>().UseInMemoryDatabase("CreateProduct").Options;

            using (ReFreshDbContext context = new ReFreshDbContext(options))
            {
                Product testProduct = new Product();
                testProduct.Sku         = 1;
                testProduct.Name        = "Test Product";
                testProduct.Price       = 5;
                testProduct.Description = "This is a test";
                testProduct.Image       = "https://image-url.com";

                InventoryManagementService ims = new InventoryManagementService(context);
                await ims.CreateAsync(testProduct);

                var result = context.Inventory.FirstOrDefaultAsync(pr => pr.ID == testProduct.ID);

                Assert.True(testProduct.Sku == result.Result.Sku);
            }
        }
예제 #12
0
        public async Task GetAllAsync()
        {
            DbContextOptions <ReFreshDbContext> options = new DbContextOptionsBuilder <ReFreshDbContext>().UseInMemoryDatabase("GetAllProduct").Options;

            using (ReFreshDbContext context = new ReFreshDbContext(options))
            {
                Product testProduct = new Product();
                testProduct.Sku         = 1;
                testProduct.Name        = "Test Product";
                testProduct.Price       = 5;
                testProduct.Description = "This is a test";
                testProduct.Image       = "https://image-url.com";

                InventoryManagementService ims = new InventoryManagementService(context);
                await ims.CreateAsync(testProduct);

                List <Product> result = await ims.GetAllAsync() as List <Product>;

                Assert.True(result.Count == 1);
            }
        }
예제 #13
0
 public InventoryManagementService(ReFreshDbContext context)
 {
     _db = context;
 }
예제 #14
0
 public SearchBarManagementService(ReFreshDbContext context)
 {
     _context = context;
 }
예제 #15
0
 public CartManagementService(ReFreshDbContext context)
 {
     _context = context;
 }