feat(Fake): add extension method to Fake to create Envelope

This commit is contained in:
tekh 2025-09-02 15:25:59 +02:00
parent a87a524271
commit 6cdd1db7a9
2 changed files with 27 additions and 5 deletions

View File

@ -5,7 +5,6 @@ using EnvelopeGenerator.Application;
using EnvelopeGenerator.Application.EnvelopeReceivers.Commands; using EnvelopeGenerator.Application.EnvelopeReceivers.Commands;
using EnvelopeGenerator.Application.Envelopes.Commands; using EnvelopeGenerator.Application.Envelopes.Commands;
using EnvelopeGenerator.Application.Histories.Commands; using EnvelopeGenerator.Application.Histories.Commands;
using EnvelopeGenerator.Application.Model;
using EnvelopeGenerator.Application.Receivers.Commands; using EnvelopeGenerator.Application.Receivers.Commands;
using EnvelopeGenerator.Application.Users.Commands; using EnvelopeGenerator.Application.Users.Commands;
using EnvelopeGenerator.Infrastructure; using EnvelopeGenerator.Infrastructure;
@ -16,8 +15,8 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using QuestPDF.Fluent; using QuestPDF.Fluent;
using QuestPDF.Infrastructure; using QuestPDF.Infrastructure;
using EnvelopeGenerator.Domain;
using EnvelopeGenerator.Domain.Constants; using EnvelopeGenerator.Domain.Constants;
using EnvelopeGenerator.Domain.Entities;
namespace EnvelopeGenerator.Tests.Application; namespace EnvelopeGenerator.Tests.Application;
@ -164,10 +163,29 @@ public static class Extensions
=> Enumerable.Range(0, userIDs.Length) => Enumerable.Range(0, userIDs.Length)
.Select(fake.CreateEnvelopeCommand) .Select(fake.CreateEnvelopeCommand)
.ToList(); .ToList();
public static Envelope CreateEnvelope(this Faker faker, int userId, bool tfaEnabled = false) => new()
{
Id = faker.Random.Number(1, 1000),
UserId = userId,
Status = EnvelopeStatus.EnvelopeCreated,
Uuid = Guid.NewGuid().ToString(),
Title = faker.Lorem.Paragraph(faker.Random.Number(1, 2)),
Message = faker.Lorem.Paragraph(faker.Random.Number(2, 5)),
TfaEnabled = tfaEnabled,
AddedWhen = DateTime.UtcNow,
CertificationType = (int)CertificationType.AdvancedElectronicSignature,
UseAccessCode = false,
ContractType = (int)ContractType.Contract,
Language = "de",
SendReminderEmails = false,
Comment = faker.Lorem.Sentence(10),
DocResult = faker.CreatePdfAsByte()
};
#endregion #endregion
#region Document #region Document
public static string CreatePdfAsBase64(this Faker faker) public static byte[] CreatePdfAsByte(this Faker faker)
{ {
string name = faker.Name.FullName(); string name = faker.Name.FullName();
string address = faker.Address.FullAddress(); string address = faker.Address.FullAddress();
@ -191,9 +209,11 @@ public static class Extensions
using var ms = new MemoryStream(); using var ms = new MemoryStream();
document.GeneratePdf(ms); document.GeneratePdf(ms);
return Convert.ToBase64String(ms.ToArray()); return ms.ToArray();
} }
public static string CreatePdfAsBase64(this Faker faker) => Convert.ToBase64String(faker.CreatePdfAsByte());
public static DocumentCreateCommand CreateDocumentCommand(this Faker faker) => new() public static DocumentCreateCommand CreateDocumentCommand(this Faker faker) => new()
{ {
DataAsBase64 = faker.CreatePdfAsBase64() DataAsBase64 = faker.CreatePdfAsBase64()

View File

@ -1,7 +1,7 @@
using Bogus; using Bogus;
using DigitalData.UserManager.Domain.Entities; using DigitalData.UserManager.Domain.Entities;
using EnvelopeGenerator.Application.Envelopes.Commands; using EnvelopeGenerator.Application.Envelopes.Commands;
using EnvelopeGenerator.Application.Receivers.Commands; using EnvelopeGenerator.Domain.Entities;
using MediatR; using MediatR;
namespace EnvelopeGenerator.Tests.Application; namespace EnvelopeGenerator.Tests.Application;
@ -16,6 +16,8 @@ public class TestBase : Faker
public CreateEnvelopeCommand FakeCreateEnvelopeCommand => this.CreateEnvelopeCommand(Host.User.Id); public CreateEnvelopeCommand FakeCreateEnvelopeCommand => this.CreateEnvelopeCommand(Host.User.Id);
public Envelope FakeEnvelope => this.CreateEnvelope(Host.User.Id);
[SetUp] [SetUp]
public virtual async Task Setup() public virtual async Task Setup()
{ {