public async Task DeleteAsync(DeleteTodo command) { var todo = await _todoRepository.GetAsync(command.TodoId); if (todo is null) { throw new TodoNotFoundException(command.TodoId); } await _todoRepository.DeleteAsync(todo); }
private async Task OnDeleteTodo(DeleteTodo todo, CancellationToken ct) { var existingTodo = await _todoRepo.GetAsync(todo.TodoId, ct); if (existingTodo == default) { return; } await _todoRepo.RemoveAsync(existingTodo.Id, ct); await _publisher.PublishAsync(new TodoDeleted { Todo = existingTodo }, ct); }
public async Task Handle_Async_Published_TodoItem_Deleted_If_TodoItem_With_Given_Id_Exists() { DeleteTodo command = new DeleteTodo(_id); _todoItemRepository .ExistsAsync(_id) .Returns(true); await Act(command); await _busPublisher .Received() .PublishAsync(Arg.Is <TodoItemDeleted>(e => e.Id == command.Id), _context); }
public async Task Handle_Async_Published_Delete_TodoItem_Rejected_If_TodoItem_With_Given_Id_Does_Not_Exist() { DeleteTodo command = new DeleteTodo(_id); _todoItemRepository .ExistsAsync(_id) .Returns(false); await Act(command); await _busPublisher .Received() .PublishAsync(Arg.Is <DeleteTodoItemRejected>(e => e.Id == command.Id && e.Code == "todo_item_does_not_exist" && e.Reason == $"TodoItem with id: '{command.Id}' was not found."), _context); }
public async Task <IActionResult> Handle(DeleteTodo request, CancellationToken cancellationToken) { var todoItem = await _context.TodoItems.FindAsync(request.Id); if (todoItem == null) { return(new NotFoundResult()); } _context.TodoItems.Remove(todoItem); await _context.SaveChangesAsync(cancellationToken); return(new NoContentResult()); }
public IActionResult Delete(DeleteTodo deleteTodo) { Todo todo = new Todo { ID = deleteTodo.Id }; var result = _todoService.Delete(todo); if (result.Success) { return(Ok(result)); } return(BadRequest(result)); }
public async Task delete_todo_should_succeed_given_valid_id() { var todo = new Todo(Guid.NewGuid(), "Some Title", "Some Description", Priority.HIGH, State.NEW); _todoRepository.GetAsync(todo.Id).Returns(todo); var command = new DeleteTodo(todo.Id); await _todosService.DeleteAsync(command); await _todoRepository.Received().DeleteAsync(Arg.Is <Todo>(x => x.Id == todo.Id && x.Title == todo.Title && x.Description == todo.Description && x.Priority == todo.Priority && x.State == todo.State && x.CreatedAt == todo.CreatedAt)); }
private async Task Act(DeleteTodo command) => await _commandHandler.HandleAsync(command, _context);
public async Task<ActionResult> Delete(DeleteTodo command) { await _todoService.DeleteAsync(command); return Ok(); }
static TodoAppState DeleteTodo(TodoAppState state, DeleteTodo act) => new TodoAppState { Todos = state.Todos.Where(todo => todo.Id != act.Id), Visibility = state.Visibility };
public Task Delete(DeleteTodo request) { Todos.RemoveAll(x => x.Id == request.Id); return(ServerEvents.NotifyChannelAsync("todos", "todos.delete", request.Id)); }
public void Delete(DeleteTodo request) { Repository.Delete(request); }