|
1 |
| -using Digdir.Domain.Dialogporten.Application.Common.Extensions.FluentValidation; |
| 1 | +using Digdir.Domain.Dialogporten.Application.Common.Extensions.Enumerables; |
| 2 | +using Digdir.Domain.Dialogporten.Application.Common.Extensions.FluentValidation; |
2 | 3 | using Digdir.Domain.Dialogporten.Application.Features.V1.Common.Localizations;
|
3 | 4 | using Digdir.Domain.Dialogporten.Domain.Common;
|
4 | 5 | using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Actions;
|
@@ -63,33 +64,31 @@ public CreateDialogCommandValidator(
|
63 | 64 | .IsInEnum();
|
64 | 65 |
|
65 | 66 | RuleFor(x => x.Content)
|
66 |
| - .NotNull() |
67 |
| - .DependentRules(() => |
68 |
| - { |
69 |
| - RuleFor(x => x.Content) |
70 |
| - .UniqueBy(x => x.Type) |
71 |
| - .Must(content => DialogContentType.RequiredTypes |
72 |
| - .All(requiredContent => content |
73 |
| - .Select(x => x.Type) |
74 |
| - .Contains(requiredContent))) |
75 |
| - .WithMessage("Dialog must contain the following content: " + |
76 |
| - $"[{string.Join(", ", DialogContentType.RequiredTypes)}].") |
77 |
| - .ForEach(x => x.SetValidator(contentValidator)); |
78 |
| - }); |
| 67 | + .UniqueBy(x => x.Type) |
| 68 | + .Must(content => DialogContentType.RequiredTypes |
| 69 | + .All(requiredContent => content |
| 70 | + .EmptyIfNull() |
| 71 | + .Select(x => x.Type) |
| 72 | + .Contains(requiredContent))) |
| 73 | + .WithMessage("Dialog must contain the following content: " + |
| 74 | + $"[{string.Join(", ", DialogContentType.RequiredTypes)}].") |
| 75 | + .ForEach(x => x.SetValidator(contentValidator)); |
79 | 76 |
|
80 |
| - RuleForEach(x => x.SearchTags) |
81 |
| - .SetValidator(searchTagValidator); |
82 | 77 | RuleFor(x => x.SearchTags)
|
83 |
| - .UniqueBy(x => x.Value, StringComparer.InvariantCultureIgnoreCase); |
| 78 | + .UniqueBy(x => x.Value, StringComparer.InvariantCultureIgnoreCase) |
| 79 | + .ForEach(x => x.SetValidator(searchTagValidator)); |
84 | 80 |
|
85 | 81 | RuleFor(x => x.GuiActions)
|
86 | 82 | .Must(x => x
|
| 83 | + .EmptyIfNull() |
87 | 84 | .Count(x => x.Priority == DialogGuiActionPriority.Values.Primary) <= 1)
|
88 | 85 | .WithMessage("Only one primary GUI action is allowed.")
|
89 | 86 | .Must(x => x
|
| 87 | + .EmptyIfNull() |
90 | 88 | .Count(x => x.Priority == DialogGuiActionPriority.Values.Secondary) <= 1)
|
91 | 89 | .WithMessage("Only one secondary GUI action is allowed.")
|
92 | 90 | .Must(x => x
|
| 91 | + .EmptyIfNull() |
93 | 92 | .Count(x => x.Priority == DialogGuiActionPriority.Values.Tertiary) <= 5)
|
94 | 93 | .WithMessage("Only five tertiary GUI actions are allowed.")
|
95 | 94 | .ForEach(x => x.SetValidator(guiActionValidator));
|
|
0 commit comments