- Add unit tests for ValidatePdfAQueryHandler (4 tests) - Add integration tests for PDF/A validation endpoint (6 tests) - Fix FluentValidation: Add Base64 format validation to ValidatePdfAQueryValidator - Update AGENTS.md: Document 3-folder test structure rationale and test count (30 tests) - Add DocumentOperator.API/README.md: 16 manual test scenarios for all endpoints Test coverage: - Unit: ValidatePdfAQueryHandler (compliant, non-compliant, encrypted, exceptions) - Integration: PDF/A endpoint (multipart + Base64, validation, error handling) - Manual: Step-by-step Swagger UI testing guide for all features All 30 automated tests passing.
49 lines
1.4 KiB
C#
49 lines
1.4 KiB
C#
using FluentValidation;
|
|
|
|
namespace DocumentOperator.Application.ValidatePdfA.Validators;
|
|
|
|
/// <summary>
|
|
/// Validator for ValidatePdfAQuery
|
|
/// Ensures exactly ONE input format is provided (PdfBytes XOR Base64Pdf)
|
|
/// </summary>
|
|
public class ValidatePdfAQueryValidator : AbstractValidator<Queries.ValidatePdfAQuery>
|
|
{
|
|
public ValidatePdfAQueryValidator()
|
|
{
|
|
RuleFor(x => x)
|
|
.Must(x => (x.PdfBytes != null && x.PdfBytes.Length > 0) ^
|
|
!string.IsNullOrWhiteSpace(x.Base64Pdf))
|
|
.WithMessage("Either PdfBytes or Base64Pdf must be provided, but not both");
|
|
|
|
When(x => !string.IsNullOrWhiteSpace(x.Base64Pdf), () =>
|
|
{
|
|
RuleFor(x => x.Base64Pdf!)
|
|
.Must(BeValidBase64)
|
|
.WithMessage("Base64Pdf must be a valid Base64 string");
|
|
});
|
|
|
|
When(x => x.PdfBytes != null, () =>
|
|
{
|
|
RuleFor(x => x.PdfBytes!)
|
|
.Must(bytes => bytes.Length > 0)
|
|
.WithMessage("PdfBytes cannot be empty");
|
|
});
|
|
}
|
|
|
|
private static bool BeValidBase64(string base64)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(base64))
|
|
return false;
|
|
|
|
try
|
|
{
|
|
Convert.FromBase64String(base64);
|
|
return true;
|
|
}
|
|
catch (FormatException)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|