Exemplo n.º 1
0
        public void Get_WhenCalled_ReturnsAllItems()
        {
            // Act
            var okResult = _controller.GetTodoItems().Result as OkObjectResult;

            // Assert
            var items = Assert.IsAssignableFrom <IEnumerable <TodoItem> >(okResult.Value);

            Assert.NotEmpty(items);
        }
        public async Task GetTodoItems_ReturnsInvalidException_WithEmptyList()
        {
            var items          = new List <TodoItem>();
            var mockRepository = new Mock <ITodoItemRepository>();

            mockRepository.Setup(repo => repo.GetItemsListAsync())
            .ReturnsAsync(items);
            var controller = new TodoController(mockRepository.Object);

            await Assert.ThrowsAsync <InvalidOperationException>(async() =>
                                                                 await controller.GetTodoItems());
        }
Exemplo n.º 3
0
        public async Task GetTodoItems()
        {
            // Arrange
            var mockRepo = new Mock <ITodoRepository>();

            mockRepo.Setup(repo => repo.SelectAllAsync()).ReturnsAsync(GetTestTodoList);
            var controller = new TodoController(mockRepo.Object);

            // Act
            var result = await controller.GetTodoItems();

            // Assert
            Assert.Equal(2, result.Value.Count());
            Assert.Equal("Item1", result.Value.First().Name);
            Assert.Equal("Item2", result.Value.Last().Name);
        }
        public async Task GetTodoItems_ReturnsResultValue_WithListOfTodoItems()
        {
            var mockRepository = new Mock <ITodoItemRepository>();

            mockRepository.Setup(repo => repo.GetItemsListAsync())
            .ReturnsAsync(GetTestItems());
            var controller = new TodoController(mockRepository.Object);

            var result = await controller.GetTodoItems();

            var items = Assert.IsType <List <TodoItem> >(result.Value);

            Assert.Equal(2, result.Value.Count);
            var firstItem = items.Find(item => item.Id == 1);

            Assert.Equal("Test One", firstItem.Name);
        }
Exemplo n.º 5
0
        public async Task GetTodoItems_WithEmptyList_ShouldReturnEmptyList()
        {
            // Arrange
            var mockService = new Mock <ITodoItemService>();

            mockService.Setup(service => service.GetTodoItemsAsync())
            .ReturnsAsync(new List <TodoItemDTO>());

            var controller = new TodoController(mockService.Object);

            // Act
            var result = await controller.GetTodoItems();

            // Assert
            var viewResult = Assert.IsType <ActionResult <IEnumerable <TodoItemDTO> > >(result);
            var okResult   = Assert.IsType <OkObjectResult>(viewResult.Result);

            Assert.Equal((int)HttpStatusCode.OK, okResult.StatusCode);
            var todoItemsDTO = Assert.IsAssignableFrom <IEnumerable <TodoItemDTO> >(okResult.Value);

            Assert.True(0 == todoItemsDTO.Count());
        }
Exemplo n.º 6
0
        public async Task GetTodoItems_WithExistingElements_ShouldReturnOkWithTodoItems()
        {
            // Arrange
            var expectedTodoItemDTOs = new List <TodoItemDTO>()
            {
                CreateFakeTodoItemDTO(1), CreateFakeTodoItemDTO(2)
            };
            var mockService = new Mock <ITodoItemService>();

            mockService.Setup(service => service.GetTodoItemsAsync())
            .ReturnsAsync((expectedTodoItemDTOs));

            var controller = new TodoController(mockService.Object);

            // Act
            var result = await controller.GetTodoItems();

            // Assert
            var viewResult = Assert.IsType <ActionResult <IEnumerable <TodoItemDTO> > >(result);
            var okResult   = Assert.IsType <OkObjectResult>(viewResult.Result);

            Assert.Equal((int)HttpStatusCode.OK, okResult.StatusCode);
            var todoItemsDTO = Assert.IsAssignableFrom <IEnumerable <TodoItemDTO> >(okResult.Value);

            Assert.Equal(expectedTodoItemDTOs.Count, todoItemsDTO.Count());

            var todoItemsDTOList = todoItemsDTO.ToList();

            for (int index = 0; index < expectedTodoItemDTOs.Count; index++)
            {
                Assert.Equal(expectedTodoItemDTOs[index].Name, todoItemsDTOList[index].Name);
                Assert.Equal(expectedTodoItemDTOs[index].Description, todoItemsDTOList[index].Description);
                Assert.Equal(expectedTodoItemDTOs[index].DueAt, todoItemsDTOList[index].DueAt);
                Assert.Equal(expectedTodoItemDTOs[index].IsComplete, todoItemsDTOList[index].IsComplete);
                Assert.Equal(expectedTodoItemDTOs[index].Order, todoItemsDTOList[index].Order);
            }
        }
Exemplo n.º 7
0
        public async Task OkGetTodoItemsTest()
        {
            var result = await controller.GetTodoItems();

            Assert.IsType <ActionResult <IEnumerable <TodoItem> > >(result);
        }
Exemplo n.º 8
0
        public async Task OkGetTodoItemsTest()
        {
            var result = await controller.GetTodoItems();

            Assert.Equal(itemlist, result);
        }