| | 1 | | using Api.Request.Parameters; |
| | 2 | | using FluentValidation; |
| | 3 | |
|
| | 4 | | namespace Api.Request.Validation; |
| | 5 | |
|
| | 6 | | public class CustomerRequestValidator : AbstractValidator<CustomerRequest> { |
| | 7 | | public const int MAX_ID_LENGTH = 55; |
| | 8 | |
|
| 12 | 9 | | public CustomerRequestValidator() { |
| 6 | 10 | | RuleFor(x => x.CustomerID) |
| 6 | 11 | | .Cascade(CascadeMode.Stop) |
| 6 | 12 | | .NotNull() |
| 6 | 13 | | .WithErrorCode("CustomerID.NotNull") |
| 6 | 14 | | .WithMessage("Customer Id cannot be null") |
| 6 | 15 | | .NotEmpty() |
| 6 | 16 | | .WithErrorCode("CustomerID.NotEmpty") |
| 6 | 17 | | .WithMessage("Customer Id cannot be empty") |
| 3 | 18 | | .Must(id => string.IsNullOrWhiteSpace(id) == false) |
| 6 | 19 | | .WithErrorCode("CustomerID.WhitespaceOnly") |
| 6 | 20 | | .WithMessage("Customer Id cannot be whitespace") |
| 6 | 21 | | .MaximumLength(MAX_ID_LENGTH) |
| 6 | 22 | | .WithErrorCode("CustomerID.TooLong") |
| 6 | 23 | | .WithMessage($"Customer Id cannot be longer can {MAX_ID_LENGTH}"); |
| 6 | 24 | | } |
| | 25 | | } |