Skip to content

Commit 8efdea0

Browse files
Support SMS Message Sending
1 parent 00116ee commit 8efdea0

File tree

52 files changed

+2552
-161
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+2552
-161
lines changed

MessagingService.BusinessLogic.Tests/RequestHandlers/EmailRequestHandlerTests.cs

Lines changed: 0 additions & 34 deletions
This file was deleted.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace MessagingService.BusinessLogic.Tests.RequestHandlers
6+
{
7+
using System.Threading;
8+
using BusinessLogic.RequestHandlers;
9+
using BusinessLogic.Requests;
10+
using BusinessLogic.Services;
11+
using Moq;
12+
using Services;
13+
using Shouldly;
14+
using Testing;
15+
using Xunit;
16+
17+
public class MessagingRequestHandlerTests
18+
{
19+
[Fact]
20+
public void MessagingRequestHandler_SendEmailRequest_IsHandled()
21+
{
22+
Mock<IMessagingDomainService> messagingDomainService = new Mock<IMessagingDomainService>();
23+
MessagingRequestHandler handler = new MessagingRequestHandler(messagingDomainService.Object);
24+
25+
SendEmailRequest command = TestData.SendEmailRequest;
26+
27+
Should.NotThrow(async () =>
28+
{
29+
await handler.Handle(command, CancellationToken.None);
30+
});
31+
32+
}
33+
34+
[Fact]
35+
public void MessagingRequestHandler_SendSMSRequest_IsHandled()
36+
{
37+
Mock<IMessagingDomainService> messagingDomainService = new Mock<IMessagingDomainService>();
38+
MessagingRequestHandler handler = new MessagingRequestHandler(messagingDomainService.Object);
39+
40+
SendSMSRequest command = TestData.SendSMSRequest;
41+
42+
Should.NotThrow(async () =>
43+
{
44+
await handler.Handle(command, CancellationToken.None);
45+
});
46+
47+
}
48+
}
49+
}

MessagingService.BusinessLogic.Tests/Requests/RequestTests.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,22 @@ public void SendEmailRequest_CanBeCreated_IsCreated()
3131
request.Body.ShouldBe(TestData.Body);
3232
request.IsHtml.ShouldBe(TestData.IsHtmlTrue);
3333
}
34+
35+
[Fact]
36+
public void SendSMSRequest_CanBeCreated_IsCreated()
37+
{
38+
SendSMSRequest request = SendSMSRequest.Create(TestData.ConnectionIdentifier,
39+
TestData.MessageId,
40+
TestData.Sender,
41+
TestData.Destination,
42+
TestData.Message);
43+
44+
request.ShouldNotBeNull();
45+
request.ConnectionIdentifier.ShouldBe(TestData.ConnectionIdentifier);
46+
request.MessageId.ShouldBe(TestData.MessageId);
47+
request.Sender.ShouldBe(TestData.Sender);
48+
request.Destination.ShouldBe(TestData.Destination);
49+
request.Message.ShouldBe(TestData.Message);
50+
}
3451
}
3552
}

MessagingService.BusinessLogic.Tests/Services/EmailDomainServiceTests.cs

Lines changed: 0 additions & 48 deletions
This file was deleted.
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace MessagingService.BusinessLogic.Tests.Services
6+
{
7+
using System.Threading;
8+
using System.Threading.Tasks;
9+
using BusinessLogic.Services;
10+
using BusinessLogic.Services.EmailServices;
11+
using BusinessLogic.Services.SMSServices;
12+
using EmailMessageAggregate;
13+
using Moq;
14+
using Shared.EventStore.EventStore;
15+
using SMSMessageAggregate;
16+
using Testing;
17+
using Xunit;
18+
19+
public class MessagingDomainServiceTests
20+
{
21+
[Fact]
22+
public async Task MessagingDomainService_SendEmailMessage_MessageSent()
23+
{
24+
Mock<IAggregateRepository<EmailAggregate>> emailAggregateRepository = new Mock<IAggregateRepository<EmailAggregate>>();
25+
emailAggregateRepository.Setup(a => a.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.GetEmptyEmailAggregate());
26+
Mock<IAggregateRepository<SMSAggregate>> smsAggregateRepository = new Mock<IAggregateRepository<SMSAggregate>>();
27+
Mock<IEmailServiceProxy> emailServiceProxy = new Mock<IEmailServiceProxy>();
28+
emailServiceProxy
29+
.Setup(e => e.SendEmail(It.IsAny<Guid>(),
30+
It.IsAny<String>(),
31+
It.IsAny<List<String>>(),
32+
It.IsAny<String>(),
33+
It.IsAny<String>(),
34+
It.IsAny<Boolean>(),
35+
It.IsAny<CancellationToken>())).ReturnsAsync(TestData.SuccessfulEmailServiceProxyResponse);
36+
Mock<ISMSServiceProxy> smsServiceProxy = new Mock<ISMSServiceProxy>();
37+
38+
MessagingDomainService messagingDomainService =
39+
new MessagingDomainService(emailAggregateRepository.Object, smsAggregateRepository.Object, emailServiceProxy.Object, smsServiceProxy.Object);
40+
41+
await messagingDomainService.SendEmailMessage(TestData.ConnectionIdentifier,
42+
TestData.MessageId,
43+
TestData.FromAddress,
44+
TestData.ToAddresses,
45+
TestData.Subject,
46+
TestData.Body,
47+
TestData.IsHtmlTrue,
48+
CancellationToken.None);
49+
}
50+
51+
[Fact]
52+
public async Task MessagingDomainService_SendSMSMessage_MessageSent()
53+
{
54+
Mock<IAggregateRepository<EmailAggregate>> emailAggregateRepository = new Mock<IAggregateRepository<EmailAggregate>>();
55+
Mock<IAggregateRepository<SMSAggregate>> smsAggregateRepository = new Mock<IAggregateRepository<SMSAggregate>>();
56+
smsAggregateRepository.Setup(a => a.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.GetEmptySMSAggregate());
57+
Mock<IEmailServiceProxy> emailServiceProxy = new Mock<IEmailServiceProxy>();
58+
Mock<ISMSServiceProxy> smsServiceProxy = new Mock<ISMSServiceProxy>();
59+
smsServiceProxy
60+
.Setup(e => e.SendSMS(It.IsAny<Guid>(),
61+
It.IsAny<String>(),
62+
It.IsAny<String>(),
63+
It.IsAny<String>(),
64+
It.IsAny<CancellationToken>())).ReturnsAsync(TestData.SuccessfulSMSServiceProxyResponse);
65+
MessagingDomainService messagingDomainService =
66+
new MessagingDomainService(emailAggregateRepository.Object, smsAggregateRepository.Object, emailServiceProxy.Object, smsServiceProxy.Object);
67+
68+
await messagingDomainService.SendSMSMessage(TestData.ConnectionIdentifier,
69+
TestData.MessageId,
70+
TestData.Sender,
71+
TestData.Destination,
72+
TestData.Message,
73+
CancellationToken.None);
74+
}
75+
76+
}
77+
}

MessagingService.BusinessLogic/MessagingService.BusinessLogic.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
<ItemGroup>
1717
<ProjectReference Include="..\MessagingService.EmailMessageAggregate\MessagingService.EmailMessageAggregate.csproj" />
18+
<ProjectReference Include="..\MessagingService.SMSMessageAggregate\MessagingService.SMSMessageAggregate.csproj" />
1819
</ItemGroup>
1920

2021
</Project>

MessagingService.BusinessLogic/RequestHandlers/EmailRequestHandler.cs

Lines changed: 0 additions & 65 deletions
This file was deleted.
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
namespace MessagingService.BusinessLogic.RequestHandlers
2+
{
3+
using System;
4+
using System.Threading;
5+
using System.Threading.Tasks;
6+
using MediatR;
7+
using Requests;
8+
using Services;
9+
10+
/// <summary>
11+
///
12+
/// </summary>
13+
/// <seealso cref="MediatR.IRequestHandler{MessagingService.BusinessLogic.Requests.SendEmailRequest, System.String}" />
14+
public class MessagingRequestHandler : IRequestHandler<SendEmailRequest, String>, IRequestHandler<SendSMSRequest, String>
15+
{
16+
#region Fields
17+
18+
/// <summary>
19+
/// The messaging domain service
20+
/// </summary>
21+
private readonly IMessagingDomainService MessagingDomainService;
22+
23+
#endregion
24+
25+
#region Constructors
26+
27+
/// <summary>
28+
/// Initializes a new instance of the <see cref="MessagingRequestHandler" /> class.
29+
/// </summary>
30+
/// <param name="messagingDomainService">The messaging domain service.</param>
31+
public MessagingRequestHandler(IMessagingDomainService messagingDomainService)
32+
{
33+
this.MessagingDomainService = messagingDomainService;
34+
}
35+
36+
#endregion
37+
38+
#region Methods
39+
40+
/// <summary>
41+
/// Handles a request
42+
/// </summary>
43+
/// <param name="request">The request</param>
44+
/// <param name="cancellationToken">Cancellation token</param>
45+
/// <returns>
46+
/// Response from the request
47+
/// </returns>
48+
public async Task<String> Handle(SendEmailRequest request,
49+
CancellationToken cancellationToken)
50+
{
51+
await this.MessagingDomainService.SendEmailMessage(request.ConnectionIdentifier,
52+
request.MessageId,
53+
request.FromAddress,
54+
request.ToAddresses,
55+
request.Subject,
56+
request.Body,
57+
request.IsHtml,
58+
cancellationToken);
59+
60+
return string.Empty;
61+
}
62+
63+
public async Task<String> Handle(SendSMSRequest request,
64+
CancellationToken cancellationToken)
65+
{
66+
await this.MessagingDomainService.SendSMSMessage(request.ConnectionIdentifier,
67+
request.MessageId,
68+
request.Sender,
69+
request.Destination,
70+
request.Message,
71+
cancellationToken);
72+
return string.Empty;
73+
}
74+
75+
#endregion
76+
}
77+
}

0 commit comments

Comments
 (0)