Refactor DTOs and tests; add framework-specific handling

Refactored the codebase to use shared DTOs from `DocumentService.Application.Common.DTOs`, removing inline DTO definitions in client interfaces and tests. Introduced conditional compilation to handle framework-specific differences in DTOs and handlers.

Updated test cases to align with the new DTO structures, including `SwissQrCodeExtractionResult`, `PdfValidationResult`, and `ZugferdExtractionResult`. Adjusted test data to match updated DTO properties.

Cleaned up solution and project files, ensuring proper references and organization. Removed unused files and fixed project references in `DocumentService.Tests.csproj`. Improved maintainability and consistency across the codebase.
This commit is contained in:
2026-08-31 00:54:38 +02:00
parent 108e522316
commit 75bea9ef29
18 changed files with 65 additions and 133 deletions

View File

@@ -1,3 +1,4 @@
using DocumentService.Application.Common.DTOs;
using DocumentService.Client.Clients;
using DocumentService.Client.Interfaces;
using DocumentService.Client.Models.Requests;
@@ -63,7 +64,7 @@ public class PdfAttachmentClientTests
{
HasAttachments = true,
AttachmentCount = 1,
Attachments = new List<AttachmentMetadata>
Attachments = new List<AttachmentDto>
{
new() { FileName = "factur-x.xml", MimeType = "application/xml", Size = 512 }
}
@@ -85,7 +86,7 @@ public class PdfAttachmentClientTests
public async Task CheckAttachmentsAsync_Stream_PdfWithNoAttachments_ReturnsFalse()
{
// Arrange
var expected = new AttachmentCheckResult { HasAttachments = false, AttachmentCount = 0 };
var expected = new AttachmentCheckResult { HasAttachments = false, AttachmentCount = 0, Attachments = [] };
var (client, _) = BuildJson(expected);
// Act

View File

@@ -2,6 +2,7 @@ using DocumentService.Client.Clients;
using DocumentService.Client.Interfaces;
using DocumentService.Client.Models.Requests;
using DocumentService.Client.Models.ValueObjects;
using DocumentService.Domain.Models.ValueObjects;
using FluentAssertions;
using Microsoft.Extensions.Logging.Abstractions;
using System.Net;

View File

@@ -1,3 +1,4 @@
using DocumentService.Application.Common.DTOs;
using DocumentService.Client.Clients;
using DocumentService.Client.Interfaces;
using FluentAssertions;
@@ -32,7 +33,7 @@ public class PdfValidationClientTests
[Fact]
public async Task ValidatePdfAsync_Stream_SendsMultipartPost()
{
var expected = new PdfValidationResult { PageCount = 3, PdfVersion = "1.7", FileSizeBytes = 2048, IsEncrypted = false };
var expected = new PdfValidationResult(PageCount: 3, FileSizeBytes: 2048, FileSizeMB: 0, PdfVersion: "1.7", HasAttachments: false, AttachmentCount: 0, IsEncrypted: false);
var (client, handler) = Build(expected);
var result = await client.ValidatePdfAsync(new MemoryStream(FakePdfBytes()));
@@ -49,7 +50,7 @@ public class PdfValidationClientTests
[Fact]
public async Task ValidatePdfAsync_Stream_EncryptedPdf_DeserializesIsEncryptedTrue()
{
var expected = new PdfValidationResult { PageCount = 1, IsEncrypted = true, PdfVersion = "1.6" };
var expected = new PdfValidationResult(PageCount: 1, FileSizeBytes: 0, FileSizeMB: 0, PdfVersion: "1.6", HasAttachments: false, AttachmentCount: 0, IsEncrypted: true);
var (client, _) = Build(expected);
var result = await client.ValidatePdfAsync(new MemoryStream(FakePdfBytes()));
@@ -89,7 +90,7 @@ public class PdfValidationClientTests
[Fact]
public async Task ValidatePdfAsync_Bytes_SendsJsonWithBase64()
{
var expected = new PdfValidationResult { PageCount = 1, IsEncrypted = false, HasAttachments = true, AttachmentCount = 2 };
var expected = new PdfValidationResult(PageCount: 1, FileSizeBytes: 0, FileSizeMB: 0, PdfVersion: "", HasAttachments: true, AttachmentCount: 2, IsEncrypted: false);
var (client, handler) = Build(expected);
var result = await client.ValidatePdfAsync(FakePdfBytes());

View File

@@ -1,3 +1,4 @@
using DocumentService.Application.Common.DTOs;
using DocumentService.Client.Clients;
using DocumentService.Client.Interfaces;
using FluentAssertions;
@@ -14,7 +15,7 @@ namespace DocumentService.Tests.Unit.Client;
/// </summary>
public class SwissQrCodeClientTests
{
// ?? helpers ?????????????????????????????????????????????????????????????
// ?? helpers ????????????????????????????????????????????????????????????
private static (SwissQrCodeClient client, MockHttpMessageHandler handler) Build<T>(T body)
{
@@ -26,13 +27,23 @@ public class SwissQrCodeClientTests
private static byte[] FakePdfBytes() => "fake-pdf-content"u8.ToArray();
// ?? ExtractSwissQrCodeAsync (Stream) — parsed Bill ???????????????????????
// ?? ExtractSwissQrCodeAsync (Stream) — parsed Bill ??????????????????????
[Fact]
public async Task ExtractSwissQrCodeAsync_Stream_ParsedMode_SendsMultipartToCorrectEndpoint()
{
// Arrange
var expected = new SwissQrCodeExtractionResult { Bill = new { Iban = "CH93-0076-2011-6238-5295-7" } };
var expected = new SwissQrCodeExtractionResult(
Bill: new SwissQrBillDto
{
Version = "V2_0",
Currency = "CHF",
Account = "CH9300762011623852957",
Creditor = new AddressDto { Name = "Test AG", Town = "Bern", CountryCode = "CH", Type = "S", PostalCode = "3000" },
ReferenceType = "NON"
},
RawLines: []
);
var (client, handler) = Build(expected);
// Act
@@ -48,7 +59,7 @@ public class SwissQrCodeClientTests
public async Task ExtractSwissQrCodeAsync_Stream_RawMode_SendsRawFlagInUrl()
{
// Arrange
var expected = new SwissQrCodeExtractionResult { RawLines = new List<string> { "SPC", "0200", "1" } };
var expected = new SwissQrCodeExtractionResult(Bill: null, RawLines: ["SPC", "0200", "1"]);
var (client, handler) = Build(expected);
// Act
@@ -59,13 +70,13 @@ public class SwissQrCodeClientTests
handler.LastRequest!.RequestUri!.PathAndQuery.Should().Be("/api/pdf/qr-code/extract-swiss?raw=True");
}
// ?? ExtractSwissQrCodeAsync (byte[]) ?????????????????????????????????????
// ?? ExtractSwissQrCodeAsync (byte[]) ????????????????????????????????????
[Fact]
public async Task ExtractSwissQrCodeAsync_Bytes_SendsJsonWithBase64()
{
// Arrange
var expected = new SwissQrCodeExtractionResult();
var expected = new SwissQrCodeExtractionResult(Bill: null, RawLines: []);
var (client, handler) = Build(expected);
// Act
@@ -83,7 +94,7 @@ public class SwissQrCodeClientTests
public async Task ExtractSwissQrCodeAsync_Bytes_RawMode_IncludesRawFlagInUrl()
{
// Arrange
var expected = new SwissQrCodeExtractionResult { RawLines = new List<string> { "SPC" } };
var expected = new SwissQrCodeExtractionResult(Bill: null, RawLines: ["SPC"]);
var (client, handler) = Build(expected);
// Act
@@ -93,7 +104,7 @@ public class SwissQrCodeClientTests
handler.LastRequest!.RequestUri!.PathAndQuery.Should().Be("/api/pdf/qr-code/extract-swiss?raw=True");
}
// ?? HTTP error propagation ???????????????????????????????????????????????
// ?? HTTP error propagation ??????????????????????????????????????????????
[Fact]
public async Task ExtractSwissQrCodeAsync_WhenApiReturns404_ThrowsHttpRequestException()

View File

@@ -1,3 +1,5 @@
using DocumentService.Application.Common.DTOs;
using DocumentService.Application.ExtractZugferd;
using DocumentService.Client.Clients;
using DocumentService.Client.Interfaces;
using FluentAssertions;
@@ -41,7 +43,7 @@ public class ZugferdClientTests
public async Task HasZugferdAsync_Stream_WhenZugferdPresent_ReturnsTrue()
{
// Arrange
var expected = new ZugferdCheckResult { HasZugferd = true, Version = "2.1", Profile = "EN 16931" };
var expected = new ZugferdCheckResult { HasZugferd = true, ZugferdFileName = "factur-x.xml" };
var (client, handler) = BuildJson(expected);
// Act
@@ -49,8 +51,6 @@ public class ZugferdClientTests
// Assert
result.HasZugferd.Should().BeTrue();
result.Version.Should().Be("2.1");
result.Profile.Should().Be("EN 16931");
handler.LastRequest!.RequestUri!.PathAndQuery.Should().Be("/api/pdf/zugferd/has-zugferd");
handler.LastRequest.Content.Should().BeOfType<MultipartFormDataContent>();
}
@@ -67,7 +67,7 @@ public class ZugferdClientTests
// Assert
result.HasZugferd.Should().BeFalse();
result.Version.Should().BeNull();
result.ZugferdFileName.Should().BeNull();
}
// ?? HasZugferdAsync (byte[]) ?????????????????????????????????????????????
@@ -149,8 +149,6 @@ public class ZugferdClientTests
{
FileName = "factur-x.xml",
XmlContent = "<invoice/>",
Version = "2.1",
Profile = "EN 16931"
};
var (client, handler) = BuildJson(expected);
@@ -160,7 +158,6 @@ public class ZugferdClientTests
// Assert
result.FileName.Should().Be("factur-x.xml");
result.XmlContent.Should().Be("<invoice/>");
result.Version.Should().Be("2.1");
handler.LastRequest!.RequestUri!.PathAndQuery.Should().Be("/api/pdf/zugferd/extract?asFile=false");
}