public async Task Handle_WhenRequestIsValid_ShouldReturnCommandResultSuccess() { //Arrange var successfulValidationResult = new ValidationResult(); _validator.ValidateAsync(Arg.Any <MarkAsDoneTodoListItemCommand>()).Returns(successfulValidationResult); var todoListItem = TodoListItemTestData.CreateTodoListItemTestData(); var todoListItemId = todoListItem.TodoListItemId; _todoListItemsRepository.AnyAsync(Arg.Any <Expression <Func <TodoListItem, bool> > >()).Returns(true); _todoListItemsRepository.GetTodoListItemsByIdAsync(Arg.Any <Guid>()).Returns(todoListItem); request = new MarkAsDoneTodoListItemCommand { TodoListItemId = todoListItemId }; subject = new MarkAsDoneTodoListItemCommandHandler(_todoListItemsRepository, _validator); //Act var result = await subject.Handle(request, default); //Assert result.Errors.ShouldBeEmpty(); result.IsSuccessful.ShouldBeTrue(); result.Result.ShouldBeOfType <MediatR.Unit>(); result.Message.ShouldBe("The to-do item was done successfully"); }
public UpdateTodoListItemCommandValidator(ITodoListItemsRepository todoListItemsRepository) { RuleFor(model => model.TodoListItemId) .MustAsync((todoListItemId, cancellation) => todoListItemsRepository.AnyAsync(x => x.TodoListItemId == todoListItemId, cancellation)) .WithMessage("The to-do item associated with this transaction was not found."); RuleFor(model => model.Name) .NotEmpty() .WithMessage("Name must not be empty"); RuleFor(model => model.Description) .MaximumLength(500) .WithMessage(model => $"Description must be less than 500 characters long. Current length: {model.Description.Length}") .When(model => !string.IsNullOrWhiteSpace(model.Description)); }
public DeleteTodoListItemCommandValidator(ITodoListItemsRepository todoListItemsRepository) { RuleFor(model => model.TodoListItemId) .MustAsync((todoListItemId, cancellation) => todoListItemsRepository.AnyAsync(x => x.TodoListItemId == todoListItemId, cancellation)) .WithMessage("The to-do item associated with this transaction was not found."); }