public void ShouldRequireValidTodoItemId()
        {
            var command = new DeleteTodoItemCommand {
                Id = 99
            };

            FluentActions.Invoking(() =>
                                   SendAsync(command)).Should().Throw <NotFoundException>();
        }
        public async Task AssertValidAsync(DeleteTodoItemCommand command)
        {
            var itemExists = await _todoItemQueries.TodoItemExists(command.Id);

            if (!itemExists)
            {
                throw new Exception($"Todo Item with Id {command.Id} does not exist. Cannot be deleted.");
            }
        }
예제 #3
0
        public async Task <Unit> Handle(DeleteTodoItemCommand request, CancellationToken cancellationToken)
        {
            var todoItem = await todoItemContext.TodoItem.FindAsync(request.Id);

            todoItemContext.TodoItem.Remove(todoItem);

            await SaveAndPublish(todoItem, cancellationToken);

            return(Unit.Value);
        }
        public void Handle_GivenInvalidId_ThrowsException()
        {
            var command = new DeleteTodoItemCommand
            {
                Id = 99
            };

            var handler = new DeleteTodoItemCommand.DeleteTodoItemCommandHandler(Context);

            Should.ThrowAsync <NotFoundException>(() =>
                                                  handler.Handle(command, CancellationToken.None));
        }
예제 #5
0
        public void Handle(DeleteTodoItemCommand message)
        {
            var list = FindList(message.ListId);

            if (list == null)
            {
                return;
            }

            list.DeleteItem(message.ItemId);
            _repository.Save(list);
        }
        public async Task Handle_GivenValidId_ShouldRemovePersistedTodoItem()
        {
            var command = new DeleteTodoItemCommand
            {
                Id = 1
            };

            var handler = new DeleteTodoItemCommand.DeleteTodoItemCommandHandler(Context);

            await handler.Handle(command, CancellationToken.None);

            var entity = Context.TodoItems.Find(command.Id);

            entity.ShouldBeNull();
        }
        public void Handle(DeleteTodoItemCommand command)
        {
            var todoItem = _todoItemService.Read(x => x.Id == command.Id).FirstOrDefault();

            if (todoItem == null)
            {
                throw new NotFoundException("Objeto não encontrado.", null);
            }

            if (command.Invalid)
            {
                return;
            }

            _todoItemService.Delete((long)command.Id);
        }
예제 #8
0
        public bool Handle(DeleteTodoItemCommand command)
        {
            if (command == null)
            {
                throw new ArgumentNullException("UpdateTodoItemCommand can not be null");
            }

            try
            {
                _todoRepository.Delete(command.Id);
            }
            catch (Exception e)
            {
                return(false);
            }

            return(true);
        }
        public async Task <ActionResult> Delete(DeleteTodoItemCommand command)
        {
            await Mediator.Send(command);

            return(NoContent());
        }