using System.Reflection; using HrynCo.NotificationService.DAL.Abstract.Providers; using HrynCo.NotificationService.Services.Core; using HrynCo.NotificationService.Services.EmailChannels.Get; using HrynCo.NotificationService.Services.EmailChannels.TestSmtp; using MediatR; using ServiceUnit = HrynCo.NotificationService.Services.Core.Unit; namespace HrynCo.NotificationService.Web.IntegrationTests; public class RecordingAdminSmtpMediator : DispatchProxy { public EmailChannel? Channel { get; set; } public TestSmtpCommand? SentCommand { get; private set; } public int LookupCount { get; private set; } protected override object Invoke(MethodInfo? targetMethod, object?[]? args) { if (targetMethod?.Name != nameof(IMediator.Send) || args?.Length is null or 0) throw new NotSupportedException(); return args[0] switch { GetEmailChannelQuery => RecordLookup(), TestSmtpCommand command => RecordSend(command), _ => throw new NotSupportedException() }; } private Task> RecordLookup() { LookupCount++; return Task.FromResult(Channel is null ? ServiceResult.Failure("Channel not found.") : ServiceResult.Success(Channel)); } private Task> RecordSend(TestSmtpCommand command) { SentCommand = command; return Task.FromResult(ServiceResult.Success(ServiceUnit.Value)); } }