test: Add PDF/A validation tests and manual testing guide
- 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.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using DocumentOperator.Application.Common.DTOs;
|
||||
using DocumentOperator.Application.ValidatePdf.Queries;
|
||||
using DocumentOperator.Application.ValidatePdfA.Queries;
|
||||
using FluentAssertions;
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
using System.Net;
|
||||
@@ -166,4 +167,151 @@ public class PdfValidationControllerTests : IClassFixture<WebApplicationFactory<
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region PDF/A Validation Tests (Base64)
|
||||
|
||||
[Fact]
|
||||
public async Task POST_ValidatePdfA_Base64_ValidPdf_Returns200()
|
||||
{
|
||||
// Arrange
|
||||
var assembly = typeof(PdfValidationControllerTests).Assembly;
|
||||
var resourceName = "DocumentOperator.Tests.TestData.Pdfs.valid.pdf";
|
||||
|
||||
byte[] pdfBytes;
|
||||
using (var stream = assembly.GetManifestResourceStream(resourceName))
|
||||
{
|
||||
if (stream == null)
|
||||
{
|
||||
throw new InvalidOperationException($"Test resource '{resourceName}' not found");
|
||||
}
|
||||
|
||||
using var ms = new MemoryStream();
|
||||
await stream.CopyToAsync(ms);
|
||||
pdfBytes = ms.ToArray();
|
||||
}
|
||||
|
||||
var base64Pdf = Convert.ToBase64String(pdfBytes);
|
||||
var request = new ValidatePdfAQuery { Base64Pdf = base64Pdf };
|
||||
|
||||
// Act
|
||||
var response = await _client.PostAsJsonAsync("/api/pdf/validation/validate-pdfa", request);
|
||||
|
||||
// Assert
|
||||
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
||||
|
||||
var result = await response.Content.ReadFromJsonAsync<PdfAValidationResult>();
|
||||
result.Should().NotBeNull();
|
||||
result!.IsValid.Should().BeTrue();
|
||||
result.PageCount.Should().BeGreaterThan(0);
|
||||
result.PdfVersion.Should().NotBeNullOrEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task POST_ValidatePdfA_Base64_InvalidBase64_Returns400()
|
||||
{
|
||||
// Arrange
|
||||
var request = new ValidatePdfAQuery { Base64Pdf = "invalid-base64!!!" };
|
||||
|
||||
// Act
|
||||
var response = await _client.PostAsJsonAsync("/api/pdf/validation/validate-pdfa", request);
|
||||
|
||||
// Assert
|
||||
response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
|
||||
|
||||
var problemDetails = await response.Content.ReadAsStringAsync();
|
||||
problemDetails.Should().Contain("Base64");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task POST_ValidatePdfA_Base64_EmptyPdf_Returns400()
|
||||
{
|
||||
// Arrange
|
||||
var request = new ValidatePdfAQuery { Base64Pdf = string.Empty };
|
||||
|
||||
// Act
|
||||
var response = await _client.PostAsJsonAsync("/api/pdf/validation/validate-pdfa", request);
|
||||
|
||||
// Assert
|
||||
response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
|
||||
|
||||
var problemDetails = await response.Content.ReadAsStringAsync();
|
||||
problemDetails.Should().Contain("Either PdfBytes or Base64Pdf must be provided");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region PDF/A Validation Tests (Multipart)
|
||||
|
||||
[Fact]
|
||||
public async Task POST_ValidatePdfA_Multipart_ValidPdf_Returns200()
|
||||
{
|
||||
// Arrange
|
||||
var assembly = typeof(PdfValidationControllerTests).Assembly;
|
||||
var resourceName = "DocumentOperator.Tests.TestData.Pdfs.valid.pdf";
|
||||
|
||||
byte[] pdfBytes;
|
||||
using (var stream = assembly.GetManifestResourceStream(resourceName))
|
||||
{
|
||||
if (stream == null)
|
||||
{
|
||||
throw new InvalidOperationException($"Test resource '{resourceName}' not found");
|
||||
}
|
||||
|
||||
using var ms = new MemoryStream();
|
||||
await stream.CopyToAsync(ms);
|
||||
pdfBytes = ms.ToArray();
|
||||
}
|
||||
|
||||
// Create multipart/form-data content
|
||||
using var content = new MultipartFormDataContent();
|
||||
var fileContent = new ByteArrayContent(pdfBytes);
|
||||
fileContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/pdf");
|
||||
content.Add(fileContent, "file", "test.pdf");
|
||||
|
||||
// Act
|
||||
var response = await _client.PostAsync("/api/pdf/validation/validate-pdfa", content);
|
||||
|
||||
// Assert
|
||||
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
||||
|
||||
var result = await response.Content.ReadFromJsonAsync<PdfAValidationResult>();
|
||||
result.Should().NotBeNull();
|
||||
result!.IsValid.Should().BeTrue();
|
||||
result.PageCount.Should().BeGreaterThan(0);
|
||||
result.PdfVersion.Should().NotBeNullOrEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task POST_ValidatePdfA_Multipart_EmptyFile_Returns400()
|
||||
{
|
||||
// Arrange
|
||||
using var content = new MultipartFormDataContent();
|
||||
var fileContent = new ByteArrayContent(Array.Empty<byte>());
|
||||
fileContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/pdf");
|
||||
content.Add(fileContent, "file", "empty.pdf");
|
||||
|
||||
// Act
|
||||
var response = await _client.PostAsync("/api/pdf/validation/validate-pdfa", content);
|
||||
|
||||
// Assert
|
||||
response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
|
||||
|
||||
var problemDetails = await response.Content.ReadAsStringAsync();
|
||||
problemDetails.Should().Contain("cannot be empty");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task POST_ValidatePdfA_Multipart_NoFile_Returns400()
|
||||
{
|
||||
// Arrange
|
||||
using var content = new MultipartFormDataContent();
|
||||
|
||||
// Act
|
||||
var response = await _client.PostAsync("/api/pdf/validation/validate-pdfa", content);
|
||||
|
||||
// Assert
|
||||
response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user