public void Process_ListProduct_True()
        {
            InventoryService iService = new InventoryService();

            iService.CreateProduct(new Product {
                ProductID = 1, ProductName = "Fridge"
            });
            iService.CreateProduct(new Product {
                ProductID = 2, ProductName = "Television"
            });

            Assert.Equal(2, iService.GetProducts().Count);
        }
        public void Process_DeleteProduct_True()
        {
            InventoryService iService = new InventoryService();

            iService.CreateProduct(new Product {
                ProductID = 1, ProductName = "Fridge"
            });
            iService.CreateProduct(new Product {
                ProductID = 2, ProductName = "TV"
            });

            int productId = 2;

            Assert.True(iService.DeleteProduct(productId));
        }
Beispiel #3
0
        public async Task CanAddProductToDb()
        {
            DbContextOptions <StoreDbContext> options = new DbContextOptionsBuilder <StoreDbContext>()
                                                        .UseInMemoryDatabase("TestDb1")
                                                        .Options;

            using (StoreDbContext context = new StoreDbContext(options))
            {
                InventoryService service = new InventoryService(context);

                Product product = new Product()
                {
                    ID          = 7,
                    Name        = "Mismatched Socks",
                    Sku         = "69xls69",
                    Description = "The Left one is red, and XL, the Right one is blue and S",
                    Size        = Sizes.M,
                    Price       = 56.99M,
                    Image       = "someimage.jpg"
                };

                var result = await service.CreateProduct(product);

                var data = context.Products.Find(product.ID);
                Assert.Equal(result, data);
            }
        }
Beispiel #4
0
        public async void CanDeleteCheckoutProduct()
        {
            DbContextOptions <NurseryDbContext> options = new DbContextOptionsBuilder <NurseryDbContext>().UseInMemoryDatabase("GetBasektProduct").Options;

            using (NurseryDbContext context = new NurseryDbContext(options))
            {
                InventoryService       inventoryService       = new InventoryService(context);
                CheckoutProductService checkoutProductService = new CheckoutProductService(context);
                CheckoutService        checkoutService        = new CheckoutService(context);
                Checkout checkout = new Checkout();
                await checkoutService.CreateCheckoutAsync(checkout);

                Product product = new Product();
                await inventoryService.CreateProduct(product);

                await checkoutProductService.AddCheckoutProduct(product.ID, 3, checkout.ID);

                var checkoutProduct = await checkoutProductService.GetCheckoutProductByID(checkout.ID, product.ID);

                await checkoutProductService.DeleteCheckoutProductByID(checkout.ID, product.ID);

                var actual = await checkoutProductService.GetCheckoutProductByID(checkout.ID, product.ID);

                Assert.Null(actual);
            }
        }
        public void Process_GetProduct_True()
        {
            InventoryService iService = new InventoryService();

            iService.CreateProduct(new Product {
                ProductID = 1, ProductName = "Fridge"
            });
            iService.CreateProduct(new Product {
                ProductID = 2, ProductName = "Washing Machine"
            });

            int    productId   = 2;
            string productName = "Washing Machine";

            Assert.Equal(productName, iService.GetProduct(productId).ProductName);
        }
Beispiel #6
0
        public async void CanDeleteBasketProduct()
        {
            DbContextOptions <NurseryDbContext> options = new DbContextOptionsBuilder <NurseryDbContext>().UseInMemoryDatabase("GetBasektProduct").Options;

            using (NurseryDbContext context = new NurseryDbContext(options))
            {
                InventoryService     inventoryService     = new InventoryService(context);
                BasketProductService basketProductService = new BasketProductService(context);
                BasketService        basketService        = new BasketService(context);
                Basket basket = new Basket();
                await basketService.CreateBasketAsync(basket);

                Product product = new Product();
                await inventoryService.CreateProduct(product);

                await basketProductService.AddBasketProduct(product.ID, 3, basket.ID);

                var basketProduct = await basketProductService.GetBasketProductByID(basket.ID, product.ID);

                await basketProductService.DeleteBasketProductByID(basket.ID, product.ID);

                var actual = await basketProductService.GetBasketProductByID(basket.ID, product.ID);

                Assert.Null(actual);
            }
        }
Beispiel #7
0
        public async Task CanUpdateProduct()
        {
            DbContextOptions <StoreDbContext> options = new DbContextOptionsBuilder <StoreDbContext>()
                                                        .UseInMemoryDatabase("TestDb4")
                                                        .Options;

            using StoreDbContext context = new StoreDbContext(options);
            InventoryService service = new InventoryService(context);

            var product = new Product()
            {
                ID          = 14,
                Name        = "My favorite Cardigan",
                Sku         = "33somanyholes33",
                Description = "My mom made me donate this, even though the hole is barely the size of a softball!",
                Size        = Sizes.S,
                Price       = 32.99M,
                Image       = "cardigan.jpg"
            };
            await service.CreateProduct(product);

            product.Price = 46.99M;

            await service.UpdateProduct(product);

            decimal upsell = service.GetProductById(14).Result.Price;

            Assert.Equal(46.99M, upsell);
        }
Beispiel #8
0
        public async Task CanDeleteProduct()
        {
            DbContextOptions <StoreDbContext> options = new DbContextOptionsBuilder <StoreDbContext>()
                                                        .UseInMemoryDatabase("TestDb5")
                                                        .Options;

            using StoreDbContext context = new StoreDbContext(options);
            InventoryService service = new InventoryService(context);

            var product = new Product()
            {
                ID          = 14,
                Name        = "My favorite Cardigan",
                Sku         = "33somanyholes33",
                Description = "My mom made me donate this, even though the hole is barely the size of a softball!",
                Size        = Sizes.S,
                Price       = 32.99M,
                Image       = "cardigan.jpg"
            };
            await service.CreateProduct(product);

            await service.DeleteProduct(product.ID);

            Assert.Null(await service.GetProductById(product.ID));
        }
        public void Process_UpdateProduct_True()
        {
            InventoryService iService = new InventoryService();

            iService.CreateProduct(new Product {
                ProductID = 1, ProductName = "Fridge"
            });
            iService.CreateProduct(new Product {
                ProductID = 2, ProductName = "TV"
            });

            int    productId      = 2;
            string newProductName = "Television";

            iService.UpdateProduct(productId, newProductName);

            Assert.Equal(newProductName, iService.GetProduct(productId).ProductName);
        }
        public void Process_CreateProduct_True()
        {
            InventoryService iService = new InventoryService();

            iService.CreateProduct(new Product {
                ProductID = 3, ProductName = "Washing Machine"
            });

            Assert.Equal("Washing Machine", iService.GetProduct(3).ProductName);
        }
Beispiel #11
0
        public async Task CanGetAllProducts()
        {
            DbContextOptions <StoreDbContext> options = new DbContextOptionsBuilder <StoreDbContext>()
                                                        .UseInMemoryDatabase("TestDb3")
                                                        .Options;

            using StoreDbContext context = new StoreDbContext(options);
            InventoryService service = new InventoryService(context);

            var products = new List <Product>
            {
                new Product()
                {
                    ID          = 3,
                    Name        = "Broken Glasses",
                    Sku         = "20nomore20",
                    Description = "One lens is missing, the other is a half inch thick.",
                    Size        = Sizes.L,
                    Price       = 20.40M,
                    Image       = "picture.jpg"
                },
                new Product()
                {
                    ID          = 7,
                    Name        = "Mismatched Socks",
                    Sku         = "69xls69",
                    Description = "The Left one is red, and XL, the Right one is blue and S",
                    Size        = Sizes.M,
                    Price       = 56.99M,
                    Image       = "someimage.jpg"
                },
                new Product()
                {
                    ID          = 14,
                    Name        = "My favorite Cardigan",
                    Sku         = "33somanyholes33",
                    Description = "My mom made me donate this, even though the hole is barely the size of a softball!",
                    Size        = Sizes.S,
                    Price       = 32.99M,
                    Image       = "cardigan.jpg"
                }
            };

            foreach (var p in products)
            {
                await service.CreateProduct(p);
            }

            Assert.Equal(products, await service.GetProducts());
        }
Beispiel #12
0
        public async void CanGetProduct()
        {
            DbContextOptions <NurseryDbContext> options = new DbContextOptionsBuilder <NurseryDbContext>().UseInMemoryDatabase("test").Options;

            using (NurseryDbContext context = new NurseryDbContext(options))
            {
                InventoryService inventoryService = new InventoryService(context);
                Product          product          = new Product();
                await inventoryService.CreateProduct(product);

                var expected = await inventoryService.GetProductByID(product.ID);

                Assert.Equal(expected, product);
            }
        }
Beispiel #13
0
        public async void CanGetAllProduct()
        {
            DbContextOptions <NurseryDbContext> options = new DbContextOptionsBuilder <NurseryDbContext>().UseInMemoryDatabase("check2").Options;

            using (NurseryDbContext context = new NurseryDbContext(options))
            {
                InventoryService inventoryService = new InventoryService(context);
                Product          product          = new Product();
                await inventoryService.CreateProduct(product);

                var expected = await inventoryService.GetAllProducts();

                Assert.Equal(new List <Product> {
                    product
                }, expected);
            }
        }
Beispiel #14
0
        public void CreateProduct_AddingNewProduct_ReturnTrue()
        {
            //BP-2.	Follow AAA rule. Arrange, Act and Assert
            //Arrange
            InventoryService invService = new InventoryService();
            Product          newProduct = new Product {
                ProductId = 1, ProductName = "Fridge", ReorderLevel = 4, StockIn = 10, UnitPrice = 1200
            };
            Product expectedProduct = new Product {
                ProductId = 1, ProductName = "Fridge", ReorderLevel = 4, StockIn = 10, UnitPrice = 1200
            };

            //Act
            int result = invService.CreateProduct(newProduct);

            //Assert
            Assert.AreEqual(expectedProduct.ProductId, result);
        }
Beispiel #15
0
        public async void CanUpdateProduct()
        {
            DbContextOptions <NurseryDbContext> options = new DbContextOptionsBuilder <NurseryDbContext>().UseInMemoryDatabase("check3").Options;

            using (NurseryDbContext context = new NurseryDbContext(options))
            {
                InventoryService inventoryService = new InventoryService(context);
                Product          product          = new Product();
                product.Name = "flower";
                await inventoryService.CreateProduct(product);

                product.Name = "sunflower";
                await inventoryService.Update(product);

                var expected = await inventoryService.GetProductByID(product.ID);

                Assert.Equal("sunflower", expected.Name);
            }
        }
Beispiel #16
0
        public async void CanCreateBasketProduct()
        {
            DbContextOptions <NurseryDbContext> options = new DbContextOptionsBuilder <NurseryDbContext>().UseInMemoryDatabase("test").Options;

            using (NurseryDbContext context = new NurseryDbContext(options))
            {
                InventoryService     inventoryService     = new InventoryService(context);
                BasketProductService basketProductService = new BasketProductService(context);
                BasketService        basketService        = new BasketService(context);
                Basket basket = new Basket();
                await basketService.CreateBasketAsync(basket);

                Product product = new Product();
                await inventoryService.CreateProduct(product);

                await basketProductService.AddBasketProduct(product.ID, 3, basket.ID);

                var expected = await context.BasketProducts.FirstOrDefaultAsync(p => p.BasketID == basket.ID && p.ProductID == product.ID);

                Assert.NotNull(expected);
            }
        }
Beispiel #17
0
        public async void CanCreateCheckoutProduct()
        {
            DbContextOptions <NurseryDbContext> options = new DbContextOptionsBuilder <NurseryDbContext>().UseInMemoryDatabase("test").Options;

            using (NurseryDbContext context = new NurseryDbContext(options))
            {
                InventoryService       inventoryService       = new InventoryService(context);
                CheckoutProductService checkoutProductService = new CheckoutProductService(context);
                CheckoutService        checkoutService        = new CheckoutService(context);
                Checkout checkout = new Checkout();
                await checkoutService.CreateCheckoutAsync(checkout);

                Product product = new Product();
                await inventoryService.CreateProduct(product);

                await checkoutProductService.AddCheckoutProduct(product.ID, 3, checkout.ID);

                var expected = await context.CheckoutProducts.FirstOrDefaultAsync(p => p.CheckoutID == checkout.ID && p.ProductID == product.ID);

                Assert.NotNull(expected);
            }
        }
Beispiel #18
0
        public async Task CanGetProductFromDb()
        {
            DbContextOptions <StoreDbContext> options = new DbContextOptionsBuilder <StoreDbContext>()
                                                        .UseInMemoryDatabase("TestDb2")
                                                        .Options;

            using StoreDbContext context = new StoreDbContext(options);
            InventoryService service = new InventoryService(context);

            var result = await service.CreateProduct(new Product()
            {
                ID          = 3,
                Name        = "Broken Glasses",
                Sku         = "20nomore20",
                Description = "One lens is missing, the other is a half inch thick.",
                Size        = Sizes.L,
                Price       = 20.40M,
                Image       = "picture.jpg"
            });

            Assert.Equal(result, await service.GetProductById(result.ID));
        }
Beispiel #19
0
        public static int process(int option)
        {
            int result = 0;

            switch (option)
            {
            case 1:
                Console.WriteLine("= = = = = = = = = = = = =");
                Console.WriteLine("Listing products");
                Console.WriteLine("= = = = = = = = = = = = =");
                foreach (var item in prodService.GetProducts())
                {
                    Console.WriteLine(string.Format("{0}, {1}", item.ProductID, item.ProductName));
                }
                result = prodService.GetProducts().Count;
                break;

            case 2:
                Console.WriteLine("= = = = = = = = = = = = =");
                Console.WriteLine("Add product");
                Console.WriteLine("= = = = = = = = = = = = =");
                Console.WriteLine("Enter ProductID");
                int productId = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("Enter Product Name");
                string productName = Convert.ToString(Console.ReadLine());

                Product product = new Product {
                    ProductID = productId, ProductName = productName
                };
                prodService.CreateProduct(product);

                break;

            case 3:
                Console.WriteLine("= = = = = = = = = = = = =");
                Console.WriteLine("Edit product");
                Console.WriteLine("= = = = = = = = = = = = =");

                Console.WriteLine("Enter ProductID");
                int productId_Edit = Convert.ToInt32(Console.ReadLine());

                Console.WriteLine("Old Product Name");

                Product product_Edit = prodService.GetProduct(productId_Edit);
                Console.WriteLine(product_Edit.ProductName);

                Console.WriteLine("Enter New Product Name");
                product_Edit.ProductName = Convert.ToString(Console.ReadLine());

                prodService.UpdateProduct(productId_Edit, product_Edit.ProductName);

                break;

            case 4:
                Console.WriteLine("= = = = = = = = = = = = =");
                Console.WriteLine("Delete Product");
                Console.WriteLine("= = = = = = = = = = = = =");

                Console.WriteLine("Enter ProductID");
                int productId_Delete = Convert.ToInt32(Console.ReadLine());

                Console.WriteLine("Product Name to be deleted");

                Product product_Delete = prodService.GetProduct(productId_Delete);
                Console.WriteLine(product_Delete.ProductName);

                Console.WriteLine("Are you sure you want to delete? Type Yes or No.");
                string confirmation = Convert.ToString(Console.ReadLine());

                if (confirmation.ToLower() == "yes")
                {
                    prodService.DeleteProduct(productId_Delete);
                }
                else
                {
                    Console.WriteLine("No proper input. Not deleted.");
                }

                break;

            case 5:
                break;

            default:
                break;
            }

            return(result);
        }