Exemple #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);
            }
        }
Exemple #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);
            }
        }
Exemple #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");
            }
        }
Exemple #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);
            }
        }
Exemple #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);
            }
        }
Exemple #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);
            }
        }
Exemple #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);
            }
        }
Exemple #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);
            }
        }
Exemple #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));
            }
        }
Exemple #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));
            }
        }
Exemple #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);
            }
        }
Exemple #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);
            }
        }
Exemple #13
0
 public InventoryManagementService(ReFreshDbContext context)
 {
     _db = context;
 }
Exemple #14
0
 public SearchBarManagementService(ReFreshDbContext context)
 {
     _context = context;
 }
 public CartManagementService(ReFreshDbContext context)
 {
     _context = context;
 }