Exemplo n.º 1
0
        public void GetTodo()
        {
            var toDoId = 1;

            var result = _controller.GetTodo(toDoId) as ObjectResult;

            Assert.True(result != null, "result is null");
            Assert.True(result.StatusCode == 200, "Status code is not OK");
            Assert.True((result.Value as Todo).Text == "Text1", "Seleted toDo's text is not correct");
        }
Exemplo n.º 2
0
        public async Task GetTodo_TodoDoesNotExist_ReturnsANotFoundResult()
        {
            // Arrange
            var todoId      = 1;
            var mockService = new Mock <ITodosService>();

            mockService.Setup(ts => ts.FindByIdAsync(todoId)).ReturnsAsync((TodoDTO)null);

            var controller = new TodosController(mockService.Object);

            // Action
            var result = await controller.GetTodo(todoId);

            // Assert
            Assert.NotNull(result);
            Assert.IsType <NotFoundResult>(result.Result);
        }
Exemplo n.º 3
0
        public async Task GetTodo_TodoExists_ReturnsOkResult()
        {
            // Arrange
            var todoId       = 1;
            var expectedTodo = new TodoDTO()
            {
                Id = todoId, Name = "Todo 1", IsComplete = true
            };
            var mockService = new Mock <ITodosService>();

            mockService.Setup(ts => ts.FindByIdAsync(todoId)).ReturnsAsync(expectedTodo);

            var controller = new TodosController(mockService.Object);

            // Action
            var result = await controller.GetTodo(todoId);

            // Assert
            Assert.NotNull(result);
            Assert.NotNull(result.Value);
            Assert.Equal(expectedTodo.Id, result.Value.Id);
            Assert.Equal(expectedTodo.Name, result.Value.Name);
            Assert.Equal(expectedTodo.IsComplete, result.Value.IsComplete);
        }