public PostTodoItem ( TodoItemDto todoItemDto ) : HttpResponseMessage, | ||
todoItemDto | TodoItemDto | |
return | HttpResponseMessage, |
public async Task PostTodoItem_WithNewItem_ShouldReturnCreatedAtAction() { // Arrange var todoItemDTO = CreateFakeTodoItemDTO(); var expectedTodoItem = new TodoItem { Id = 1 }; var mockService = new Mock <ITodoItemService>(); mockService.Setup(service => service.PostTodoItemAsync(todoItemDTO)) .ReturnsAsync(expectedTodoItem); var controller = new TodoController(mockService.Object); // Act var result = await controller.PostTodoItem(todoItemDTO); // Assert var viewResult = Assert.IsType <ActionResult <TodoItem> >(result); var createdResult = Assert.IsType <CreatedAtActionResult>(viewResult.Result); Assert.Equal((int)HttpStatusCode.Created, createdResult.StatusCode); var todoItem = Assert.IsAssignableFrom <TodoItem>(createdResult.Value); Assert.Equal(expectedTodoItem.Id, todoItem.Id); }
public async Task PostTodoItem_ReturnsCreatedAtAction() { string testName = "test name"; var mockRepository = new Mock <ITodoItemRepository>(); mockRepository.Setup(repo => repo.PostItemAsync(It.IsAny <TodoItem>())) .Returns(Task.CompletedTask) .Verifiable(); var controller = new TodoController(mockRepository.Object); var newTodoItem = new TodoItem { Name = testName, IsComplete = false }; var result = await controller.PostTodoItem(newTodoItem); var actionResult = Assert.IsType <ActionResult <TodoItem> >(result); var createdAtActionResult = Assert.IsType <CreatedAtActionResult>(actionResult.Result); var returnValue = Assert.IsType <TodoItem>(createdAtActionResult.Value); mockRepository.Verify(); Assert.Equal(testName, returnValue.Name); Assert.False(returnValue.IsComplete); }
public async Task OkPostTodoItemTest() { var item = new TodoItem { Id = Guid.NewGuid().ToString("N"), Name = "new item", IsComplete = false }; var result = await controller.PostTodoItem(item); Assert.IsType <ActionResult <TodoItem> >(result); Assert.Equal(4, itemlist.Count); }
public async Task OkPostTodoItemTest() { var item = new TodoItem { Name = "new item", IsComplete = false }; var result = await controller.PostTodoItem(item); await PrintData(); Assert.IsType <ActionResult <TodoItem> >(result); Assert.Equal(4, context.TodoItems.Count()); }
public async Task DeleteTodoItme() { // Arrange var mockRepo = new Mock <ITodoRepository>(); var todo = new TodoItem { Name = "item1" }; mockRepo.Setup(repo => repo.DeleteAsync(todo)).Returns(Task.CompletedTask); var controller = new TodoController(mockRepo.Object); // Act var result = await controller.PostTodoItem(todo); // Assert Assert.Null(result.Value); }