Update validators to use IsInEnum for Entity property

Refactored DeleteObjectProcedureValidator, InsertObjectProcedureValidator, and UpdateObjectProcedureValidator to use .IsInEnum() for validating the Entity property. This replaces custom or hardcoded checks with enum-based validation, improving consistency, maintainability, and robustness across all validators.
This commit is contained in:
2026-04-16 17:13:00 +02:00
parent 6374a5c257
commit d61f5ce885
3 changed files with 10 additions and 4 deletions

View File

@@ -7,6 +7,10 @@ public class DeleteObjectProcedureValidator : AbstractValidator<DeleteObjectProc
{ {
public DeleteObjectProcedureValidator() public DeleteObjectProcedureValidator()
{ {
RuleFor(x => x.Entity)
.IsInEnum()
.WithMessage("ENTITY must be a valid EntityType value.");
RuleFor(x => x.Start) RuleFor(x => x.Start)
.GreaterThan(0) .GreaterThan(0)
.WithMessage("Start GUID/ID must be greater than 0."); .WithMessage("Start GUID/ID must be greater than 0.");

View File

@@ -7,11 +7,9 @@ public class InsertObjectProcedureValidator : AbstractValidator<InsertObjectProc
{ {
public InsertObjectProcedureValidator() public InsertObjectProcedureValidator()
{ {
// ENTITY must be one of the allowed values
RuleFor(x => x.Entity) RuleFor(x => x.Entity)
.NotEmpty() .IsInEnum()
.Must(e => e is "ACTION" or "ENDPOINT" or "ENDPOINT_AUTH" or "ENDPOINT_PARAMS" or "PROFILE" or "RESULT") .WithMessage("ENTITY must be a valid EntityType value.");
.WithMessage("ENTITY must be one of: ACTION, ENDPOINT, ENDPOINT_AUTH, ENDPOINT_PARAMS, PROFILE, RESULT.");
// ACTION validation // ACTION validation
When(x => x.Action != null, () => When(x => x.Action != null, () =>

View File

@@ -7,6 +7,10 @@ public class UpdateObjectProcedureValidator : AbstractValidator<UpdateObjectProc
{ {
public UpdateObjectProcedureValidator() public UpdateObjectProcedureValidator()
{ {
RuleFor(x => x.Entity)
.IsInEnum()
.WithMessage("ENTITY must be a valid EntityType value.");
RuleFor(x => x.Id) RuleFor(x => x.Id)
.GreaterThan(0) .GreaterThan(0)
.WithMessage("Target GUID/ID must be greater than 0."); .WithMessage("Target GUID/ID must be greater than 0.");