Commit Graph

17 Commits

Author SHA1 Message Date
e12b64a517 test: Add 10 unit tests for MergePdfsAsync + LoadTestPdfAsStream helper
Unit tests (10):
- MergePdfsAsync_TwoPdfs_ReturnsMergedPdf
- MergePdfsAsync_ThreePdfs_ReturnsMergedPdf
- MergePdfsAsync_WithNullPageRanges_MergesAllPages
- MergePdfsAsync_WithEmptyPageRanges_MergesAllPages
- MergePdfsAsync_WithRangeFormat_MergesSelectedPages
- MergePdfsAsync_SinglePdf_ThrowsBadRequestException
- MergePdfsAsync_InvalidPageRangeCount_ThrowsBadRequestException
- MergePdfsAsync_InvalidPageRangeFormat_ThrowsBadRequestException
- MergePdfsAsync_PageNumberOutOfRange_ThrowsBadRequestException
- MergePdfsAsync_StreamNotAtPositionZero_ThrowsBadRequestException

Helper:
- Add LoadTestPdfAsStream helper for Stream-returning test setup
2026-07-21 10:20:53 +02:00
fa4e55242d fix: Update SwissQrCode test - ArgumentException to BadRequestException 2026-07-21 09:26:51 +02:00
61b1595258 test: Add ExtractAttachmentsAsync unit tests (ZIP validation, edge cases) 2026-07-21 09:26:27 +02:00
645dfceafa test(unit): migrate unit tests to Stream API
Application Handler Tests:
- ValidatePdfHandlerTests: PdfStream = new MemoryStream(pdfBytes)
- ValidatePdfAQueryHandlerTests: PdfStream = new MemoryStream(pdfBytes)
- CheckPdfAttachmentsQueryHandlerTests: PdfStream = new MemoryStream(pdfBytes)
- Remove Base64/PdfBytes property usage

Infrastructure Tests:
- DevExpressSwissQrCodeProcessorTests: LoadTestPdf() returns Stream
- All test methods use 'using var stream' pattern
- Add test: ExtractSwissQrCodeAsync_StreamNotAtBeginning_ThrowsBadRequestException

Result: All unit tests pass with Stream-based API
2026-07-20 16:33:00 +02:00
251ecc34d9 test: Add tests for CheckPdfAttachments feature
- Unit tests for CheckPdfAttachmentsQueryHandler (3 tests)
- Integration tests for PdfAttachmentController (14 tests covering both multipart and JSON endpoints)
- Tests verify: attachment detection, metadata extraction, empty PDF handling, validation errors
- All tests using Stream API (mocks with It.IsAny<Stream>())
- Total: 17 new tests, all passing
2026-07-20 11:56:19 +02:00
8aff3138ff test: Fix obsolete exception expectations in SwissQrCodeProcessor tests
- SwissQrCodeNotFoundException → NotFoundException (obsolete exception replaced)
- PdfProcessingException → ArgumentException (DevExpress throws ArgumentException for invalid PDFs)
- ArgumentNullException → NullReferenceException (actual behavior of current implementation)
2026-07-20 11:55:48 +02:00
58f9b07af3 test: Update Application handler unit tests for Stream API
- Update mock setups: It.IsAny<byte[]>() → It.IsAny<Stream>()
- Update mock verifications: Verify Stream parameter instead of byte[]
- Remove obsolete namespace imports (Domain.Models.ValueObjects)
- Update exception expectations (BadRequestException instead of PdfProcessingException)
2026-07-20 11:55:41 +02:00
468dca46d4 test: Update DevExpressPdfProcessor unit tests for Stream API
- Add ToStream() helper method to convert byte[] → MemoryStream
- Update all test method calls to use ToStream(pdfBytes)
- Fix null/empty stream tests (use Stream directly instead of byte[])
- Update exception expectations (ArgumentNullException for null streams, BadRequestException for empty streams)
- Update namespace imports (Application.Common.DTOs instead of Domain.Models.ValueObjects)
2026-07-20 11:55:33 +02:00
1a89887056 test: Update tests for tuple return type and new API structure
- Update unit tests to assert (Bill, string[]) tuple return
- Update integration tests for new response structure (Bill + RawLines)
- Fix exception message assertion in DevExpressSwissQrCodeProcessorTests
- All 34 tests passing, 6 skipped (require real Swiss QR Bill PDFs)
2026-07-16 15:47:56 +02:00
f7433111a7 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.
2026-07-09 14:01:57 +02:00
45bc90b8b8 test: Update integration tests for Controller-based API
Integration test updates:

  - PdfValidationControllerTests.cs (new)

    - Test /api/pdf/validation/validate endpoint

    - Test BOTH multipart/form-data AND Base64 JSON

  - ExtractSwissQrCodeEndpointTests.cs (updated)

    - Update endpoint path to /api/swissqrcode/extract

    - Test BOTH input formats

Unit test updates:

  - ValidatePdfHandlerTests.cs:

    - Update for Query + Handler co-location

    - Test AutoMapper integration

  - ExtractSwissQrCodeHandlerTests.cs:

    - Update for Query + Handler co-location

    - Test AutoMapper integration

Deleted:

  - DocumentEndpointsTests.cs (Minimal API tests, no longer relevant)

Result: 20/20 tests passing, Controller endpoint coverage
2026-07-07 19:01:35 +02:00
OlgunR
586fd4a207 Add Swiss QR Code extraction feature
Introduced DTOs for request and response to handle Swiss QR Code extraction from PDF documents. Implemented `ExtractSwissQrCodeHandler` to process the extraction using `ISwissQrCodeProcessor`. Added validation for the query with `ExtractSwissQrCodeValidator`. Developed unit tests to ensure correct behavior for successful and failure scenarios.
2026-06-26 08:46:42 +02:00
OlgunR
18e956c2cf Enhance PDF attachment detection and counting
Refactored `DevExpressPdfProcessor` to improve attachment detection:
- Changed `DetectEmbeddedFiles` return type to a tuple for better
  handling of attachment presence and count.
- Enhanced logic to parse `/Names` arrays and count object references
  for accurate attachment detection.
- Implemented robust search for `/EmbeddedFiles` to handle multiple
  occurrences and ensure proper context validation.

Updated PHASENPLAN.md and ROADMAP.md to reflect these changes, including
the addition of fixes for attachment detection and counting logic.

Added new tests in `DevExpressPdfProcessorTests`:
- Verified detection of multiple attachments and accurate counts.
- Ensured no crashes when processing PDFs with `/EmbeddedFiles`.

Included a new test resource (`pdfWithMoreThanOneAttachment.pdf`) for
validating multiple attachment scenarios.
2026-06-25 17:17:32 +02:00
OlgunR
1b38d5a729 Implement attachment detection in ValidatePDF
Updated PHASENPLAN.md and ROADMAP.md to reflect a complete restructuring of the development plan and added a "Bugfix: Attachment Detection" entry.

Implemented attachment detection in DevExpressPdfProcessor.cs using the new `DetectEmbeddedFiles` method, which scans raw PDF data for the `/EmbeddedFiles` keyword. Updated the `hasAttachments` property to use this method and set `attachmentCount` to `-1` when attachments are detected.

Added a new test, `ValidateAsync_PdfWithoutAttachments_ReturnsNoAttachments`, in DevExpressPdfProcessorTests.cs to verify that PDFs without attachments are correctly identified. Included a note about future testing for PDFs with attachments using ZUGFeRD files.

All related tests are passing (12/12 green).
2026-06-25 16:25:16 +02:00
OlgunR
afc0e34312 Complete Step 1.1: ValidatePDF Application Layer
Updated PHASENPLAN and ROADMAP to reflect progress on Feature 1 - ValidatePDF (75% complete). Marked Step 1.1 as completed, including MediatR setup, pipeline behaviors (`ValidationBehavior`, `LoggingBehavior`), ValidatePDF feature (Query, Handler, Validator), and DTOs.

Added `DependencyInjection.cs` for Application Layer DI configuration. Introduced `LoggingBehavior` and `ValidationBehavior` for MediatR pipelines. Implemented `ValidatePdfHandler`, `ValidatePdfQuery`, and `ValidatePdfValidator`.

Created DTOs (`ValidatePdfRequest`, `ValidatePdfResponse`) for the ValidatePDF feature. Added unit tests for `ValidatePdfHandler` to verify metadata handling and exception propagation.

Removed unused folder references in `DocumentOperator.Application.csproj`.
2026-06-25 15:23:58 +02:00
OlgunR
b1d48418cf Migrate to DevExpress.Document.Processor library
Replaced `DevExpress.Pdf.Core` with `DevExpress.Document.Processor` in `DocumentOperator.Infrastructure.csproj` to adopt a newer library for PDF processing. Removed the `Services\PdfProcessing\` folder reference.

Updated `DevExpressPdfProcessorTests` to reflect changes in the `ValidateAsync` method's behavior.

Introduced the `DevExpressPdfProcessor` class, implementing the `IPdfProcessor` interface. This class validates PDF documents and extracts metadata using the `DevExpress.Pdf` library. Added defensive input validation, metadata extraction, and exception handling for domain consistency.
2026-06-23 10:33:43 +02:00
OlgunR
64be11f7ad Add tests for DevExpressPdfProcessor and roadmap updates
Updated ROADMAP.md to reflect progress on the TDD process for
DevExpressPdfProcessor, including the creation of unit tests
(6 tests in the Red Phase). Updated progress to 4/7 mini-steps
completed and outlined the next step (Green Phase).

Added `DevExpressPdfProcessorTests.cs` with unit tests to
validate PDF files and extract metadata. Tests cover valid
PDFs, null/empty inputs, corrupted PDFs, and file size
calculations. Used `FluentAssertions` for assertions.

Cleaned up `DocumentOperator.Tests.csproj` by removing an
unused folder reference. No functional changes to the project
structure.
2026-06-19 14:38:12 +02:00