From f731e2b467e259a0512b4fdfc4bc781c40493dfd Mon Sep 17 00:00:00 2001 From: ancplua Date: Thu, 4 Jun 2026 14:49:49 +0200 Subject: [PATCH] test: consume CreatePdf.NET 3.0.5 in-memory PDF output Bump CreatePdfNETVersion 3.0.4 -> 3.0.5 and collapse TestPdf.BytesAsync onto Document.ToBytesAsync(), dropping the SaveAsync -> File.ReadAllBytes -> File.Delete round-trip through the project output dir. The shared helper now renders straight to a byte array, so neither integration suite can leak a stray PDF under output/. Co-Authored-By: Claude Opus 4.8 (1M context) --- Paperless.TestSupport/TestPdf.cs | 26 ++++++-------------------- Version.props | 2 +- 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/Paperless.TestSupport/TestPdf.cs b/Paperless.TestSupport/TestPdf.cs index 9a2b559..f611ddc 100644 --- a/Paperless.TestSupport/TestPdf.cs +++ b/Paperless.TestSupport/TestPdf.cs @@ -3,28 +3,14 @@ namespace Paperless.TestSupport; /// -/// Builds a single-line test PDF from a line of text using CreatePdf.NET's fluent builder and -/// returns its bytes, shared by both integration suites. CreatePdf.NET's public output is disk-only -/// (SaveAsync writes under the project's output/ dir and returns the real path), so this -/// saves with a unique name, reads the returned path, then deletes it — neither suite duplicates the -/// round-trip or leaks PDFs. The root fix is an in-memory output on the library itself -/// (e.g. ToBytesAsync/SaveAsync(Stream)), after which this collapses to a single call. +/// Renders a single-line test PDF from a line of text via CreatePdf.NET's fluent builder and returns +/// its bytes in memory — shared by both integration suites so neither duplicates PDF creation. +/// Uses (CreatePdf.NET 3.0.5+), which renders straight to a +/// byte array with no disk round-trip, so there is nothing to clean up or leak. /// public static class TestPdf { /// Renders (black text on white) to a PDF and returns its bytes. - public static async Task BytesAsync(string content) - { - // SaveAsync routes through FileOperations.GetOutputPath (project output dir + a sanitized name), - // so the file rarely lands where a caller-supplied path would suggest — always read the RETURN. - var path = await Pdf.Create(Dye.White).AddText(content).SaveAsync($"paperless-test-{Guid.NewGuid():N}.pdf"); - try - { - return await File.ReadAllBytesAsync(path); - } - finally - { - File.Delete(path); - } - } + public static Task BytesAsync(string content) => + Pdf.Create(Dye.White).AddText(content).ToBytesAsync(); } diff --git a/Version.props b/Version.props index a251d5c..e81c272 100644 --- a/Version.props +++ b/Version.props @@ -38,7 +38,7 @@ 4.11.0 - 3.0.4 + 3.0.5 3.2.0 9.4.0 5.3.0