Compare commits
6 Commits
196f6d9cfb
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
64be11f7ad | ||
|
|
b88f011701 | ||
|
|
b8c9e1b6a6 | ||
|
|
09cc64eff0 | ||
|
|
867e0b2655 | ||
|
|
fc79665241 |
@@ -434,8 +434,17 @@ public class ApplyStampHandler : IRequestHandler<ApplyStampCommand, byte[]>
|
|||||||
| Package | Version | Purpose |
|
| Package | Version | Purpose |
|
||||||
|---------|---------|---------|
|
|---------|---------|---------|
|
||||||
| **DevExpress.Pdf.Core** | 25.2.8 | PDF-Operationen (Merge, Extract, Sign, etc.) |
|
| **DevExpress.Pdf.Core** | 25.2.8 | PDF-Operationen (Merge, Extract, Sign, etc.) |
|
||||||
|
| **DevExpress Universal License** | ? Verfügbar | **Vollzugriff auf alle DevExpress Bibliotheken** |
|
||||||
| **Microsoft.Extensions.Options.ConfigurationExtensions** | 8.0.0 | Options Pattern |
|
| **Microsoft.Extensions.Options.ConfigurationExtensions** | 8.0.0 | Options Pattern |
|
||||||
|
|
||||||
|
**Hinweis zur DevExpress Lizenz:**
|
||||||
|
- ? Universal License vorhanden - wir können **ALLE** DevExpress Pakete nutzen
|
||||||
|
- Neben `DevExpress.Pdf.Core` können wir auch weitere Pakete integrieren:
|
||||||
|
- `DevExpress.Office.Core` (Word, Excel)
|
||||||
|
- `DevExpress.Document.Processor` (erweiterte Dokumenten-Verarbeitung)
|
||||||
|
- `DevExpress.Blazor` (falls UI später benötigt wird)
|
||||||
|
- Alle weiteren DevExpress Produkte nach Bedarf
|
||||||
|
|
||||||
#### Domain Layer
|
#### Domain Layer
|
||||||
|
|
||||||
| Package | Version | Purpose |
|
| Package | Version | Purpose |
|
||||||
@@ -1289,36 +1298,62 @@ public async Task POST_ValidatePdf_InvalidPdf_Returns400() { }
|
|||||||
|
|
||||||
### ? Completed
|
### ? Completed
|
||||||
- **Phase 1:** Foundation & Clean Architecture Setup ?
|
- **Phase 1:** Foundation & Clean Architecture Setup ?
|
||||||
|
- Solution Structure ?
|
||||||
- Dependencies ?
|
- Dependencies ?
|
||||||
- Packages ?
|
- NuGet Packages ?
|
||||||
- Folder Structure ?
|
- Folder Structure ?
|
||||||
- Configuration ?
|
- Configuration (appsettings.json) ?
|
||||||
- Serilog ?
|
- Serilog Setup ?
|
||||||
|
- Program.cs Setup ?
|
||||||
|
|
||||||
- **Phase 2:** Domain Layer (Minimal) ?
|
- **Phase 2:** Domain Layer (Minimal) ?
|
||||||
- ? Step 2.1 - Domain Exceptions (4 Exceptions erstellt)
|
- ? Step 2.1 - Domain Exceptions (4 Exceptions erstellt)
|
||||||
|
- `DomainException.cs`
|
||||||
|
- `DomainValidationException.cs`
|
||||||
|
- `NotFoundException.cs`
|
||||||
|
- `PdfProcessingException.cs`
|
||||||
- ? Step 2.2 - Enums (DocumentOperationType, ProcessingStatus)
|
- ? Step 2.2 - Enums (DocumentOperationType, ProcessingStatus)
|
||||||
- ? Step 2.3 - Value Objects (Base64String, TenantId, PdfMetadata)
|
- ? Step 2.3 - Value Objects (Base64String, TenantId, PdfMetadata)
|
||||||
|
|
||||||
### ?? In Progress
|
|
||||||
- **Phase 3:** Infrastructure Layer (Outside-In!)
|
- **Phase 3:** Infrastructure Layer (Outside-In!)
|
||||||
- **NEXT:** Step 3.1 - IPdfProcessor Interface erstellen
|
- ? Step 3.1 - IPdfProcessor Interface erstellt
|
||||||
|
- ?? Step 3.2 - DevExpressPdfProcessor implementieren (TDD - **IN PROGRESS**)
|
||||||
### ? Pending
|
- ? Step 3.2.1 - ProcessDocument Ordner gelöscht (Application Layer cleanup)
|
||||||
- **Phase 1:** Foundation & Clean Architecture Setup
|
- ? Step 3.2.2 - Test-Ordnerstruktur erstellt (Unit/Infrastructure/Services/PdfProcessing)
|
||||||
- Dependencies ?
|
- ? Step 3.2.3 - Test-PDF Datei hinzugefügt (valid.pdf als Embedded Resource)
|
||||||
- Packages ?
|
- ? Step 3.2.4 - DevExpressPdfProcessorTests.cs erstellt (TDD Red Phase - 6 Tests)
|
||||||
- Folder Structure ?
|
|
||||||
- Configuration ?
|
|
||||||
- Serilog ?
|
|
||||||
|
|
||||||
### ?? In Progress
|
### ?? In Progress
|
||||||
- **Phase 2:** Domain Layer (Minimal)
|
- **Phase 3, Step 3.2:** DevExpressPdfProcessor (TDD)
|
||||||
- ? Step 2.1 - Domain Exceptions
|
- **NEXT:** Step 3.2.5 - DevExpressPdfProcessor.cs implementieren (TDD Green Phase)
|
||||||
- **NEXT:** Step 2.2 - Enums
|
- **Progress:** 4/7 Mini-Steps abgeschlossen
|
||||||
|
|
||||||
### ? Pending
|
### ? Pending
|
||||||
- Phase 3-9
|
- **Phase 3:** Infrastructure Layer
|
||||||
|
- Step 3.2 - DevExpressPdfProcessor Implementation
|
||||||
|
|
||||||
|
- **Phase 4:** Application Layer
|
||||||
|
- Step 4.1 - MediatR Setup (DependencyInjection.cs, ValidationBehavior.cs)
|
||||||
|
- Step 4.2 - ValidatePdf Feature (Query, Handler, Validator)
|
||||||
|
|
||||||
|
- **Phase 5:** API Layer
|
||||||
|
- Step 5.1 - Exception Handling Middleware
|
||||||
|
- Step 5.2 - Minimal API Endpoint
|
||||||
|
- Step 5.3 - Integration Test
|
||||||
|
|
||||||
|
- **Phase 6-9:** Weitere Features, Swagger, Multi-Tenancy, Production
|
||||||
|
|
||||||
|
### ?? Hinweise zum aktuellen Stand
|
||||||
|
|
||||||
|
1. **Infrastructure Services:**
|
||||||
|
- Ordner existieren (PdfProcessing, FileStorage, DocumentValidation)
|
||||||
|
- **Aber:** Alle leer
|
||||||
|
- ?? **Action:** DevExpressPdfProcessor.cs implementieren (Step 3.2 - IN PROGRESS)
|
||||||
|
|
||||||
|
2. **DevExpress Universal License:**
|
||||||
|
- ? **Verfügbar!** Wir können alle DevExpress Pakete nutzen
|
||||||
|
- Aktuell nur: `DevExpress.Pdf.Core`
|
||||||
|
- Bei Bedarf können weitere Pakete hinzugefügt werden
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -1440,7 +1475,17 @@ public async Task POST_ValidatePdf_InvalidPdf_Returns400() { }
|
|||||||
| 2024-XX-XX | Phase 1 | ? Phase 1 completed |
|
| 2024-XX-XX | Phase 1 | ? Phase 1 completed |
|
||||||
| 2024-XX-XX | Phase 2 | ? Step 2.1 completed - Domain Exceptions created |
|
| 2024-XX-XX | Phase 2 | ? Step 2.1 completed - Domain Exceptions created |
|
||||||
| 17.01.2025 | Roadmap | ?? **ROADMAP komplett überarbeitet** (Pragmatisch, Outside-In, TDD) |
|
| 17.01.2025 | Roadmap | ?? **ROADMAP komplett überarbeitet** (Pragmatisch, Outside-In, TDD) |
|
||||||
| 17.01.2025 | Phase 2 | ?? Starting Step 2.2 - Enums (vor Value Objects) |
|
| 17.01.2025 | Phase 2 | ? Step 2.2 completed - Enums erstellt |
|
||||||
|
| 17.01.2025 | Phase 2 | ? Step 2.3 completed - Value Objects erstellt |
|
||||||
|
| 17.01.2025 | Phase 2 | ? **Phase 2 (Domain Layer) komplett abgeschlossen!** |
|
||||||
|
| 17.01.2025 | Phase 3 | ? Step 3.1 completed - IPdfProcessor Interface erstellt |
|
||||||
|
| 17.01.2025 | Roadmap | ?? **ROADMAP Status-Update** - Aktueller Projektstand dokumentiert |
|
||||||
|
| 17.01.2025 | Infrastructure | ?? **DevExpress Universal License** hinzugefügt - Vollzugriff auf alle Pakete |
|
||||||
|
| 17.01.2025 | Phase 3 | ?? **Step 3.2 gestartet** - DevExpressPdfProcessor (TDD) |
|
||||||
|
| 17.01.2025 | Application | ? Step 3.2.1 - ProcessDocument Ordner gelöscht (Cleanup) |
|
||||||
|
| 17.01.2025 | Tests | ? Step 3.2.2 - Test-Ordnerstruktur erstellt, UnitTest1.cs gelöscht |
|
||||||
|
| 17.01.2025 | Tests | ? Step 3.2.3 - Test-PDF (valid.pdf) als Embedded Resource hinzugefügt |
|
||||||
|
| 17.01.2025 | Tests | ? Step 3.2.4 - DevExpressPdfProcessorTests.cs erstellt (TDD Red - 6 Tests) |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
218
DocumentOperator.API/STATUS_UPDATE_17_01_2025.md
Normal file
218
DocumentOperator.API/STATUS_UPDATE_17_01_2025.md
Normal file
@@ -0,0 +1,218 @@
|
|||||||
|
# ?? Status Update - DocumentOperator (17.01.2025)
|
||||||
|
|
||||||
|
## ? Was wurde aktualisiert?
|
||||||
|
|
||||||
|
Die **ROADMAP.md** wurde vollständig mit dem **tatsächlichen Projektstand** abgeglichen und aktualisiert.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ?? Haupterkenntnisse
|
||||||
|
|
||||||
|
### 1. **DevExpress Universal License** ?
|
||||||
|
|
||||||
|
**Wichtig:** Das Projekt verfügt über eine **DevExpress Universal License**!
|
||||||
|
|
||||||
|
**Das bedeutet:**
|
||||||
|
- ? Vollzugriff auf **ALLE** DevExpress Bibliotheken
|
||||||
|
- ? Nicht nur `DevExpress.Pdf.Core` - wir können **jedes** DevExpress Paket nutzen
|
||||||
|
- ? Falls künftig Word/Excel-Verarbeitung benötigt wird ? einfach hinzufügen!
|
||||||
|
|
||||||
|
**Aktuell verwendet:**
|
||||||
|
- `DevExpress.Pdf.Core` v25.2.8
|
||||||
|
|
||||||
|
**Bei Bedarf verfügbar:**
|
||||||
|
- `DevExpress.Office.Core` (Word, Excel)
|
||||||
|
- `DevExpress.Document.Processor` (erweiterte Dokumenten-Verarbeitung)
|
||||||
|
- `DevExpress.Blazor` (falls UI später benötigt wird)
|
||||||
|
- Alle weiteren DevExpress Produkte
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 2. **Aktueller Projektstand**
|
||||||
|
|
||||||
|
#### ? Abgeschlossen (Completed)
|
||||||
|
|
||||||
|
**Phase 1: Foundation**
|
||||||
|
- ? Solution Structure (4 Projekte + Tests)
|
||||||
|
- ? Dependencies (Clean Architecture Rules)
|
||||||
|
- ? NuGet Packages installiert
|
||||||
|
- ? Folder Structure erstellt
|
||||||
|
- ? Configuration (appsettings.json, Options Pattern)
|
||||||
|
- ? Serilog Setup
|
||||||
|
- ? Program.cs Setup
|
||||||
|
|
||||||
|
**Phase 2: Domain Layer (Minimal)**
|
||||||
|
- ? **4 Domain Exceptions:**
|
||||||
|
- `DomainException.cs` (Basis)
|
||||||
|
- `DomainValidationException.cs` (Value Object Validierung)
|
||||||
|
- `NotFoundException.cs` (Resource nicht gefunden)
|
||||||
|
- `PdfProcessingException.cs` (PDF-spezifische Fehler)
|
||||||
|
|
||||||
|
- ? **2 Enums:**
|
||||||
|
- `DocumentOperationType` (Validate, ExtractAttachments, Concatenate, ApplyStamp, EmbedCertificate)
|
||||||
|
- `ProcessingStatus` (Pending, Processing, Success, Failed)
|
||||||
|
|
||||||
|
- ? **3 Value Objects:**
|
||||||
|
- `Base64String` (typsicher, selbst-validierend, mit Factory Methods)
|
||||||
|
- `TenantId` (normalisiert, validiert)
|
||||||
|
- `PdfMetadata` (PageCount, FileSizeBytes, PdfVersion, HasAttachments, etc.)
|
||||||
|
|
||||||
|
**Phase 3: Infrastructure Layer**
|
||||||
|
- ? **IPdfProcessor Interface** erstellt
|
||||||
|
- `Task<PdfMetadata> ValidateAsync(byte[] pdfBytes)`
|
||||||
|
- Mit XML Comments dokumentiert
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
#### ?? In Arbeit (In Progress)
|
||||||
|
|
||||||
|
**Phase 3: Infrastructure Layer**
|
||||||
|
- **NEXT:** Step 3.2 - `DevExpressPdfProcessor` implementieren (mit TDD!)
|
||||||
|
- Ordner `Services/PdfProcessing/` existiert bereits
|
||||||
|
- **Aber:** Noch leer - muss implementiert werden
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
#### ?? Wichtige Hinweise
|
||||||
|
|
||||||
|
**1. Application Layer - ProcessDocument vs ValidatePdf**
|
||||||
|
- **Problem:**
|
||||||
|
- Ordner: `Features/Documents/ProcessDocument/`
|
||||||
|
- Dateien: `ProcessDocumentCommand.cs`, `ProcessDocumentHandler.cs`, `ProcessDocumentValidator.cs`
|
||||||
|
- **Alle leer!**
|
||||||
|
|
||||||
|
- **Roadmap sagt:**
|
||||||
|
- Wir sollten mit `ValidatePdf` Feature starten (nicht ProcessDocument)
|
||||||
|
|
||||||
|
- **Action Required:**
|
||||||
|
- Entweder ProcessDocument-Dateien löschen
|
||||||
|
- Oder umbenennen zu ValidatePdf
|
||||||
|
- Oder erst später nutzen (wenn wir ein generisches ProcessDocument Command brauchen)
|
||||||
|
|
||||||
|
**2. Tests Layer**
|
||||||
|
- **Problem:** Nur `UnitTest1.cs` (Dummy-Test)
|
||||||
|
- **Action Required:**
|
||||||
|
- Ordnerstruktur erstellen:
|
||||||
|
```
|
||||||
|
Tests/
|
||||||
|
??? Unit/
|
||||||
|
? ??? Application/
|
||||||
|
? ??? Infrastructure/
|
||||||
|
? ??? Domain/
|
||||||
|
??? Integration/
|
||||||
|
??? API/
|
||||||
|
```
|
||||||
|
- `UnitTest1.cs` löschen
|
||||||
|
|
||||||
|
**3. Infrastructure Services**
|
||||||
|
- **Problem:** Ordner existieren, aber leer
|
||||||
|
- `Services/PdfProcessing/` ? DevExpressPdfProcessor.cs fehlt
|
||||||
|
- `Services/FileStorage/` ? leer
|
||||||
|
- `Services/DocumentValidation/` ? leer
|
||||||
|
|
||||||
|
- **Action Required:**
|
||||||
|
- Step 3.2 durchführen: DevExpressPdfProcessor implementieren
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ?? Nächste Schritte (Roadmap)
|
||||||
|
|
||||||
|
### Schritt 1: DevExpressPdfProcessor implementieren (Phase 3, Step 3.2)
|
||||||
|
|
||||||
|
**TDD-Flow:**
|
||||||
|
1. **Test schreiben** (Red)
|
||||||
|
- `Tests/Unit/Infrastructure/Services/PdfProcessing/DevExpressPdfProcessorTests.cs`
|
||||||
|
- Test: `ValidateAsync_ValidPdf_ReturnsMetadata()`
|
||||||
|
|
||||||
|
2. **Code schreiben** (Green)
|
||||||
|
- `Infrastructure/Services/PdfProcessing/DevExpressPdfProcessor.cs`
|
||||||
|
- `IPdfProcessor` Interface implementieren
|
||||||
|
- DevExpress PDF API nutzen
|
||||||
|
|
||||||
|
3. **Test grün machen**
|
||||||
|
|
||||||
|
4. **Refactoring** (falls nötig)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Schritt 2: Application Layer aufräumen
|
||||||
|
|
||||||
|
**Option A: ProcessDocument löschen**
|
||||||
|
```powershell
|
||||||
|
Remove-Item "DocumentOperator.Application\Features\Documents\ProcessDocument" -Recurse
|
||||||
|
```
|
||||||
|
|
||||||
|
**Option B: Zu ValidatePdf umbenennen**
|
||||||
|
```powershell
|
||||||
|
Rename-Item "ProcessDocument" "ValidatePdf"
|
||||||
|
# Dann Dateien umbenennen + Namespaces anpassen
|
||||||
|
```
|
||||||
|
|
||||||
|
**Option C: Behalten und später nutzen**
|
||||||
|
- Erst ValidatePdf neu erstellen
|
||||||
|
- ProcessDocument später für generisches Command nutzen
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Schritt 3: MediatR Setup (Phase 4, Step 4.1)
|
||||||
|
|
||||||
|
**Erstellen:**
|
||||||
|
1. `Application/DependencyInjection.cs`
|
||||||
|
- MediatR registrieren
|
||||||
|
- FluentValidation registrieren
|
||||||
|
- ValidationBehavior registrieren
|
||||||
|
|
||||||
|
2. `Application/Common/Behaviors/ValidationBehavior.cs`
|
||||||
|
- Pipeline Behavior für FluentValidation
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Schritt 4: ValidatePdf Feature (Phase 4, Step 4.2)
|
||||||
|
|
||||||
|
**Erstellen:**
|
||||||
|
1. `Application/Features/Documents/ValidatePdf/ValidatePdfQuery.cs`
|
||||||
|
2. `Application/Features/Documents/ValidatePdf/ValidatePdfHandler.cs`
|
||||||
|
3. `Application/Features/Documents/ValidatePdf/ValidatePdfValidator.cs`
|
||||||
|
|
||||||
|
**Mit TDD:**
|
||||||
|
- `Tests/Unit/Application/Features/ValidatePdf/ValidatePdfHandlerTests.cs`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ?? Empfehlung
|
||||||
|
|
||||||
|
**Nächster Sprint:**
|
||||||
|
1. ? ROADMAP.md ist aktuell
|
||||||
|
2. **Jetzt:** DevExpressPdfProcessor implementieren (mit TDD)
|
||||||
|
3. **Dann:** Application Layer aufräumen (ProcessDocument ? ValidatePdf)
|
||||||
|
4. **Dann:** MediatR Setup + ValidationBehavior
|
||||||
|
5. **Dann:** ValidatePdf Feature komplett durchziehen
|
||||||
|
|
||||||
|
**Vorteil dieses Ansatzes:**
|
||||||
|
- Wir sehen **echten** Code (DevExpress Integration)
|
||||||
|
- Wir wissen welche Exceptions geworfen werden
|
||||||
|
- Application Layer kann darauf aufbauen
|
||||||
|
- Schneller Feedback-Loop
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ?? Build Status
|
||||||
|
|
||||||
|
? **Build erfolgreich!** (17.01.2025)
|
||||||
|
|
||||||
|
Alle Projekte kompilieren ohne Fehler.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ?? Dokumentation
|
||||||
|
|
||||||
|
- ? **ROADMAP.md** vollständig aktualisiert
|
||||||
|
- ? **STATUS_UPDATE_17_01_2025.md** erstellt (diese Datei)
|
||||||
|
- ? DevExpress Universal License dokumentiert
|
||||||
|
- ? Aktueller Projektstand dokumentiert
|
||||||
|
- ? Nächste Schritte klar definiert
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Last Updated:** 17.01.2025
|
||||||
|
**Status:** Ready für Phase 3, Step 3.2 (DevExpressPdfProcessor)
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace DocumentOperator.Application.Features.Documents.ProcessDocument
|
|
||||||
{
|
|
||||||
internal class ProcessDocumentCommand
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace DocumentOperator.Application.Features.Documents.ProcessDocument
|
|
||||||
{
|
|
||||||
internal class ProcessDocumentHandler
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace DocumentOperator.Application.Features.Documents.ProcessDocument
|
|
||||||
{
|
|
||||||
internal class ProcessDocumentValidator
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -9,6 +9,14 @@
|
|||||||
<IsTestProject>true</IsTestProject>
|
<IsTestProject>true</IsTestProject>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Remove="TestData\Pdfs\valid.pdf" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<EmbeddedResource Include="TestData\Pdfs\valid.pdf" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="coverlet.collector" Version="6.0.0" />
|
<PackageReference Include="coverlet.collector" Version="6.0.0" />
|
||||||
<PackageReference Include="FluentAssertions" Version="7.0.0" />
|
<PackageReference Include="FluentAssertions" Version="7.0.0" />
|
||||||
|
|||||||
BIN
DocumentOperator.Tests/TestData/Pdfs/valid.pdf
Normal file
BIN
DocumentOperator.Tests/TestData/Pdfs/valid.pdf
Normal file
Binary file not shown.
@@ -0,0 +1,146 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
using DocumentOperator.Application.Common.Interfaces;
|
||||||
|
using DocumentOperator.Domain.Common.Exceptions;
|
||||||
|
using DocumentOperator.Domain.Models.ValueObjects;
|
||||||
|
using DocumentOperator.Infrastructure.Services.PdfProcessing;
|
||||||
|
using FluentAssertions;
|
||||||
|
|
||||||
|
namespace DocumentOperator.Tests.Unit.Infrastructure.Services.PdfProcessing;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Unit tests for DevExpressPdfProcessor.
|
||||||
|
/// Tests PDF validation and metadata extraction.
|
||||||
|
/// </summary>
|
||||||
|
public class DevExpressPdfProcessorTests
|
||||||
|
{
|
||||||
|
private readonly IPdfProcessor _sut; // SUT = System Under Test
|
||||||
|
|
||||||
|
public DevExpressPdfProcessorTests()
|
||||||
|
{
|
||||||
|
// Arrange: Create instance (wird später implementiert)
|
||||||
|
_sut = new DevExpressPdfProcessor();
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Helper Methods
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Loads a test PDF from embedded resources.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filename">Name of the PDF file (e.g., "valid.pdf")</param>
|
||||||
|
/// <returns>PDF content as byte array</returns>
|
||||||
|
private static byte[] LoadTestPdf(string filename)
|
||||||
|
{
|
||||||
|
var assembly = Assembly.GetExecutingAssembly();
|
||||||
|
var resourceName = $"DocumentOperator.Tests.TestData.Pdfs.{filename}";
|
||||||
|
|
||||||
|
using var stream = assembly.GetManifestResourceStream(resourceName);
|
||||||
|
|
||||||
|
if (stream == null)
|
||||||
|
{
|
||||||
|
throw new FileNotFoundException(
|
||||||
|
$"Embedded resource '{resourceName}' not found. " +
|
||||||
|
$"Available resources: {string.Join(", ", assembly.GetManifestResourceNames())}");
|
||||||
|
}
|
||||||
|
|
||||||
|
using var memoryStream = new MemoryStream();
|
||||||
|
stream.CopyTo(memoryStream);
|
||||||
|
return memoryStream.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region ValidateAsync Tests
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task ValidateAsync_ValidPdf_ReturnsPdfMetadata()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
byte[] pdfBytes = LoadTestPdf("valid.pdf");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var metadata = await _sut.ValidateAsync(pdfBytes);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
metadata.Should().NotBeNull("a valid PDF should return metadata");
|
||||||
|
metadata.PageCount.Should().BeGreaterThan(0, "PDF must have at least one page");
|
||||||
|
metadata.FileSizeBytes.Should().Be(pdfBytes.Length, "file size should match input");
|
||||||
|
metadata.PdfVersion.Should().NotBeNullOrEmpty("PDF version should be detected");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task ValidateAsync_ValidPdf_ReturnsCorrectPageCount()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
byte[] pdfBytes = LoadTestPdf("valid.pdf");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var metadata = await _sut.ValidateAsync(pdfBytes);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
// Deine valid.pdf hat wahrscheinlich 1-5 Seiten - passe an!
|
||||||
|
metadata.PageCount.Should().BeInRange(1, 100, "test PDF should have reasonable page count");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task ValidateAsync_NullBytes_ThrowsPdfProcessingException()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
byte[]? pdfBytes = null;
|
||||||
|
|
||||||
|
// Act
|
||||||
|
Func<Task> act = async () => await _sut.ValidateAsync(pdfBytes!);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
await act.Should().ThrowAsync<PdfProcessingException>()
|
||||||
|
.WithMessage("*null*", "null input should be rejected");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task ValidateAsync_EmptyBytes_ThrowsPdfProcessingException()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
byte[] pdfBytes = Array.Empty<byte>();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
Func<Task> act = async () => await _sut.ValidateAsync(pdfBytes);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
await act.Should().ThrowAsync<PdfProcessingException>()
|
||||||
|
.WithMessage("*empty*", "empty input should be rejected");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task ValidateAsync_CorruptedPdf_ThrowsPdfProcessingException()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
byte[] pdfBytes = "This is not a valid PDF content"u8.ToArray();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
Func<Task> act = async () => await _sut.ValidateAsync(pdfBytes);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
await act.Should().ThrowAsync<PdfProcessingException>()
|
||||||
|
.WithMessage("*invalid*", "corrupted PDF should throw exception");
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Metadata Tests
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task ValidateAsync_ValidPdf_FileSizeMBCalculatedCorrectly()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
byte[] pdfBytes = LoadTestPdf("valid.pdf");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var metadata = await _sut.ValidateAsync(pdfBytes);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
double expectedSizeMB = pdfBytes.Length / 1024.0 / 1024.0;
|
||||||
|
metadata.FileSizeMB.Should().BeApproximately(expectedSizeMB, 0.01,
|
||||||
|
"FileSizeMB should be calculated correctly from bytes");
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
namespace DocumentOperator.Tests
|
|
||||||
{
|
|
||||||
public class UnitTest1
|
|
||||||
{
|
|
||||||
[Fact]
|
|
||||||
public void Test1()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user