Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ public class CommandValidation : AbstractValidator<Command>
{
public CommandValidation()
{
RuleFor(x => x.Discount).GreaterThanOrEqualTo(0);
RuleFor(x => x.Discount)
.GreaterThanOrEqualTo(0)
.MustAsync(async (_, __) => await Task.Delay(0).ContinueWith(x => true));
}
}

Expand All @@ -65,4 +67,4 @@ public async Task<Unit> Handle(Command request, CancellationToken cancellationTo
return await Unit.Task;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ public ValidationBehavior(IEnumerable<IValidator<TRequest>> validators)
_validators = validators;
}

public Task<TResponse> Handle(TRequest request
public async Task<TResponse> Handle(TRequest request
, CancellationToken cancellationToken
, RequestHandlerDelegate<TResponse> next
)
{
var failures = _validators
.Select(v => v.Validate(request))
var failures =
(await Task.WhenAll(_validators.Select(async v => await v.ValidateAsync(request, cancellationToken))))
.Where(result => result != null)
.SelectMany(result => result.Errors)
.Where(f => f != null)
.ToList();
Expand All @@ -32,7 +33,7 @@ public Task<TResponse> Handle(TRequest request
throw new ValidationException(failures);
}

return next();
return await next();
}
}
}