Exemplo n.º 1
0
        public void TestIndexView()
        {
            //gets a user
            var currUser = _dbContext.AppUser.Find("1");

            var context = TestInitHelper.CreateTestingControllerContext(currUser);

            ToDoListsController controller = new ToDoListsController(_dbContext, _userManager);

            controller.ControllerContext = context;

            var result = controller.Index().Result as ViewResult;

            if (result.Model is List <ToDoList> indexList)
            {
                //Gets count of ToDoLists belonging to current user in database
                //Gets count of ToDoLists of Index View
                //Compares counts
                Assert.AreEqual(_dbContext.ToDoList.Include(list => list.Owner).Where(list => list.Owner == currUser).Count(), indexList.Count());
            }
            else
            {
                Assert.Fail();
            }
        }
Exemplo n.º 2
0
 public ToDoListsControllerTests()
 {
     this.optionsBuilder = new DbContextOptionsBuilder <ApplicationDbContext>()
                           .UseInMemoryDatabase("toDoListsDatabase");
     this.db = new ApplicationDbContext(this.optionsBuilder.Options);
     this.toDoListsService = new ToDoListsService(this.db);
     this.userManager      = new FakeUserManager();
     this.controller       = new ToDoListsController(this.toDoListsService, this.userManager);
 }