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:
@@ -7,6 +7,10 @@ public class DeleteObjectProcedureValidator : AbstractValidator<DeleteObjectProc
|
||||
{
|
||||
public DeleteObjectProcedureValidator()
|
||||
{
|
||||
RuleFor(x => x.Entity)
|
||||
.IsInEnum()
|
||||
.WithMessage("ENTITY must be a valid EntityType value.");
|
||||
|
||||
RuleFor(x => x.Start)
|
||||
.GreaterThan(0)
|
||||
.WithMessage("Start GUID/ID must be greater than 0.");
|
||||
|
||||
@@ -7,11 +7,9 @@ public class InsertObjectProcedureValidator : AbstractValidator<InsertObjectProc
|
||||
{
|
||||
public InsertObjectProcedureValidator()
|
||||
{
|
||||
// ENTITY must be one of the allowed values
|
||||
RuleFor(x => x.Entity)
|
||||
.NotEmpty()
|
||||
.Must(e => e is "ACTION" or "ENDPOINT" or "ENDPOINT_AUTH" or "ENDPOINT_PARAMS" or "PROFILE" or "RESULT")
|
||||
.WithMessage("ENTITY must be one of: ACTION, ENDPOINT, ENDPOINT_AUTH, ENDPOINT_PARAMS, PROFILE, RESULT.");
|
||||
.IsInEnum()
|
||||
.WithMessage("ENTITY must be a valid EntityType value.");
|
||||
|
||||
// ACTION validation
|
||||
When(x => x.Action != null, () =>
|
||||
|
||||
@@ -7,6 +7,10 @@ public class UpdateObjectProcedureValidator : AbstractValidator<UpdateObjectProc
|
||||
{
|
||||
public UpdateObjectProcedureValidator()
|
||||
{
|
||||
RuleFor(x => x.Entity)
|
||||
.IsInEnum()
|
||||
.WithMessage("ENTITY must be a valid EntityType value.");
|
||||
|
||||
RuleFor(x => x.Id)
|
||||
.GreaterThan(0)
|
||||
.WithMessage("Target GUID/ID must be greater than 0.");
|
||||
|
||||
Reference in New Issue
Block a user