public void Index_NoTaskInRepository_ShouldReturnEmptyModel() { // Arrange _taskRepository .Stub(r => r.Tasks) .Return(new List <Task>()); // Act var viewResult = _controller.Index(); // Assert Assert.That(viewResult.Model, Is.Empty); }
public void WhenConfirmDataCalledAfterIndexShouldReturnTaskListViewModelWithDataNotConfirmed() { var context = new Mock <HttpContext>(); var schoolService = new Mock <ISchoolService>(); var config = new Mock <IConfiguration>(); var httpRequest = new Mock <HttpRequest>(); httpRequest.Setup(x => x.RouteValues).Returns(new RouteValueDictionary { { "phase", "ks5" } }); schoolService.Setup(x => x.UpdateConfirmation(It.IsAny <TaskListViewModel>(), It.IsAny <string>(), It.IsAny <string>())); context.Setup(x => x.Session).Returns(Session); context.Setup(x => x.Request).Returns(httpRequest.Object); var controller = new TaskListController(schoolService.Object, config.Object, GetUserInfo()) { ControllerContext = GetControllerContext("ks5", context) }; controller.Index(); var result = controller.ConfrimData() as RedirectToActionResult; var viewModel = Session.Get <TaskListViewModel>($"task-list-{UserId}KS5"); Assert.True(viewModel != null); Assert.True(viewModel.DataConfirmed == false); }
public void Index_with_1_Task_in_List() { #region Arrange List <TaskDetailsModel> mockTaskList = new List <TaskDetailsModel>(); TaskDetailsModel mockTaskDetails = new TaskDetailsModel { ID = 1, TaskCompleted = false, TaskDescription = HttpUtility.HtmlEncode("Mocked Task") }; TaskListModel mockTaskListModel = new TaskListModel(); mockTaskList.Add(mockTaskDetails); this.mockContext.SetupGet(x => x.Request).Returns(this.mockRequest.Object); this.mockContext.SetupGet(x => x.Response).Returns(this.mockResponse.Object); mockContext.Setup(x => x.Session["InMemoryTaskList"]).Returns(mockTaskListModel); var mockControllerContext = new RequestContext(this.mockContext.Object, new RouteData()); TaskListController controller = new TaskListController(); controller.tasklist = mockTasklist.Object; controller.ControllerContext = new ControllerContext(mockControllerContext, controller); this.mockTasklist.Setup(c => c.GetAllTasks()).Returns(mockTaskList); #endregion #region Act var result = (ActionResult)controller.Index(); var viewModel = controller.ViewData.Model as TaskListModel; #endregion #region Assert this.mockTasklist.Verify(c => c.GetAllTasks(), Times.Once()); Assert.IsNotNull(controller.HttpContext.Session["InMemoryTaskList"]); Assert.AreEqual(1, mockTaskList.Count); #endregion }
public void WhenIndexCalledShouldReturnTaskListViewModelWithDataUnconfirmed() { var context = new Mock <HttpContext>(); var schoolService = new Mock <ISchoolService>(); var config = new Mock <IConfiguration>(); schoolService.Setup(x => x.GetConfirmationRecord(It.IsAny <string>(), It.IsAny <string>())) .Returns(new TaskListViewModel("ks5")); context.Setup(x => x.Session).Returns(Session); var controller = new TaskListController(schoolService.Object, config.Object, GetUserInfo()) { ControllerContext = GetControllerContext("ks5", context) }; var result = controller.Index() as ViewResult; var model = result.Model as TaskListViewModel; Assert.True(model != null); Assert.True(model.DataConfirmed == false); }