public PutTodoItem ( int id, TodoItemDto todoItemDto ) : HttpResponseMessage, | ||
id | int | |
todoItemDto | TodoItemDto | |
리턴 | HttpResponseMessage, |
public async Task OkPutTodoItemTest() { var targetId = itemlist[0].Id; var item = new TodoItem { Id = targetId, Name = "updated item", IsComplete = true }; var result = await controller.PutTodoItem(targetId, item); Assert.IsType <NoContentResult>(result); Assert.Equal(item.Name, itemlist[0].Name); Assert.Equal(item.IsComplete, itemlist[0].IsComplete); }
public async Task OkPutTodoItemTest() { var targetId = context.TodoItems.ToList()[0].Id; var item = context.TodoItems.ToList()[0]; item.Name = "updated"; item.IsComplete = true; var result = await controller.PutTodoItem(targetId, item); _output.WriteLine("{0}", result.Value.Name); await PrintData(); Assert.IsType <ActionResult <TodoItem> >(result); Assert.Equal(item.Name, (await context.TodoItems.Where(x => x.Id == targetId).FirstOrDefaultAsync()).Name); Assert.Equal(item.IsComplete, (await context.TodoItems.Where(x => x.Id == targetId).FirstOrDefaultAsync()).IsComplete); }
public async Task PutTodoItem_ReturnsBadRequest_WhenIdIsNotItemId() { long testId = 2; long testItemId = 1; string testName = "test name"; var mockRepository = new Mock <ITodoItemRepository>(); var controller = new TodoController(mockRepository.Object); var newTodoItem = new TodoItem { Id = testItemId, Name = testName, IsComplete = true }; var result = await controller.PutTodoItem(testId, newTodoItem); Assert.IsType <BadRequestResult>(result); mockRepository.Verify(); }
public async Task PutTodoItem_WithValidId_ShouldReturnNoContent() { // Arrange var todoItemDTO = CreateFakeTodoItemDTO(1); var mockService = new Mock <ITodoItemService>(); mockService.Setup(service => service.PutTodoItemAsync(1, todoItemDTO)) .ReturnsAsync(new TodoItem()); var controller = new TodoController(mockService.Object); // Act var result = await controller.PutTodoItem(1, todoItemDTO); // Assert var viewResult = Assert.IsType <ActionResult <TodoItem> >(result); var noContentResult = Assert.IsType <NoContentResult>(viewResult.Result); Assert.Equal((int)HttpStatusCode.NoContent, noContentResult.StatusCode); }
public async Task PutTodoItem_ReturnsNoContent() { long testId = 1; string testName = "test name"; var mockRepository = new Mock <ITodoItemRepository>(); mockRepository.Setup(repo => repo.PutItemAsync(It.IsAny <TodoItem>())) .Returns(Task.CompletedTask) .Verifiable(); var controller = new TodoController(mockRepository.Object); var newTodoItem = new TodoItem { Id = testId, Name = testName, IsComplete = true }; var result = await controller.PutTodoItem(testId, newTodoItem); Assert.IsAssignableFrom <IActionResult>(result); Assert.IsType <NoContentResult>(result); mockRepository.Verify(); }