コード例 #1
0
        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)));
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        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));
        }