コード例 #1
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));
            }
        }
コード例 #2
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());
            }
        }
コード例 #3
0
        public async Task TestPostMailingList()
        {
            DbContextOptions <FoodProductsContext> options = new DbContextOptionsBuilder <FoodProductsContext>().UseInMemoryDatabase(databaseName: "PostMailingList").Options;

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

                MailingListsController mailingListsController = new MailingListsController(context);
                IActionResult          result = await mailingListsController.PostMailingList(mailingList1) 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(true, context.MailingList.Any(x => x.Id == model.Id));
            }
        }