test(live): add live API integration test project (DocumentService.Tests.Live)
End-to-end tests that run against a real, deployed API instance to verify that
all controllers respond correctly over HTTP - bypassing WebApplicationFactory.
Project setup:
- Targets net8.0; xUnit 2.9.3 + FluentAssertions 7.0.0
- References DocumentService.Client, Application and Domain as project refs
- Embeds 4 test PDFs as EmbeddedResources:
valid.pdf, pdfWithSwissQRCode.pdf, pdfWithMoreThanOneAttachment.pdf,
encryptedPdf.pdf
LiveApiTestBase:
- Base URL defaults to http://172.24.12.39:9393, overridable via
LIVE_API_BASE_URL env var
- Constructs typed clients (PdfValidationClient, PdfAttachmentClient,
PdfOperationsClient, SwissQrCodeClient) backed by a single HttpClient
- LoadPdfBytes / LoadPdfStream helpers for EmbeddedResource access
Test coverage per file:
- PdfValidationLiveTests : Stream + byte[] overloads for validate and
validate-pdfa; empty/corrupted inputs assert 4xx/5xx
- PdfAttachmentLiveTests : check + extract endpoints; stream and byte[] variants
- PdfOperationsLiveTests : merge and stamp endpoints
- SwissQrCodeLiveTests : extract Swiss QR bill; invalid content asserts error
Tests are intentionally skipped in CI (no live server); run manually with
the LIVE_API_BASE_URL variable pointing to a running instance.
This commit is contained in:
64
DocumentService.Tests.Live/LiveApiTestBase.cs
Normal file
64
DocumentService.Tests.Live/LiveApiTestBase.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using DocumentService.Client.Clients;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using System.Reflection;
|
||||
|
||||
namespace DocumentService.Tests.Live;
|
||||
|
||||
/// <summary>
|
||||
/// Shared base for all live API tests.
|
||||
/// Uses the typed DocumentService.Client classes — no hardcoded routes.
|
||||
///
|
||||
/// Live API: http://172.24.12.39:9393/
|
||||
/// Override via LIVE_API_BASE_URL environment variable if needed.
|
||||
/// </summary>
|
||||
public abstract class LiveApiTestBase : IDisposable
|
||||
{
|
||||
public static readonly string BaseUrl =
|
||||
Environment.GetEnvironmentVariable("LIVE_API_BASE_URL")
|
||||
?? "http://172.24.12.39:9393";
|
||||
|
||||
protected readonly HttpClient HttpClient;
|
||||
|
||||
// Typed clients (route-free — routes live inside the client implementations)
|
||||
protected readonly PdfValidationClient ValidationClient;
|
||||
protected readonly PdfAttachmentClient AttachmentClient;
|
||||
protected readonly PdfOperationsClient OperationsClient;
|
||||
protected readonly SwissQrCodeClient QrCodeClient;
|
||||
|
||||
protected LiveApiTestBase()
|
||||
{
|
||||
HttpClient = new HttpClient { BaseAddress = new Uri(BaseUrl) };
|
||||
|
||||
ValidationClient = new PdfValidationClient(HttpClient, NullLogger<PdfValidationClient>.Instance);
|
||||
AttachmentClient = new PdfAttachmentClient(HttpClient, NullLogger<PdfAttachmentClient>.Instance);
|
||||
OperationsClient = new PdfOperationsClient(HttpClient, NullLogger<PdfOperationsClient>.Instance);
|
||||
QrCodeClient = new SwissQrCodeClient(HttpClient, NullLogger<SwissQrCodeClient>.Instance);
|
||||
}
|
||||
|
||||
// ──────────────────────────────────────────────────────────────
|
||||
// Embedded-resource helpers
|
||||
// ──────────────────────────────────────────────────────────────
|
||||
|
||||
protected static byte[] LoadPdfBytes(string fileName)
|
||||
{
|
||||
var assembly = Assembly.GetExecutingAssembly();
|
||||
var resourceName = $"DocumentService.Tests.Live.TestData.Pdfs.{fileName}";
|
||||
|
||||
using var stream = assembly.GetManifestResourceStream(resourceName)
|
||||
?? throw new FileNotFoundException(
|
||||
$"Embedded resource not found: '{resourceName}'. " +
|
||||
$"Available: {string.Join(", ", assembly.GetManifestResourceNames())}");
|
||||
|
||||
using var ms = new MemoryStream();
|
||||
stream.CopyTo(ms);
|
||||
return ms.ToArray();
|
||||
}
|
||||
|
||||
protected static Stream LoadPdfStream(string fileName)
|
||||
{
|
||||
var bytes = LoadPdfBytes(fileName);
|
||||
return new MemoryStream(bytes);
|
||||
}
|
||||
|
||||
public void Dispose() => HttpClient.Dispose();
|
||||
}
|
||||
Reference in New Issue
Block a user