- IMedioRepository, ISeccionRepository interfaces - MediosQuery, SeccionesQuery common records - TipoSeccion static AllowedTipos helper - Medios: 6 use cases (Create/Update/Deactivate/Reactivate/List/GetById) with validators, handlers and DTOs - Secciones: 6 use cases mirroring Medios; Create validates MedioId active via IMedioRepository - 52 unit tests (xUnit + NSubstitute) all green; audit LogAsync asserted per mutating handler - DI registrations for all 12 handlers and validators auto-scanned via AddValidatorsFromAssemblyContaining
26 lines
993 B
C#
26 lines
993 B
C#
using FluentValidation;
|
|
using SIGCM2.Domain.Entities;
|
|
|
|
namespace SIGCM2.Application.Medios.Create;
|
|
|
|
public sealed class CreateMedioCommandValidator : AbstractValidator<CreateMedioCommand>
|
|
{
|
|
private const int CodigoMaxLength = 30;
|
|
private const int NombreMaxLength = 100;
|
|
|
|
public CreateMedioCommandValidator()
|
|
{
|
|
RuleFor(x => x.Codigo)
|
|
.NotEmpty().WithMessage("El código es requerido.")
|
|
.MaximumLength(CodigoMaxLength).WithMessage($"El código no puede superar los {CodigoMaxLength} caracteres.")
|
|
.Matches(@"^[A-Za-z0-9_]+$").WithMessage("El código solo puede contener letras, dígitos y guiones bajos.");
|
|
|
|
RuleFor(x => x.Nombre)
|
|
.NotEmpty().WithMessage("El nombre es requerido.")
|
|
.MaximumLength(NombreMaxLength).WithMessage($"El nombre no puede superar los {NombreMaxLength} caracteres.");
|
|
|
|
RuleFor(x => x.Tipo)
|
|
.IsInEnum().WithMessage("El tipo de medio no es válido.");
|
|
}
|
|
}
|