public void GivenALoggedInUser_WhenThenExecutueTheTodoIndexMethod_ThenAViewResultIsReturned() { Mock<ITodoRepository> repository = new Mock<ITodoRepository>(); repository.Setup(r => r.GetTodos()).Returns(new List<Todo>()); TodoController controller = new TodoController(repository.Object); var result = controller.Index(); Assert.That(result, Is.TypeOf(typeof(ViewResult))); }
public void GivenATodoController_WhenIAskForAListOfTodos_ThenIGetTheFullList() { _repository.Setup(r => r.GetTodos()).Returns(new List<Todo> { new Todo() }); TodoController controller = new TodoController(_repository.Object); var result = controller.Index() as ViewResult; var model = result.Model as List<ListTodoVM>; Assert.That(model.Count, Is.EqualTo(1)); }
public void GivenThreeTodosInTheDatabase_WhenIndexIsCalled_ThenThreeViewModelsArePassedToTheView() { Mock<ITodoRepository> repository = new Mock<ITodoRepository>(); repository.Setup(r => r.GetTodos()).Returns(new List<Todo>{new Todo(), new Todo(), new Todo()}); TodoController controller = new TodoController(repository.Object); var result = controller.Index() as ViewResult; var model = result.Model as List<ListTodoVM>; Assert.That(model.Count, Is.EqualTo(3)); }