From 145a2ebe8fbfa14182245156e96dbfa5659002ba Mon Sep 17 00:00:00 2001 From: TekH Date: Fri, 29 Aug 2025 16:11:14 +0200 Subject: [PATCH] feat(Extensions): add PDF generation support for EnvelopeGenerator tests - Introduced QuestPDF dependency to generate PDF documents in tests. - Added `CreatePdfAsBase64` extension method for generating random PDF content. - Added `CreateDocumentCommand` and `CreateDocumentCommands` helpers for creating document test data. - Refactored using statements and added `EnvelopeGenerator.Application.EnvelopeReceivers.Commands`. - Maintains existing sample user and receiver setup for integration testing. --- .../EnvelopeGenerator.Infrastructure.csproj | 1 + EnvelopeGenerator.Tests.Application/Fake.cs | 42 +++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/EnvelopeGenerator.Infrastructure/EnvelopeGenerator.Infrastructure.csproj b/EnvelopeGenerator.Infrastructure/EnvelopeGenerator.Infrastructure.csproj index c03a5d99..9be5c881 100644 --- a/EnvelopeGenerator.Infrastructure/EnvelopeGenerator.Infrastructure.csproj +++ b/EnvelopeGenerator.Infrastructure/EnvelopeGenerator.Infrastructure.csproj @@ -12,6 +12,7 @@ + diff --git a/EnvelopeGenerator.Tests.Application/Fake.cs b/EnvelopeGenerator.Tests.Application/Fake.cs index fc8223e7..e1aa9627 100644 --- a/EnvelopeGenerator.Tests.Application/Fake.cs +++ b/EnvelopeGenerator.Tests.Application/Fake.cs @@ -2,6 +2,7 @@ using DigitalData.Core.Abstraction.Application.Repository; using DigitalData.UserManager.Domain.Entities; using EnvelopeGenerator.Application; +using EnvelopeGenerator.Application.EnvelopeReceivers.Commands; using EnvelopeGenerator.Application.Envelopes.Commands; using EnvelopeGenerator.Application.Receivers.Commands; using EnvelopeGenerator.Application.Users.Commands; @@ -11,6 +12,8 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using QuestPDF.Fluent; +using QuestPDF.Infrastructure; namespace EnvelopeGenerator.Tests.Application; @@ -151,6 +154,45 @@ public static class Extensions .ToList(); #endregion + #region Envelope Document + public static string CreatePdfAsBase64(this Faker faker) + { + string name = faker.Name.FullName(); + string address = faker.Address.FullAddress(); + string lorem = faker.Lorem.Paragraphs(2); + + QuestPDF.Settings.License = LicenseType.Community; + var document = Document.Create(container => + { + container.Page(page => + { + page.Margin(50); + page.Header().Text("Random PDF").FontSize(20).Bold(); + page.Content().Column(col => + { + col.Item().Text($"Vor- und Nachname: {name}"); + col.Item().Text($"Adresse: {address}"); + col.Item().Text(lorem); + }); + }); + }); + + using var ms = new MemoryStream(); + document.GeneratePdf(ms); + return Convert.ToBase64String(ms.ToArray()); + } + + public static DocumentCreateCommand CreateDocumentCommand(this Faker faker) => new() + { + DataAsBase64 = faker.CreatePdfAsBase64() + }; + + public static List CreateDocumentCommands(this Faker fake, int minCount = 10, int maxCount = 20) + => Enumerable.Range(0, fake.Random.Number(minCount, maxCount)) + .Select(_ => fake.CreateDocumentCommand()) + .ToList(); + #endregion + #region User Command public static CreateUserCommand CreateUserCommand(this Faker fake) => new() {