Skip to content

Commit

Permalink
fix: Check Content for null, use DependentRules, disallow empty local…
Browse files Browse the repository at this point in the history
…ization values (#413)

#375
  • Loading branch information
oskogstad authored Feb 12, 2024
1 parent 669c7a5 commit 894644a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public LocalizationDtoValidator(int maximumLength = 255)
RuleFor(x => x).NotNull();

RuleFor(x => x.Value)
.NotEmpty()
.NotNull()
.MaximumLength(maximumLength);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,19 @@ public CreateDialogCommandValidator(
.IsInEnum();

RuleFor(x => x.Content)
.UniqueBy(x => x.Type)
.Must(content => DialogContentType.RequiredTypes
.All(requiredContent => content
.Select(x => x.Type)
.Contains(requiredContent)))
.WithMessage($"Dialog must contain the following content: [{string.Join(", ", DialogContentType.RequiredTypes)}].")
.ForEach(x => x.SetValidator(contentValidator));
.NotNull()
.DependentRules(() =>
{
RuleFor(x => x.Content)
.UniqueBy(x => x.Type)
.Must(content => DialogContentType.RequiredTypes
.All(requiredContent => content
.Select(x => x.Type)
.Contains(requiredContent)))
.WithMessage("Dialog must contain the following content: " +
$"[{string.Join(", ", DialogContentType.RequiredTypes)}].")
.ForEach(x => x.SetValidator(contentValidator));
});

RuleForEach(x => x.SearchTags)
.SetValidator(searchTagValidator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,19 @@ public UpdateDialogDtoValidator(
.IsInEnum();

RuleFor(x => x.Content)
.UniqueBy(x => x.Type)
.Must(content => DialogContentType.RequiredTypes
.All(requiredContent => content
.Select(x => x.Type)
.Contains(requiredContent)))
.WithMessage($"Dialog must contain the following content: [{string.Join(", ", DialogContentType.RequiredTypes)}].")
.ForEach(x => x.SetValidator(contentValidator));
.NotNull()
.DependentRules(() =>
{
RuleFor(x => x.Content)
.UniqueBy(x => x.Type)
.Must(content => DialogContentType.RequiredTypes
.All(requiredContent => content
.Select(x => x.Type)
.Contains(requiredContent)))
.WithMessage("Dialog must contain the following content: " +
$"[{string.Join(", ", DialogContentType.RequiredTypes)}].")
.ForEach(x => x.SetValidator(contentValidator));
});

RuleFor(x => x.SearchTags)
.UniqueBy(x => x.Value, StringComparer.InvariantCultureIgnoreCase)
Expand Down

0 comments on commit 894644a

Please sign in to comment.