Compare commits
18 Commits
87d7262d0a
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
64be11f7ad | ||
|
|
b88f011701 | ||
|
|
b8c9e1b6a6 | ||
|
|
09cc64eff0 | ||
|
|
867e0b2655 | ||
|
|
fc79665241 | ||
|
|
196f6d9cfb | ||
|
|
498b6758bf | ||
|
|
49d1f43822 | ||
|
|
3a87ace144 | ||
|
|
cdb942210c | ||
|
|
9512913866 | ||
|
|
758d32d8e0 | ||
|
|
d7c416256c | ||
|
|
5d3ec27128 | ||
|
|
d5fc0c2e51 | ||
|
|
7272b26105 | ||
|
|
d8f3143c8a |
@@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
@@ -10,6 +10,8 @@
|
||||
<PackageReference Include="Asp.Versioning.Http" Version="8.1.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="8.0.28" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="10.0.0" />
|
||||
<PackageReference Include="Serilog.Enrichers.Environment" Version="3.0.1" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="7.0.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -1,25 +1,72 @@
|
||||
using Serilog;
|
||||
using DocumentOperator.Infrastructure.Configuration;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
// ========================================
|
||||
// 1. Serilog Configuration
|
||||
// ========================================
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.ReadFrom.Configuration(builder.Configuration)
|
||||
.Enrich.FromLogContext()
|
||||
.Enrich.WithProperty("Application", "DocumentOperator")
|
||||
.CreateLogger();
|
||||
|
||||
builder.Host.UseSerilog();
|
||||
|
||||
Log.Information("Starting DocumentOperator API...");
|
||||
|
||||
try
|
||||
{
|
||||
// ========================================
|
||||
// 2. Options Pattern Configuration
|
||||
// ========================================
|
||||
builder.Services.Configure<DocumentOperatorSettings>(
|
||||
builder.Configuration.GetSection(DocumentOperatorSettings.SectionName));
|
||||
|
||||
builder.Services.Configure<RedisSettings>(
|
||||
builder.Configuration.GetSection(RedisSettings.SectionName));
|
||||
|
||||
builder.Services.Configure<ApiKeySettings>(
|
||||
builder.Configuration.GetSection(ApiKeySettings.SectionName));
|
||||
|
||||
// ========================================
|
||||
// 3. Services
|
||||
// ========================================
|
||||
builder.Services.AddControllers();
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
|
||||
// ========================================
|
||||
// 4. Build App
|
||||
// ========================================
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
// ========================================
|
||||
// 5. Middleware Pipeline
|
||||
// ========================================
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
}
|
||||
|
||||
app.UseSerilogRequestLogging(); // Log HTTP Requests
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
Log.Information("DocumentOperator API started successfully");
|
||||
|
||||
app.Run();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Fatal(ex, "Application startup failed");
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
Log.CloseAndFlush();
|
||||
}
|
||||
1494
DocumentOperator.API/ROADMAP.md
Normal file
1494
DocumentOperator.API/ROADMAP.md
Normal file
File diff suppressed because it is too large
Load Diff
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)
|
||||
@@ -0,0 +1,16 @@
|
||||
using DocumentOperator.Domain.Models.ValueObjects;
|
||||
|
||||
namespace DocumentOperator.Application.Common.Interfaces;
|
||||
|
||||
public interface IPdfProcessor
|
||||
{
|
||||
/// <summary>
|
||||
/// Validates a PDF and extracts metadata.
|
||||
/// </summary>
|
||||
/// <param name="pdfBytes">PDF content as byte array</param>
|
||||
/// <returns>PDF metadata (page count, size, version, attachments)</returns>
|
||||
/// <exception cref="Domain.Common.Exceptions.PdfProcessingException">
|
||||
/// Thrown when PDF is corrupted or cannot be processed
|
||||
/// </exception>
|
||||
Task<PdfMetadata> ValidateAsync(byte[] pdfBytes);
|
||||
}
|
||||
@@ -7,7 +7,6 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Ardalis.Result" Version="10.1.0" />
|
||||
<PackageReference Include="FluentValidation" Version="12.1.1" />
|
||||
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="12.1.1" />
|
||||
<PackageReference Include="MediatR" Version="14.1.0" />
|
||||
@@ -18,7 +17,6 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Common\Interfaces\" />
|
||||
<Folder Include="Common\Behaviors\" />
|
||||
<Folder Include="Common\DTOs\" />
|
||||
<Folder Include="Common\Mappings\" />
|
||||
|
||||
@@ -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
|
||||
{
|
||||
}
|
||||
}
|
||||
25
DocumentOperator.Domain/Common/Exceptions/DomainException.cs
Normal file
25
DocumentOperator.Domain/Common/Exceptions/DomainException.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
namespace DocumentOperator.Domain.Common.Exceptions;
|
||||
|
||||
/// <summary>
|
||||
/// Base exception for all domain-related exceptions.
|
||||
/// Caught by the Exception Handling Middleware in the API layer.
|
||||
/// </summary>
|
||||
public abstract class DomainException : Exception
|
||||
{
|
||||
/// <summary>
|
||||
/// Error code for categorization and logging.
|
||||
/// </summary>
|
||||
public string ErrorCode { get; }
|
||||
|
||||
protected DomainException(string message, string errorCode)
|
||||
: base(message)
|
||||
{
|
||||
ErrorCode = errorCode;
|
||||
}
|
||||
|
||||
protected DomainException(string message, string errorCode, Exception innerException)
|
||||
: base(message, innerException)
|
||||
{
|
||||
ErrorCode = errorCode;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
namespace DocumentOperator.Domain.Common.Exceptions;
|
||||
|
||||
/// <summary>
|
||||
/// Exception thrown when domain validation fails (e.g., invalid Value Objects).
|
||||
/// Maps to HTTP 400 Bad Request in the API layer.
|
||||
/// </summary>
|
||||
public class DomainValidationException : DomainException
|
||||
{
|
||||
public string PropertyName { get; }
|
||||
|
||||
public DomainValidationException(string message)
|
||||
: base(message, "DOMAIN_VALIDATION_ERROR")
|
||||
{
|
||||
PropertyName = string.Empty;
|
||||
}
|
||||
|
||||
public DomainValidationException(string propertyName, string message)
|
||||
: base(message, "DOMAIN_VALIDATION_ERROR")
|
||||
{
|
||||
PropertyName = propertyName;
|
||||
}
|
||||
|
||||
public DomainValidationException(string message, Exception innerException)
|
||||
: base(message, "DOMAIN_VALIDATION_ERROR", innerException)
|
||||
{
|
||||
PropertyName = string.Empty;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
namespace DocumentOperator.Domain.Common.Exceptions;
|
||||
|
||||
/// <summary>
|
||||
/// Exception thrown when a requested resource is not found.
|
||||
/// Maps to HTTP 404 Not Found in the API layer.
|
||||
/// </summary>
|
||||
public class NotFoundException : DomainException
|
||||
{
|
||||
public string ResourceType { get; }
|
||||
public object ResourceId { get; }
|
||||
|
||||
public NotFoundException(string resourceType, object resourceId)
|
||||
: base($"{resourceType} with ID '{resourceId}' was not found.", "RESOURCE_NOT_FOUND")
|
||||
{
|
||||
ResourceType = resourceType;
|
||||
ResourceId = resourceId;
|
||||
}
|
||||
|
||||
public NotFoundException(string resourceType, object resourceId, string customMessage)
|
||||
: base(customMessage, "RESOURCE_NOT_FOUND")
|
||||
{
|
||||
ResourceType = resourceType;
|
||||
ResourceId = resourceId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
namespace DocumentOperator.Domain.Common.Exceptions;
|
||||
|
||||
/// <summary>
|
||||
/// Exception thrown when PDF processing operations fail.
|
||||
/// Maps to HTTP 500 Internal Server Error or 422 Unprocessable Entity in the API layer.
|
||||
/// </summary>
|
||||
public class PdfProcessingException : DomainException
|
||||
{
|
||||
public string Operation { get; }
|
||||
|
||||
public PdfProcessingException(string operation, string message)
|
||||
: base($"PDF processing failed during '{operation}': {message}", "PDF_PROCESSING_ERROR")
|
||||
{
|
||||
Operation = operation;
|
||||
}
|
||||
|
||||
public PdfProcessingException(string operation, string message, Exception innerException)
|
||||
: base($"PDF processing failed during '{operation}': {message}", "PDF_PROCESSING_ERROR", innerException)
|
||||
{
|
||||
Operation = operation;
|
||||
}
|
||||
|
||||
public PdfProcessingException(string message)
|
||||
: base(message, "PDF_PROCESSING_ERROR")
|
||||
{
|
||||
Operation = "Unknown";
|
||||
}
|
||||
|
||||
public PdfProcessingException(string message, Exception innerException)
|
||||
: base(message, "PDF_PROCESSING_ERROR", innerException)
|
||||
{
|
||||
Operation = "Unknown";
|
||||
}
|
||||
}
|
||||
@@ -7,11 +7,8 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Common\Exceptions\" />
|
||||
<Folder Include="Common\Results\" />
|
||||
<Folder Include="Constants\" />
|
||||
<Folder Include="Models\Enums\" />
|
||||
<Folder Include="Models\ValueObjects\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace DocumentOperator.Domain.Models.Enums;
|
||||
|
||||
public enum DocumentOperationType
|
||||
{
|
||||
Validate,
|
||||
ExtractAttachments,
|
||||
Concatenate,
|
||||
ApplyStamp,
|
||||
EmbedCertificate
|
||||
}
|
||||
9
DocumentOperator.Domain/Models/Enums/ProcessingStatus.cs
Normal file
9
DocumentOperator.Domain/Models/Enums/ProcessingStatus.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace DocumentOperator.Domain.Models.Enums;
|
||||
|
||||
public enum ProcessingStatus
|
||||
{
|
||||
Pending,
|
||||
Processing,
|
||||
Success,
|
||||
Failed
|
||||
}
|
||||
59
DocumentOperator.Domain/Models/ValueObjects/Base64String.cs
Normal file
59
DocumentOperator.Domain/Models/ValueObjects/Base64String.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
namespace DocumentOperator.Domain.Models.ValueObjects;
|
||||
|
||||
public sealed class Base64String
|
||||
{
|
||||
public string Value { get; }
|
||||
|
||||
private Base64String(string value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public static Base64String Create(string value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
throw new Common.Exceptions.DomainValidationException("Base64 string cannot be empty.");
|
||||
|
||||
// Validierung: Ist es gültiges Base64?
|
||||
try
|
||||
{
|
||||
Convert.FromBase64String(value);
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
throw new Common.Exceptions.DomainValidationException("Invalid Base64 format.");
|
||||
}
|
||||
|
||||
return new Base64String(value);
|
||||
}
|
||||
|
||||
public static Base64String FromByteArray(byte[] bytes)
|
||||
{
|
||||
if (bytes == null || bytes.Length == 0)
|
||||
throw new Common.Exceptions.DomainValidationException("Byte array cannot be null or empty.");
|
||||
|
||||
var base64 = Convert.ToBase64String(bytes);
|
||||
return new Base64String(base64);
|
||||
}
|
||||
|
||||
public byte[] ToByteArray()
|
||||
{
|
||||
return Convert.FromBase64String(Value);
|
||||
}
|
||||
|
||||
public override string ToString() => Value;
|
||||
|
||||
// Equality (wichtig für Value Objects!)
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
if (obj is not Base64String other)
|
||||
return false;
|
||||
|
||||
return Value == other.Value;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Value.GetHashCode();
|
||||
}
|
||||
}
|
||||
32
DocumentOperator.Domain/Models/ValueObjects/PdfMetadata.cs
Normal file
32
DocumentOperator.Domain/Models/ValueObjects/PdfMetadata.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
namespace DocumentOperator.Domain.Models.ValueObjects;
|
||||
|
||||
public sealed class PdfMetadata
|
||||
{
|
||||
public int PageCount { get; }
|
||||
public long FileSizeBytes { get; }
|
||||
public string PdfVersion { get; }
|
||||
public bool HasAttachments { get; }
|
||||
public int AttachmentCount { get; }
|
||||
|
||||
// Computed Property (berechnet aus FileSizeBytes)
|
||||
public double FileSizeMB => FileSizeBytes / 1024.0 / 1024.0;
|
||||
|
||||
public PdfMetadata(
|
||||
int pageCount,
|
||||
long fileSizeBytes,
|
||||
string pdfVersion,
|
||||
bool hasAttachments,
|
||||
int attachmentCount)
|
||||
{
|
||||
PageCount = pageCount;
|
||||
FileSizeBytes = fileSizeBytes;
|
||||
PdfVersion = pdfVersion;
|
||||
HasAttachments = hasAttachments;
|
||||
AttachmentCount = attachmentCount;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"PDF: {PageCount} pages, {FileSizeMB:F2} MB, Version {PdfVersion}, Attachments: {AttachmentCount}";
|
||||
}
|
||||
}
|
||||
41
DocumentOperator.Domain/Models/ValueObjects/TenantId.cs
Normal file
41
DocumentOperator.Domain/Models/ValueObjects/TenantId.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
namespace DocumentOperator.Domain.Models.ValueObjects;
|
||||
|
||||
public sealed class TenantId
|
||||
{
|
||||
public string Value { get; }
|
||||
|
||||
private TenantId(string value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public static TenantId Create(string value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
throw new Common.Exceptions.DomainValidationException("TenantId cannot be empty.");
|
||||
|
||||
if (value.Length > 100)
|
||||
throw new Common.Exceptions.DomainValidationException("TenantId cannot exceed 100 characters.");
|
||||
|
||||
// Normalisierung: Lowercase
|
||||
var normalized = value.Trim().ToLowerInvariant();
|
||||
|
||||
return new TenantId(normalized);
|
||||
}
|
||||
|
||||
public override string ToString() => Value;
|
||||
|
||||
// Equality
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
if (obj is not TenantId other)
|
||||
return false;
|
||||
|
||||
return Value == other.Value;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Value.GetHashCode();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace DocumentOperator.Infrastructure.Configuration;
|
||||
|
||||
public class ApiKeySettings
|
||||
{
|
||||
public const string SectionName = "ApiKeySettings";
|
||||
|
||||
public bool EnableValidation { get; set; } = true;
|
||||
public Dictionary<string, TenantInfo> Keys { get; set; } = new();
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace DocumentOperator.Infrastructure.Configuration;
|
||||
|
||||
public class DocumentOperatorSettings
|
||||
{
|
||||
public const string SectionName = "DocumentOperatorSettings";
|
||||
|
||||
public string TempFolderPath { get; set; } = string.Empty;
|
||||
public int TempFileRetentionHours { get; set; }
|
||||
public int MaxPdfSizeMB { get; set; }
|
||||
public bool EnableDetailedLogging { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace DocumentOperator.Infrastructure.Configuration;
|
||||
|
||||
public class RedisSettings
|
||||
{
|
||||
public const string SectionName = "RedisSettings";
|
||||
|
||||
public string ConnectionString { get; set; } = "localhost:6379";
|
||||
public string InstanceName { get; set; } = "DocumentOperator:";
|
||||
public int CacheExpirationMinutes { get; set; } = 60;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace DocumentOperator.Infrastructure.Configuration;
|
||||
|
||||
public class TenantInfo
|
||||
{
|
||||
public string TenantId { get; set; } = string.Empty;
|
||||
public string TenantName { get; set; } = string.Empty;
|
||||
public bool IsActive { get; set; } = true;
|
||||
}
|
||||
@@ -17,7 +17,6 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Configuration\" />
|
||||
<Folder Include="DependencyInjection\" />
|
||||
<Folder Include="Services\FileStorage\" />
|
||||
<Folder Include="Services\DocumentValidation\" />
|
||||
|
||||
42
DocumentOperator.Tests/DocumentOperator.Tests.csproj
Normal file
42
DocumentOperator.Tests/DocumentOperator.Tests.csproj
Normal file
@@ -0,0 +1,42 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="TestData\Pdfs\valid.pdf" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="TestData\Pdfs\valid.pdf" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.0" />
|
||||
<PackageReference Include="FluentAssertions" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
|
||||
<PackageReference Include="Moq" Version="4.20.72" />
|
||||
<PackageReference Include="xunit" Version="2.9.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="Xunit" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\DocumentOperator.Domain\DocumentOperator.Domain.csproj" />
|
||||
<ProjectReference Include="..\DocumentOperator.Application\DocumentOperator.Application.csproj" />
|
||||
<ProjectReference Include="..\DocumentOperator.Infrastructure\DocumentOperator.Infrastructure.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
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
|
||||
}
|
||||
@@ -11,6 +11,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DocumentOperator.Infrastruc
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DocumentOperator.Domain", "DocumentOperator.Domain\DocumentOperator.Domain.csproj", "{B4C1C3ED-D3E8-4272-8704-2E73CEA6A0DD}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DocumentOperator.Tests", "DocumentOperator.Tests\DocumentOperator.Tests.csproj", "{32D2E997-3DA7-4061-8A50-DBB34BBC3E5A}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -33,6 +35,10 @@ Global
|
||||
{B4C1C3ED-D3E8-4272-8704-2E73CEA6A0DD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B4C1C3ED-D3E8-4272-8704-2E73CEA6A0DD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B4C1C3ED-D3E8-4272-8704-2E73CEA6A0DD}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{32D2E997-3DA7-4061-8A50-DBB34BBC3E5A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{32D2E997-3DA7-4061-8A50-DBB34BBC3E5A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{32D2E997-3DA7-4061-8A50-DBB34BBC3E5A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{32D2E997-3DA7-4061-8A50-DBB34BBC3E5A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
Reference in New Issue
Block a user