Example #1
0
        public async System.Threading.Tasks.Task TestEditAsync()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "TestEdit")
                          .Options;
            var context = new ApplicationDbContext(options);

            var controller = new ProductCategoriesController(context);



            using (var context2 = new ApplicationDbContext(options))
            {
                context2.ProductCategory.Add(new ProductCategory
                {
                    CategoryName = "Shampoo"
                });
                context2.SaveChanges();
            }

            var result = await controller.Edit(1, new ProductCategory
            {
                CategoryId   = 1,
                CategoryName = "Hair Wax"
            });

            Assert.IsType <RedirectToActionResult>(result);
            using (var context2 = new ApplicationDbContext(options))
            {
                var cat = context2.ProductCategory.FirstOrDefault();
                Assert.Equal("Hair Wax", cat.CategoryName);
                context2.SaveChanges();
            }
        }
Example #2
0
        public async void Edit_ReturnNotFound(int?id)
        {
            // Arrange

            var mockRepo = new Mock <IAsyncRepository <ProductCategory> >();

            mockRepo.Setup(repo => repo.GetByIdAsync(id)).ReturnsAsync(GetCategories().Find(i => i.CategId == id));

            var controller = new ProductCategoriesController(mockRepo.Object);

            // Act

            var result = await controller.Edit(id);

            // Assert

            Assert.IsType <NotFoundResult>(result);
        }
Example #3
0
        public async void Edit_GetCurrentItem(int?id)
        {
            // Arrange

            var mockRepo = new Mock <IAsyncRepository <ProductCategory> >();

            mockRepo.Setup(repo => repo.GetByIdAsync(id)).ReturnsAsync(GetCategories().Find(i => i.CategId == id));

            var controller = new ProductCategoriesController(mockRepo.Object);

            // Act

            var result = await controller.Edit(id);

            // Assert

            var viewResult = Assert.IsType <ViewResult>(result);
            var model      = Assert.IsAssignableFrom <ProductCategory>(viewResult.Model);

            Assert.Equal(id, model.CategId);
        }