public IActionResult Put(string todoItemId, [FromBody] UpdateTodoitem request) { if (request == null || request.Title == string.Empty) { return(BadRequest("All parameters are required.")); } var item = _todoItemsQueryHandler.Handle(new GetTodoItemQuery() { Id = todoItemId }); if (item == null) { return(NotFound(new { Message = $"Item with id {todoItemId} not found." })); } _todoItemsCommandHandler.Handle(new UpdateTodoItemCommand() { Id = todoItemId, Title = request.Title, Completed = request.Completed }); return(NoContent()); }
public async Task Put_ShouldUpdateTodoItem() { // Arrange var postRequest = _helper.GetNewTodoItemDto(); var postResponse = await _client.PostAsync(Constants.TodoApiUrl, RequestContentHelper.GetStringContent(postRequest)); var json = await postResponse.Content.ReadAsStringAsync(); var data = JsonConvert.DeserializeObject <TodoItemDto>(json); var updateRequest = new UpdateTodoitem() { Title = "Task Updated", Completed = true }; var body = RequestContentHelper.GetStringContent(updateRequest); // Act var updateResponse = await _client.PutAsync($"{Constants.TodoApiUrl}/{data.Id}", RequestContentHelper.GetStringContent(body)); // Assert updateResponse.EnsureSuccessStatusCode(); }