Refactored `DocSignedNotification` to remove inheritance from `EnvelopeReceiverDto` and introduced a required `EnvelopeReceiver` property. Updated all usages across the codebase to align with the new structure, including controllers, handlers, and tests. - Improved encapsulation and reduced coupling by making dependencies explicit. - Updated `AnnotationController`, `DocStatusHandler`, `HistoryHandler`, and `SendSignedMailHandler` to use the `EnvelopeReceiver` property. - Adjusted `DocSignedNotificationTests` to reflect the new instantiation pattern. - Updated XML documentation and ensured consistent access to `EnvelopeReceiver` properties like `EnvelopeId`, `ReceiverId`, and `EmailAddress`.
64 lines
2.3 KiB
C#
64 lines
2.3 KiB
C#
using AutoMapper;
|
|
using DigitalData.Core.Abstraction.Application.Repository;
|
|
using DigitalData.Core.Infrastructure;
|
|
using DigitalData.EmailProfilerDispatcher.Abstraction.Entities;
|
|
using EnvelopeGenerator.Application.Common.Dto.EnvelopeReceiver;
|
|
using EnvelopeGenerator.Application.Common.Notifications.DocSigned;
|
|
using EnvelopeGenerator.Application.Common.Notifications.DocSigned.Handlers;
|
|
using EnvelopeGenerator.Domain.Entities;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace EnvelopeGenerator.Tests.Application;
|
|
|
|
public class DocSignedNotificationTests : TestBase
|
|
{
|
|
protected IMapper _mapper;
|
|
|
|
protected override void ConfigureServices(IServiceCollection services)
|
|
{
|
|
services.AddTransient<SendSignedMailHandler>();
|
|
|
|
// overwrite EmailOutRepository
|
|
services.AddDbRepository(opt => opt.RegisterEntity<Fake.EGDbContext2Prod, EmailOut>(ctx => ctx.EMailOuts));
|
|
}
|
|
|
|
public override async Task Setup()
|
|
{
|
|
await base.Setup();
|
|
_mapper = Host.Services.GetRequiredService<IMapper>();
|
|
}
|
|
|
|
[TestCase("h.tek@digitaldata.works", TestName = "SendSignedMailHandler_ShouldNotThrow_WithValidEmail")]
|
|
public async Task SendSignedMailHandler_ShouldNotThrow(string emailAddress)
|
|
{
|
|
/// Assert
|
|
CancellationToken cancel = new();
|
|
var mediator = Mediator;
|
|
|
|
// Create envelope
|
|
var envCmd = this.CreateEnvelopeCommand(User.Id);
|
|
var env = await mediator.Send(envCmd, cancel);
|
|
|
|
// Create receiver
|
|
var rcvCmd = this.CreateReceiverCommand(emailAddress);
|
|
(var rcv, _) = await mediator.Send(rcvCmd, cancel);
|
|
|
|
// Create envelope receiver
|
|
var envRcv = this.CreateEnvelopeReceiver(env!.Id, rcv.Id);
|
|
|
|
var repo = GetRepository<EnvelopeReceiver>();
|
|
|
|
envRcv = await repo.CreateAsync(envRcv, cancel);
|
|
var envRcvDto = _mapper.Map<EnvelopeReceiverDto>(envRcv);
|
|
|
|
var annots = Services.GetRequiredService<PsPdfKitAnnotation>();
|
|
|
|
var docSignedNtf = new DocSignedNotification { EnvelopeReceiver = envRcvDto, PsPdfKitAnnotation = annots };
|
|
|
|
var sendSignedMailHandler = Host.Services.GetRequiredService<SendSignedMailHandler>();
|
|
|
|
// Act + Assert
|
|
Assert.DoesNotThrowAsync(async () => await sendSignedMailHandler.Handle(docSignedNtf, cancel));
|
|
}
|
|
}
|