This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CreateCustomerCommandValidatorUnitTests | |
{ | |
private CreateCustomerCommandValidator validator; | |
public CreateCustomerCommandValidatorUnitTests() | |
{ | |
validator = new CreateCustomerCommandValidator(); | |
} | |
[Fact] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (exception is ValidationException validationException) | |
{ | |
string[] validationErrorMessages = validationException.Errors.Select(x => x.ErrorMessage).ToArray(); | |
ValidationProblemDetails problemDetails = new ValidationProblemDetails | |
{ | |
Instance = req.Path, | |
Status = StatusCodes.Status400BadRequest, | |
Title = "One or more validation errors occurred.", | |
Detail = $"{string.Join('-', validationErrorMessages)}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ValidatorBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse> | |
where TRequest : IRequest<TResponse> | |
{ | |
private readonly IEnumerable<IValidator<TRequest>> _validators; | |
public ValidatorBehavior(IEnumerable<IValidator<TRequest>> validators) | |
{ | |
_validators = validators ?? throw new ArgumentNullException(nameof(validators)); | |
} |