Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Artem Leshchev committed May 29, 2024
1 parent f7e362e commit a3458c6
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 38 deletions.
3 changes: 1 addition & 2 deletions src/Bss.Platform.Notifications/DependencyInjection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ private static IServiceCollection AddEmailSender(
throw new ArgumentException("Test email address is not provided");
}

return services.AddScoped<IEmailSender, TestEmailSender>()
.AddScoped<IRedirectService, RedirectService>();
return services.AddScoped<IEmailSender, EmailSenderTest>();
}

private static IServiceCollection AddMailMessageSenders(this IServiceCollection services, NotificationSenderOptions settings)
Expand Down
8 changes: 0 additions & 8 deletions src/Bss.Platform.Notifications/Interfaces/IRedirectService.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/Bss.Platform.Notifications/Services/EmailSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public async Task<MailMessage> SendAsync(EmailModel emailModel, CancellationToke
await sender.SendAsync(message, token);
}

if (auditService != null)
if (auditService is not null)
{
await auditService.LogAsync(message, token);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,21 @@

namespace Bss.Platform.Notifications.Services;

internal class RedirectService(IOptions<NotificationSenderOptions> settings) : IRedirectService
internal class EmailSenderTest(
IEnumerable<IMailMessageSender> senders,
IOptions<NotificationSenderOptions> settings,
IAuditService? auditService = null)
: EmailSender(senders, auditService)
{
public void Redirect(MailMessage message)
protected override MailMessage Convert(EmailModel model)
{
var message = base.Convert(model);
this.ChangeRecipients(message);

return message;
}

private void ChangeRecipients(MailMessage message)
{
AddRecipientsToBody(message);

Expand All @@ -21,14 +33,6 @@ public void Redirect(MailMessage message)
}
}

private static void ClearRecipients(MailMessage message)
{
message.To.Clear();
message.CC.Clear();
message.Bcc.Clear();
message.ReplyToList.Clear();
}

private static void AddRecipientsToBody(MailMessage message)
{
var originalRecipients =
Expand All @@ -39,4 +43,12 @@ private static void AddRecipientsToBody(MailMessage message)

message.Body = $"{originalRecipients}{message.Body}";
}

private static void ClearRecipients(MailMessage message)
{
message.To.Clear();
message.CC.Clear();
message.Bcc.Clear();
message.ReplyToList.Clear();
}
}
17 changes: 0 additions & 17 deletions src/Bss.Platform.Notifications/Services/TestEmailSender.cs

This file was deleted.

0 comments on commit a3458c6

Please sign in to comment.