Example #1
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");
            }
        }
Example #2
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));
            }
        }
Example #3
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);
            }
        }
Example #4
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);
            }
        }