public void BoardRepositoryCanCreateBoard() { /* Begin Arrange */ var data = my_list.AsQueryable(); mock_boards.As<IQueryable<Board>>().Setup(m => m.Provider).Returns(data.Provider); mock_boards.As<IQueryable<Board>>().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator()); mock_boards.As<IQueryable<Board>>().Setup(m => m.ElementType).Returns(data.ElementType); mock_boards.As<IQueryable<Board>>().Setup(m => m.Expression).Returns(data.Expression); // This allows BoardRepository to call Boards.Add and have it update the my_list instance and Enumerator // Connect DbSet.Add to List.Add so they work together mock_boards.Setup(m => m.Add(It.IsAny<Board>())).Callback((Board b) => my_list.Add(b)); mock_context.Setup(m => m.Boards).Returns(mock_boards.Object); BoardRepository board_repo = new BoardRepository(mock_context.Object); string title = "My Awesome Board"; /* End Arrange */ /* Begin Act */ Board added_board = board_repo.CreateBoard(title, owner); /* End Act */ /* Begin Assert */ Assert.IsNotNull(added_board); mock_boards.Verify(m => m.Add(It.IsAny<Board>())); mock_context.Verify(x => x.SaveChanges(), Times.Once()); Assert.AreEqual(1, board_repo.GetBoardCount()); /* End Assert */ }
public ActionResult Index() { //UserManager<ApplicationUser> manager = new UserManager<ApplicationUser>(); //UserManager<ApplicationUser> manager = HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>(); string user_id = User.Identity.GetUserId(); ApplicationUser me = repository.Users.FirstOrDefault(u => u.Id == user_id); List <Board> boards = repository.GetBoards(me); Board my_board = null; if (boards.Count() == 0) { my_board = repository.CreateBoard("My Board", me); } else { my_board = boards.First(); } ViewBag.Title = my_board.Title; ViewBag.CurrentBoardId = my_board.BoardId; //bool successful = repository.AddList(my_board.BoardId, new BrelloList { Title = "ToDo" }); List <BrelloList> board_lists = repository.GetAllLists(my_board.BoardId); return(View(board_lists)); }
public void BoardRepositoryCanCreateBoard() { /* Begin Arrange */ var data = my_list.AsQueryable(); mock_boards.As <IQueryable <Board> >().Setup(m => m.Provider).Returns(data.Provider); mock_boards.As <IQueryable <Board> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator()); mock_boards.As <IQueryable <Board> >().Setup(m => m.ElementType).Returns(data.ElementType); mock_boards.As <IQueryable <Board> >().Setup(m => m.Expression).Returns(data.Expression); // This allows BoardRepository to call Boards.Add and have it update the my_list instance and Enumerator // Connect DbSet.Add to List.Add so they work together mock_boards.Setup(m => m.Add(It.IsAny <Board>())).Callback((Board b) => my_list.Add(b)); mock_context.Setup(m => m.Boards).Returns(mock_boards.Object); BoardRepository board_repo = new BoardRepository(mock_context.Object); string title = "My Awesome Board"; /* End Arrange */ /* Begin Act */ Board added_board = board_repo.CreateBoard(title, owner); /* End Act */ /* Begin Assert */ Assert.IsNotNull(added_board); mock_boards.Verify(m => m.Add(It.IsAny <Board>())); mock_context.Verify(x => x.SaveChanges(), Times.Once()); Assert.AreEqual(1, board_repo.GetBoardCount()); /* End Assert */ }