Beispiel #1
0
        public async Task TestDeleteCurrentProduct()
        {
            DbContextOptions <FoodProductsContext> options = new DbContextOptionsBuilder <FoodProductsContext>().UseInMemoryDatabase(databaseName: "DeleteCurrentProduct").Options;

            using (var context = new FoodProductsContext(options))
            {
                context.CurrentProducts.Add(new CurrentProducts()
                {
                    Product = "Milo"
                });
                context.SaveChanges();

                CurrentProducts currentProducts1 = context.CurrentProducts.First();

                CurrentProductsController currentProductsController = new CurrentProductsController(context);
                IActionResult             result = await currentProductsController.DeleteCurrentProducts(currentProducts1.Id) as IActionResult;

                var okObjectResult = result as OkObjectResult;
                Assert.IsNotNull(okObjectResult);

                var model = okObjectResult.Value as CurrentProducts;
                Assert.IsNotNull(model);
                Assert.AreNotEqual(0, model.Id);
                Assert.AreEqual(currentProducts1.Product, model.Product);

                Assert.AreEqual(false, context.MailingList.Any(x => x.Id == currentProducts1.Id));
            }
        }
Beispiel #2
0
        public async Task TestGetCurrentProducts()
        {
            DbContextOptions <FoodProductsContext> options = new DbContextOptionsBuilder <FoodProductsContext>().UseInMemoryDatabase(databaseName: "GetCurrentProducts").Options;

            using (var context = new FoodProductsContext(options))
            {
                context.CurrentProducts.Add(new CurrentProducts()
                {
                    Product = "Nespresso"
                });
                context.CurrentProducts.Add(new CurrentProducts()
                {
                    Product = "Nesquik"
                });

                context.SaveChanges();
                CurrentProductsController currentProductsController = new CurrentProductsController(context);
                IActionResult             result = await currentProductsController.GetCurrentProducts() as IActionResult;

                var okObjectResult = result as OkObjectResult;
                Assert.IsNotNull(okObjectResult);

                var model = okObjectResult.Value as IEnumerable <CurrentProducts>;
                Assert.IsNotNull(model);
                Assert.AreEqual(2, model.Count());
            }
        }
Beispiel #3
0
        public async Task TestDeleteMailingList()
        {
            DbContextOptions <FoodProductsContext> options = new DbContextOptionsBuilder <FoodProductsContext>().UseInMemoryDatabase(databaseName: "DeleteMailingList").Options;

            using (var context = new FoodProductsContext(options))
            {
                context.MailingList.Add(new MailingList()
                {
                    Email = "*****@*****.**"
                });
                context.SaveChanges();

                MailingList mailingList1 = context.MailingList.First();

                MailingListsController mailingListsController = new MailingListsController(context);
                IActionResult          result = await mailingListsController.DeleteMailingList(mailingList1.Id) as IActionResult;

                var okObjectResult = result as OkObjectResult;
                Assert.IsNotNull(okObjectResult);

                var model = okObjectResult.Value as MailingList;
                Assert.IsNotNull(model);
                Assert.AreNotEqual(0, model.Id);
                Assert.AreEqual(mailingList1.Email, model.Email);

                Assert.AreEqual(false, context.MailingList.Any(x => x.Id == mailingList1.Id));
            }
        }
Beispiel #4
0
        public async Task TestGetMailingLists()
        {
            DbContextOptions <FoodProductsContext> options = new DbContextOptionsBuilder <FoodProductsContext>().UseInMemoryDatabase(databaseName: "GetMailingLists").Options;

            using (var context = new FoodProductsContext(options))
            {
                context.MailingList.Add(new MailingList()
                {
                    Email = "*****@*****.**"
                });
                context.MailingList.Add(new MailingList()
                {
                    Email = "*****@*****.**"
                });

                context.SaveChanges();
                MailingListsController mailingListsController = new MailingListsController(context);
                IActionResult          result = await mailingListsController.GetMailingLists() as IActionResult;

                var okObjectResult = result as OkObjectResult;
                Assert.IsNotNull(okObjectResult);

                var model = okObjectResult.Value as IEnumerable <MailingList>;
                Assert.IsNotNull(model);
                Assert.AreEqual(2, model.Count());
            }
        }
Beispiel #5
0
        public async Task TestGetNewProduct()
        {
            DbContextOptions <FoodProductsContext> options = new DbContextOptionsBuilder <FoodProductsContext>().UseInMemoryDatabase(databaseName: "GetNewProduct").Options;

            using (var context = new FoodProductsContext(options))
            {
                context.Add(new NewProducts()
                {
                    Product = "Milo"
                });
                context.SaveChanges();
                NewProducts           product1 = context.NewProducts.First();
                NewProductsController newProductsController = new NewProductsController(context);
                IActionResult         result = await newProductsController.GetNewProducts(product1.Id) as IActionResult;

                var okObjectResult = result as OkObjectResult;
                Assert.IsNotNull(okObjectResult);

                var model = okObjectResult.Value as NewProducts;
                Assert.IsNotNull(model);
                Assert.AreEqual(product1.Product, model.Product);
            }
        }