public async Task ReplaceTodoItem_Should_ReturnUnprocessableEntity() { // Arrange var model = new Models.TodoItemToUpdate { Description = "Test updated" }; _controller.ModelState.AddModelError(nameof(Models.TodoItemToUpdate.Title), "Title is required"); // Act var result = await _controller.ReplaceTodoItem(Guid.NewGuid(), model); // Assert Assert.IsType <UnprocessableEntityObjectResult>(result); }
public async Task ReplaceTodoItem_Should_ReturnNotFound() { // Arrange var guid = Guid.NewGuid(); var model = new Models.TodoItemToUpdate { Title = "Test updated" }; _serviceMock.Setup(x => x.GetById(guid)).ReturnsAsync((TodoItem)null); // Act var result = await _controller.ReplaceTodoItem(guid, model); // Assert Assert.IsType <NotFoundResult>(result); }
public async Task ReplaceTodoItem_Should_ThrowException_WhenSaveFails() { // Arrange var guid = Guid.NewGuid(); var entity = new TodoItem { Id = guid, Title = "Test" }; var model = new Models.TodoItemToUpdate { Title = "Test updated" }; _serviceMock.Setup(x => x.GetById(guid)).ReturnsAsync(entity); _serviceMock.Setup(x => x.Update(It.IsAny <TodoItem>())).ReturnsAsync(false); // Act && Assert await Assert.ThrowsAsync <ApiException>(() => _controller.ReplaceTodoItem(guid, model)); }
public async Task ReplaceTodoItem_Should_ReturnNoContent() { // Arrange var guid = Guid.NewGuid(); var entity = new TodoItem { Id = guid, Title = "Test" }; var model = new Models.TodoItemToUpdate { Title = "Test updated" }; _serviceMock.Setup(x => x.GetById(guid)).ReturnsAsync(entity); _serviceMock.Setup(x => x.Update(It.IsAny <TodoItem>())).ReturnsAsync(true); // Act var result = await _controller.ReplaceTodoItem(guid, model); // Assert Assert.IsType <NoContentResult>(result); Assert.Equal(model.Title, entity.Title); }