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:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user