Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 6 additions & 20 deletions Paperless.TestSupport/TestPdf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,14 @@
namespace Paperless.TestSupport;

/// <summary>
/// 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
/// (<c>SaveAsync</c> writes under the project's <c>output/</c> 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. <c>ToBytesAsync</c>/<c>SaveAsync(Stream)</c>), 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 <see cref="Document.ToBytesAsync" /> (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.
/// </summary>
public static class TestPdf
{
/// <summary>Renders <paramref name="content" /> (black text on white) to a PDF and returns its bytes.</summary>
public static async Task<byte[]> 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<byte[]> BytesAsync(string content) =>
Pdf.Create(Dye.White).AddText(content).ToBytesAsync();
}
2 changes: 1 addition & 1 deletion Version.props
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<TestcontainersVersion>4.11.0</TestcontainersVersion>

<!-- Domain libraries -->
<CreatePdfNETVersion>3.0.4</CreatePdfNETVersion>
<CreatePdfNETVersion>3.0.5</CreatePdfNETVersion>
<DotNetEnvVersion>3.2.0</DotNetEnvVersion>
<ElasticClientsElasticsearchVersion>9.4.0</ElasticClientsElasticsearchVersion>
<ErrorOrXVersion>5.3.0</ErrorOrXVersion>
Expand Down
Loading