public async Task GetTodoItem_WithValidId_ShouldReturnOkViewWithTodoItem() { // Arrange var expectedTodoItemDTO = CreateFakeTodoItemDTO(); var mockService = new Mock <ITodoItemService>(); mockService.Setup(service => service.GetTodoItemAsync(1)) .ReturnsAsync(expectedTodoItemDTO); var controller = new TodoController(mockService.Object); // Act var result = await controller.GetTodoItem(1); // Assert var viewResult = Assert.IsType <ActionResult <TodoItemDTO> >(result); var okResult = Assert.IsType <OkObjectResult>(viewResult.Result); Assert.Equal((int)HttpStatusCode.OK, okResult.StatusCode); var todoItemDTO = Assert.IsAssignableFrom <TodoItemDTO>(okResult.Value); Assert.Equal(expectedTodoItemDTO.Name, todoItemDTO.Name); Assert.Equal(expectedTodoItemDTO.Description, todoItemDTO.Description); Assert.Equal(expectedTodoItemDTO.DueAt, todoItemDTO.DueAt); Assert.Equal(expectedTodoItemDTO.IsComplete, todoItemDTO.IsComplete); Assert.Equal(expectedTodoItemDTO.Order, todoItemDTO.Order); }
public async Task OkGetTodoItemTest() { var targetId = itemlist[0].Id; var result = await controller.GetTodoItem(targetId); Assert.IsType <ActionResult <TodoItem> >(result); Assert.Equal(targetId, result.Value.Id); }
public async Task OkGetTodoItemTest() { // itemlist[0]のIdを指定して値を取得 var targetId = itemlist[0].Id; var result = await controller.GetTodoItem(targetId); // resultがitemlist[0]と等しいこと Assert.Equal(itemlist[0], result.Value); }
public async Task GetTodoItem_ReturnsNotFound_WhenTodoItemIsNull() { long testId = 1; var mockRepository = new Mock <ITodoItemRepository>(); mockRepository.Setup(repo => repo.GetItemByIdAsync(testId)) .ReturnsAsync((TodoItem)null); var controller = new TodoController(mockRepository.Object); var result = await controller.GetTodoItem(testId); Assert.IsType <NotFoundResult>(result.Result); }
public async Task GetTodoItem_ReturnsResultValue_WithListOfTodoItems() { long testId = 1; var mockRepository = new Mock <ITodoItemRepository>(); mockRepository.Setup(repo => repo.GetItemByIdAsync(testId)) .ReturnsAsync(GetTestItems().FirstOrDefault(td => td.Id == testId)); var controller = new TodoController(mockRepository.Object); var result = await controller.GetTodoItem(testId); Assert.IsType <TodoItem>(result.Value); Assert.Equal(testId, result.Value.Id); Assert.Equal("Test One", result.Value.Name); Assert.True(result.Value.IsComplete); }
public async Task GetTodo_ReturnHttpNotFound_ForInvalidTodo() { // Arrange int todoId = 99; var mockRepo = new Mock <ITodoItemRepository>(); mockRepo.Setup(repo => repo.GetAsync(todoId)) .ReturnsAsync((TodoItem)null); var controller = new TodoController(mockRepo.Object); // Act var result = await controller.GetTodoItem(todoId); // Assert var notFoundObjectResult = Assert.IsType <NotFoundObjectResult>(result); Assert.Equal(todoId, notFoundObjectResult.Value); }
public async Task GetTodoItem_WithInvalidIdOrEmptyList_ShouldReturnNotFoundView() { // Arrange var mockService = new Mock <ITodoItemService>(); mockService.Setup(service => service.GetTodoItemAsync(1)) .ReturnsAsync((TodoItemDTO)null); var controller = new TodoController(mockService.Object); // Act var result = await controller.GetTodoItem(1); // Assert var viewResult = Assert.IsType <ActionResult <TodoItemDTO> >(result); var notFoundResult = Assert.IsType <NotFoundResult>(viewResult.Result); Assert.Equal((int)HttpStatusCode.NotFound, notFoundResult.StatusCode); }