Skip to content

Commit

Permalink
Updated validator messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Fargekritt committed Sep 16, 2024
1 parent 711fa6d commit b53ad95
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Digdir.Domain.Dialogporten.Application.Common.Extensions.FluentValidation;
using Digdir.Domain.Dialogporten.Application.Common.Pagination;
using Digdir.Domain.Dialogporten.Application.Features.V1.Common.Localizations;
using Digdir.Domain.Dialogporten.Domain.Common;
using Digdir.Domain.Dialogporten.Domain.Localizations;
using FluentValidation;

Expand Down Expand Up @@ -45,8 +46,8 @@ public SearchDialogQueryValidator()
.When(x => x.ExtendedStatus is not null);

RuleFor(x => x.Process)
.Must(x => Uri.IsWellFormedUriString(x, UriKind.Absolute))
.WithMessage("{PropertyName} must be a valid URI")
.IsValidUri()
.MaximumLength(Constants.DefaultMaxUriLength)
.When(x => x.Process is not null);

RuleForEach(x => x.Status).IsInEnum();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ public NotificationConditionQueryValidator()
RuleFor(x => x.TransmissionId)
.NotNull()
.NotEqual(default(Guid))
.When(x => x.ActivityType == DialogActivityType.Values.TransmissionOpened);
.When(x => x.ActivityType == DialogActivityType.Values.TransmissionOpened)
.WithMessage($"{{PropertyName}} must not be empty when ${nameof(NotificationConditionQuery.ActivityType)} is ${nameof(DialogActivityType.Values.TransmissionOpened)}");

RuleFor(x => x.TransmissionId)
.Null()
.When(x => x.ActivityType == DialogActivityType.Values.DialogOpened)
.WithMessage($"{{PropertyName}} must be empty when {nameof(NotificationConditionQuery.ActivityType)} is {DialogActivityType.Values.DialogOpened}.");
.WithMessage($"{{PropertyName}} must be empty when {nameof(NotificationConditionQuery.ActivityType)} is {nameof(DialogActivityType.Values.DialogOpened)}.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ public CreateDialogCommandValidator(
.SetValidator(activityValidator);

RuleFor(x => x.Process)
.Must(x => Uri.IsWellFormedUriString(x, UriKind.Absolute))
.WithMessage("{PropertyName} must be a valid absolute URI.")
.IsValidUri()
.MaximumLength(Constants.DefaultMaxUriLength)
.When(x => x.Process is not null);

RuleFor(x => x.Process)
Expand All @@ -144,8 +144,8 @@ public CreateDialogCommandValidator(
.When(x => x.PrecedingProcess is not null);

RuleFor(x => x.PrecedingProcess)
.Must(x => Uri.IsWellFormedUriString(x, UriKind.Absolute))
.WithMessage("{PropertyName} must be a valid absolute URI.")
.IsValidUri()
.MaximumLength(Constants.DefaultMaxUriLength)
.When(x => x.PrecedingProcess is not null);
}
}
Expand Down

0 comments on commit b53ad95

Please sign in to comment.