Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,7 @@ namespace MessagingService.BusinessLogic.Tests.Mediator

public class DummyMessagingDomainService : IMessagingDomainService
{
public async Task<Result<Guid>> SendEmailMessage(Guid connectionIdentifier,
Guid messageId,
String fromAddress,
List<String> toAddresses,
String subject,
String body,
Boolean isHtml,
public async Task<Result<Guid>> SendEmailMessage(EmailCommands.SendEmailCommand command,
List<EmailAttachment> attachments,
CancellationToken cancellationToken) => Result.Success(Guid.NewGuid());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,7 @@ public async Task MessagingDomainService_SendEmailMessage_MessageSent()
MessagingDomainService messagingDomainService =
new(emailAggregateRepository.Object, smsAggregateRepository.Object, emailServiceProxy.Object, smsServiceProxy.Object);

var result = await messagingDomainService.SendEmailMessage(TestData.ConnectionIdentifier,
TestData.MessageId,
TestData.FromAddress,
TestData.ToAddresses,
TestData.Subject,
TestData.Body,
TestData.IsHtmlTrue,
var result = await messagingDomainService.SendEmailMessage(TestData.SendEmailCommand,
TestData.EmailAttachmentModels,
CancellationToken.None);
result.IsSuccess.ShouldBeTrue();
Expand Down Expand Up @@ -79,13 +73,7 @@ public async Task MessagingDomainService_SendEmailMessage_SecondSend_MessageNotS

MessagingDomainService messagingDomainService = new(emailAggregateRepository.Object, smsAggregateRepository.Object, emailServiceProxy.Object, smsServiceProxy.Object);

var result = await messagingDomainService.SendEmailMessage(TestData.ConnectionIdentifier,
TestData.MessageId,
TestData.FromAddress,
TestData.ToAddresses,
TestData.Subject,
TestData.Body,
TestData.IsHtmlTrue,
var result = await messagingDomainService.SendEmailMessage(TestData.SendEmailCommand,
TestData.EmailAttachmentModels,
CancellationToken.None);
result.IsSuccess.ShouldBeTrue();
Expand Down Expand Up @@ -113,13 +101,7 @@ [Fact] public async Task MessagingDomainService_SendEmailMessage_SaveFailed_Mess
MessagingDomainService messagingDomainService =
new(emailAggregateRepository.Object, smsAggregateRepository.Object, emailServiceProxy.Object, smsServiceProxy.Object);

await messagingDomainService.SendEmailMessage(TestData.ConnectionIdentifier,
TestData.MessageId,
TestData.FromAddress,
TestData.ToAddresses,
TestData.Subject,
TestData.Body,
TestData.IsHtmlTrue,
await messagingDomainService.SendEmailMessage(TestData.SendEmailCommand,
TestData.EmailAttachmentModels,
CancellationToken.None);
}
Expand All @@ -145,13 +127,7 @@ public async Task MessagingDomainService_SendEmailMessage_EmailSentFailed_APICal
MessagingDomainService messagingDomainService =
new(emailAggregateRepository.Object, smsAggregateRepository.Object, emailServiceProxy.Object, smsServiceProxy.Object);

await messagingDomainService.SendEmailMessage(TestData.ConnectionIdentifier,
TestData.MessageId,
TestData.FromAddress,
TestData.ToAddresses,
TestData.Subject,
TestData.Body,
TestData.IsHtmlTrue,
await messagingDomainService.SendEmailMessage(TestData.SendEmailCommand,
TestData.EmailAttachmentModels,
CancellationToken.None);
}
Expand All @@ -177,13 +153,7 @@ public async Task MessagingDomainService_SendEmailMessage_EmailSentFailed_APIRes
MessagingDomainService messagingDomainService =
new(emailAggregateRepository.Object, smsAggregateRepository.Object, emailServiceProxy.Object, smsServiceProxy.Object);

await messagingDomainService.SendEmailMessage(TestData.ConnectionIdentifier,
TestData.MessageId,
TestData.FromAddress,
TestData.ToAddresses,
TestData.Subject,
TestData.Body,
TestData.IsHtmlTrue,
await messagingDomainService.SendEmailMessage(TestData.SendEmailCommand,
TestData.EmailAttachmentModels,
CancellationToken.None);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,7 @@ public async Task<Result<Guid>> Handle(EmailCommands.SendEmailCommand command,
});
}

return await this.MessagingDomainService.SendEmailMessage(command.ConnectionIdentifier,
command.MessageId,
command.FromAddress,
command.ToAddresses,
command.Subject,
command.Body,
command.IsHtml,
return await this.MessagingDomainService.SendEmailMessage(command,
attachments,
cancellationToken);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,6 @@ public interface IEmailServiceProxy
{
#region Methods

/// <summary>
/// Sends the email.
/// </summary>
/// <param name="messageId">The message identifier.</param>
/// <param name="fromAddress">From address.</param>
/// <param name="toAddresses">To addresses.</param>
/// <param name="subject">The subject.</param>
/// <param name="body">The body.</param>
/// <param name="isHtml">if set to <c>true</c> [is HTML].</param>
/// <param name="attachments">The attachments.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
Task<EmailServiceProxyResponse> SendEmail(Guid messageId,
String fromAddress,
List<String> toAddresses,
Expand All @@ -31,14 +19,6 @@ Task<EmailServiceProxyResponse> SendEmail(Guid messageId,
List<EmailAttachment> attachments,
CancellationToken cancellationToken);

/// <summary>
/// Gets the message status.
/// </summary>
/// <param name="providerReference">The provider reference.</param>
/// <param name="startDate">The start date.</param>
/// <param name="endDate">The end date.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
Task<MessageStatusResponse> GetMessageStatus(String providerReference,
DateTime startDate,
DateTime endDate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,9 @@ public interface IMessagingDomainService
{
#region Methods

Task<Result<Guid>> SendEmailMessage(Guid connectionIdentifier,
Guid messageId,
String fromAddress,
List<String> toAddresses,
String subject,
String body,
Boolean isHtml,
List<EmailAttachment> attachments,
CancellationToken cancellationToken);
Task<Result<Guid>> SendEmailMessage(EmailCommands.SendEmailCommand command,
List<EmailAttachment> attachments,
CancellationToken cancellationToken);

Task<Result<Guid>> SendSMSMessage(Guid connectionIdentifier,
Guid messageId,
Expand Down
20 changes: 7 additions & 13 deletions MessagingService.BusinessLogic/Services/MessagingDomainService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,7 @@
}
}

public async Task<Result<Guid>> SendEmailMessage(Guid connectionIdentifier,
Guid messageId,
String fromAddress,
List<String> toAddresses,
String subject,
String body,
Boolean isHtml,
public async Task<Result<Guid>> SendEmailMessage(EmailCommands.SendEmailCommand command,
List<EmailAttachment> attachments,
CancellationToken cancellationToken) {
Result result = await ApplyEmailUpdates(async (EmailAggregate emailAggregate) =>
Expand All @@ -129,11 +123,11 @@
}

// send message to provider (record event)
emailAggregate.SendRequestToProvider(fromAddress, toAddresses, subject, body, isHtml, attachments);
emailAggregate.SendRequestToProvider(command.FromAddress, command.ToAddresses, command.Subject, command.Body, command.IsHtml, attachments);

// Make call to Email provider here
EmailServiceProxyResponse emailResponse = await this.EmailServiceProxy.SendEmail(messageId, fromAddress,
toAddresses, subject, body, isHtml, attachments, cancellationToken);
EmailServiceProxyResponse emailResponse = await this.EmailServiceProxy.SendEmail(command.MessageId, command.FromAddress,
command.ToAddresses,command.Subject, command.Body, command.IsHtml, attachments, cancellationToken);

if (emailResponse.ApiCallSuccessful)
{
Expand All @@ -147,11 +141,11 @@
}

return Result.Success();
}, messageId, cancellationToken, false);
}, command.MessageId, cancellationToken, false);

if (result.IsFailed)
return result;
return Result.Success(messageId);
return Result.Success(command.MessageId);
}

public async Task<Result<Guid>> SendSMSMessage(Guid connectionIdentifier,
Expand Down Expand Up @@ -194,7 +188,7 @@
Result result = await ApplyEmailUpdates(async (EmailAggregate emailAggregate) => {
// re-send message to provider (record event)
emailAggregate.ResendRequestToProvider();

// Make call to Email provider here
EmailServiceProxyResponse emailResponse =
await this.EmailServiceProxy.SendEmail(messageId, emailAggregate.FromAddress,
Expand Down Expand Up @@ -239,7 +233,7 @@

public async Task<Result> UpdateMessageStatus(EmailCommands.UpdateMessageStatusCommand command,
CancellationToken cancellationToken) {
Result result = await ApplyEmailUpdates(async (EmailAggregate emailAggregate) => {

Check warning on line 236 in MessagingService.BusinessLogic/Services/MessagingDomainService.cs

View workflow job for this annotation

GitHub Actions / Build and Test Pull Requests

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
switch (command.Status) {
case EmailServices.MessageStatus.Bounced:
emailAggregate.MarkMessageAsBounced(command.Description, command.Timestamp);
Expand Down
Loading