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 @@ -35,5 +35,8 @@ public async Task ResendEmailMessage(Guid connectionIdentifier,
Guid messageId,
CancellationToken cancellationToken) {
}

public async Task ResendSMSMessage(Guid connectionIdentifier, Guid messageId, CancellationToken cancellationToken){
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,19 @@ public void MessagingRequestHandler_SendSMSRequest_IsHandled()
{
await handler.Handle(command, CancellationToken.None);
});
}

[Fact]
public void MessagingRequestHandler_ResendSMSRequest_IsHandled()
{
Mock<IMessagingDomainService> messagingDomainService = new Mock<IMessagingDomainService>();
MessagingRequestHandler handler = new MessagingRequestHandler(messagingDomainService.Object);

ResendSMSRequest command = TestData.ResendSMSRequest;

Should.NotThrow(async () => {
await handler.Handle(command, CancellationToken.None);
});
}
}
}
9 changes: 9 additions & 0 deletions MessagingService.BusinessLogic.Tests/Requests/RequestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,14 @@ public void ResendEmailRequest_CanBeCreated_IsCreated() {
request.ConnectionIdentifier.ShouldBe(TestData.ConnectionIdentifier);
request.MessageId.ShouldBe(TestData.MessageId);
}

[Fact]
public void ResendSMSRequest_CanBeCreated_IsCreated()
{
ResendSMSRequest request = ResendSMSRequest.Create(TestData.ConnectionIdentifier, TestData.MessageId);
request.ShouldNotBeNull();
request.ConnectionIdentifier.ShouldBe(TestData.ConnectionIdentifier);
request.MessageId.ShouldBe(TestData.MessageId);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,58 @@ await messagingDomainService.ResendEmailMessage(TestData.ConnectionIdentifier,
CancellationToken.None);
}

[Fact]
public async Task MessagingDomainService_ResendEmailMessage_APICallFailed_MessageFailed()
{
Mock<IAggregateRepository<EmailAggregate, DomainEvent>> emailAggregateRepository = new Mock<IAggregateRepository<EmailAggregate, DomainEvent>>();
emailAggregateRepository.Setup(a => a.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.GetSentEmailAggregate);
Mock<IAggregateRepository<SMSAggregate, DomainEvent>> smsAggregateRepository = new Mock<IAggregateRepository<SMSAggregate, DomainEvent>>();
Mock<IEmailServiceProxy> emailServiceProxy = new Mock<IEmailServiceProxy>();
emailServiceProxy
.Setup(e => e.SendEmail(It.IsAny<Guid>(),
It.IsAny<String>(),
It.IsAny<List<String>>(),
It.IsAny<String>(),
It.IsAny<String>(),
It.IsAny<Boolean>(),
It.IsAny<List<EmailAttachment>>(),
It.IsAny<CancellationToken>())).ReturnsAsync(TestData.FailedAPICallEmailServiceProxyResponse);
Mock<ISMSServiceProxy> smsServiceProxy = new Mock<ISMSServiceProxy>();

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

await messagingDomainService.ResendEmailMessage(TestData.ConnectionIdentifier,
TestData.MessageId,
CancellationToken.None);
}

[Fact]
public async Task MessagingDomainService_ResendEmailMessage_APIResponseError_MessageFailed()
{
Mock<IAggregateRepository<EmailAggregate, DomainEvent>> emailAggregateRepository = new Mock<IAggregateRepository<EmailAggregate, DomainEvent>>();
emailAggregateRepository.Setup(a => a.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.GetSentEmailAggregate);
Mock<IAggregateRepository<SMSAggregate, DomainEvent>> smsAggregateRepository = new Mock<IAggregateRepository<SMSAggregate, DomainEvent>>();
Mock<IEmailServiceProxy> emailServiceProxy = new Mock<IEmailServiceProxy>();
emailServiceProxy
.Setup(e => e.SendEmail(It.IsAny<Guid>(),
It.IsAny<String>(),
It.IsAny<List<String>>(),
It.IsAny<String>(),
It.IsAny<String>(),
It.IsAny<Boolean>(),
It.IsAny<List<EmailAttachment>>(),
It.IsAny<CancellationToken>())).ReturnsAsync(TestData.FailedEmailServiceProxyResponse);
Mock<ISMSServiceProxy> smsServiceProxy = new Mock<ISMSServiceProxy>();

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

await messagingDomainService.ResendEmailMessage(TestData.ConnectionIdentifier,
TestData.MessageId,
CancellationToken.None);
}

[Fact]
public async Task MessagingDomainService_SendSMSMessage_MessageSent()
{
Expand All @@ -167,5 +219,71 @@ await messagingDomainService.SendSMSMessage(TestData.ConnectionIdentifier,
CancellationToken.None);
}

[Fact]
public async Task MessagingDomainService_ReSendSMSMessage_MessageSent()
{
Mock<IAggregateRepository<EmailAggregate, DomainEvent>> emailAggregateRepository = new Mock<IAggregateRepository<EmailAggregate, DomainEvent>>();
Mock<IAggregateRepository<SMSAggregate, DomainEvent>> smsAggregateRepository = new Mock<IAggregateRepository<SMSAggregate, DomainEvent>>();
smsAggregateRepository.Setup(a => a.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.GetSentSMSAggregate);
Mock<IEmailServiceProxy> emailServiceProxy = new Mock<IEmailServiceProxy>();
Mock<ISMSServiceProxy> smsServiceProxy = new Mock<ISMSServiceProxy>();
smsServiceProxy
.Setup(e => e.SendSMS(It.IsAny<Guid>(),
It.IsAny<String>(),
It.IsAny<String>(),
It.IsAny<String>(),
It.IsAny<CancellationToken>())).ReturnsAsync(TestData.SuccessfulSMSServiceProxyResponse);
MessagingDomainService messagingDomainService =
new MessagingDomainService(emailAggregateRepository.Object, smsAggregateRepository.Object, emailServiceProxy.Object, smsServiceProxy.Object);

await messagingDomainService.ResendSMSMessage(TestData.ConnectionIdentifier,
TestData.MessageId,
CancellationToken.None);
}

[Fact]
public async Task MessagingDomainService_ReSendSMSMessage_APICallFailed_MessageFailed()
{
Mock<IAggregateRepository<EmailAggregate, DomainEvent>> emailAggregateRepository = new Mock<IAggregateRepository<EmailAggregate, DomainEvent>>();
Mock<IAggregateRepository<SMSAggregate, DomainEvent>> smsAggregateRepository = new Mock<IAggregateRepository<SMSAggregate, DomainEvent>>();
smsAggregateRepository.Setup(a => a.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.GetSentSMSAggregate);
Mock<IEmailServiceProxy> emailServiceProxy = new Mock<IEmailServiceProxy>();
Mock<ISMSServiceProxy> smsServiceProxy = new Mock<ISMSServiceProxy>();
smsServiceProxy
.Setup(e => e.SendSMS(It.IsAny<Guid>(),
It.IsAny<String>(),
It.IsAny<String>(),
It.IsAny<String>(),
It.IsAny<CancellationToken>())).ReturnsAsync(TestData.FailedAPICallSMSServiceProxyResponse);
MessagingDomainService messagingDomainService =
new MessagingDomainService(emailAggregateRepository.Object, smsAggregateRepository.Object, emailServiceProxy.Object, smsServiceProxy.Object);

await messagingDomainService.ResendSMSMessage(TestData.ConnectionIdentifier,
TestData.MessageId,
CancellationToken.None);
}

[Fact]
public async Task MessagingDomainService_ReSendSMSMessage_APIResponseError_MessageFailed()
{
Mock<IAggregateRepository<EmailAggregate, DomainEvent>> emailAggregateRepository = new Mock<IAggregateRepository<EmailAggregate, DomainEvent>>();
Mock<IAggregateRepository<SMSAggregate, DomainEvent>> smsAggregateRepository = new Mock<IAggregateRepository<SMSAggregate, DomainEvent>>();
smsAggregateRepository.Setup(a => a.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.GetSentSMSAggregate);
Mock<IEmailServiceProxy> emailServiceProxy = new Mock<IEmailServiceProxy>();
Mock<ISMSServiceProxy> smsServiceProxy = new Mock<ISMSServiceProxy>();
smsServiceProxy
.Setup(e => e.SendSMS(It.IsAny<Guid>(),
It.IsAny<String>(),
It.IsAny<String>(),
It.IsAny<String>(),
It.IsAny<CancellationToken>())).ReturnsAsync(TestData.FailedSMSServiceProxyResponse);
MessagingDomainService messagingDomainService =
new MessagingDomainService(emailAggregateRepository.Object, smsAggregateRepository.Object, emailServiceProxy.Object, smsServiceProxy.Object);

await messagingDomainService.ResendSMSMessage(TestData.ConnectionIdentifier,
TestData.MessageId,
CancellationToken.None);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
///
/// </summary>
/// <seealso cref="MediatR.IRequestHandler{MessagingService.BusinessLogic.Requests.SendEmailRequest, System.String}" />
public class MessagingRequestHandler : IRequestHandler<SendEmailRequest, String>,
IRequestHandler<SendSMSRequest, String>,
IRequestHandler<ResendEmailRequest,String>
public class MessagingRequestHandler : IRequestHandler<SendEmailRequest>,
IRequestHandler<SendSMSRequest>,
IRequestHandler<ResendEmailRequest>,
IRequestHandler<ResendSMSRequest>
{
#region Fields

Expand Down Expand Up @@ -49,7 +50,7 @@ public MessagingRequestHandler(IMessagingDomainService messagingDomainService)
/// <returns>
/// Response from the request
/// </returns>
public async Task<String> Handle(SendEmailRequest request,
public async Task<Unit> Handle(SendEmailRequest request,
CancellationToken cancellationToken){
List<EmailAttachment> attachments = new List<Models.EmailAttachment>();

Expand All @@ -71,28 +72,28 @@ await this.MessagingDomainService.SendEmailMessage(request.ConnectionIdentifier,
attachments,
cancellationToken);

return string.Empty;
return Unit.Value;
}

public async Task<String> Handle(SendSMSRequest request,
CancellationToken cancellationToken)
public async Task<Unit> Handle(SendSMSRequest request,
CancellationToken cancellationToken)
{
await this.MessagingDomainService.SendSMSMessage(request.ConnectionIdentifier,
request.MessageId,
request.Sender,
request.Destination,
request.Message,
cancellationToken);
return string.Empty;
return Unit.Value;
}

#endregion

public async Task<String> Handle(ResendEmailRequest request,
CancellationToken cancellationToken) {
public async Task<Unit> Handle(ResendEmailRequest request,
CancellationToken cancellationToken) {
await this.MessagingDomainService.ResendEmailMessage(request.ConnectionIdentifier, request.MessageId, cancellationToken);

return String.Empty;
return Unit.Value;
}

private Models.FileType ConvertFileType(FileType emailAttachmentFileType)
Expand All @@ -105,5 +106,11 @@ private Models.FileType ConvertFileType(FileType emailAttachmentFileType)
return Models.FileType.None;
}
}

public async Task<Unit> Handle(ResendSMSRequest request, CancellationToken cancellationToken){
await this.MessagingDomainService.ResendSMSMessage(request.ConnectionIdentifier, request.MessageId, cancellationToken);

return Unit.Value;
}
}
}
14 changes: 1 addition & 13 deletions MessagingService.BusinessLogic/Requests/ResendEmailRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System;
using MediatR;

public class ResendEmailRequest : IRequest<String>
public class ResendEmailRequest : IRequest
{
#region Constructors

Expand All @@ -18,20 +18,8 @@ private ResendEmailRequest(Guid connectionIdentifier,

#region Properties

/// <summary>
/// Gets the connection identifier.
/// </summary>
/// <value>
/// The connection identifier.
/// </value>
public Guid ConnectionIdentifier { get; }

/// <summary>
/// Gets the message identifier.
/// </summary>
/// <value>
/// The message identifier.
/// </value>
public Guid MessageId { get; }

#endregion
Expand Down
36 changes: 36 additions & 0 deletions MessagingService.BusinessLogic/Requests/ResendSMSRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
namespace MessagingService.BusinessLogic.Requests;

using System;
using MediatR;

public class ResendSMSRequest : IRequest
{
#region Constructors

private ResendSMSRequest(Guid connectionIdentifier,
Guid messageId)
{
this.ConnectionIdentifier = connectionIdentifier;
this.MessageId = messageId;
}

#endregion

#region Properties

public Guid ConnectionIdentifier { get; }

public Guid MessageId { get; }

#endregion

#region Methods

public static ResendSMSRequest Create(Guid connectionIdentifier,
Guid messageId)
{
return new ResendSMSRequest(connectionIdentifier, messageId);
}

#endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
///
/// </summary>
/// <seealso cref="MediatR.IRequest{System.String}" />
public class SendEmailRequest : IRequest<String>
public class SendEmailRequest : IRequest
{
#region Constructors

Expand Down
2 changes: 1 addition & 1 deletion MessagingService.BusinessLogic/Requests/SendSMSRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
///
/// </summary>
/// <seealso cref="MediatR.IRequest{System.String}" />
public class SendSMSRequest : IRequest<String>
public class SendSMSRequest : IRequest
{
#region Constructors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ Task ResendEmailMessage(Guid connectionIdentifier,
Guid messageId,
CancellationToken cancellationToken);

Task ResendSMSMessage(Guid connectionIdentifier,
Guid messageId,
CancellationToken cancellationToken);

#endregion
}
}
33 changes: 29 additions & 4 deletions MessagingService.BusinessLogic/Services/MessagingDomainService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public async Task SendSMSMessage(Guid connectionIdentifier,
await this.SmsAggregateRepository.SaveChanges(smsAggregate, cancellationToken);
}

public async Task ResendEmailMessage(Guid connectionIdentifier,
public async Task ResendEmailMessage(Guid connectionIdentifier,
Guid messageId,
CancellationToken cancellationToken) {
// Rehydrate Email Message aggregate
Expand All @@ -125,13 +125,38 @@ await this.EmailServiceProxy.SendEmail(messageId, emailAggregate.FromAddress,
emailAggregate.IsHtml, null,
cancellationToken);

// response message from provider (record event)
emailAggregate.ReceiveResponseFromProvider(emailResponse.RequestIdentifier, emailResponse.EmailIdentifier);
if (emailResponse.ApiCallSuccessful)
{
// response message from provider (record event)
emailAggregate.ReceiveResponseFromProvider(emailResponse.RequestIdentifier, emailResponse.EmailIdentifier);
}
else
{
emailAggregate.ReceiveBadResponseFromProvider(emailResponse.Error, emailResponse.ErrorCode);
}

// Save Changes to persistance
await this.EmailAggregateRepository.SaveChanges(emailAggregate, cancellationToken);
}

public async Task ResendSMSMessage(Guid connectionIdentifier, Guid messageId, CancellationToken cancellationToken){
// Rehydrate SMS Message aggregate
SMSAggregate smsAggregate = await this.SmsAggregateRepository.GetLatestVersion(messageId, cancellationToken);

// re-send message to provider (record event)
smsAggregate.ResendRequestToProvider();

// Make call to SMS provider here
SMSServiceProxyResponse smsResponse =
await this.SmsServiceProxy.SendSMS(messageId, smsAggregate.Sender, smsAggregate.Destination, smsAggregate.Message, cancellationToken);

// response message from provider (record event)
smsAggregate.ReceiveResponseFromProvider(smsResponse.SMSIdentifier);

// Save Changes to persistance
await this.SmsAggregateRepository.SaveChanges(smsAggregate, cancellationToken);
}
}

#endregion
#endregion
}
Loading