Skip to content

Commit 88d273c

Browse files
Merge pull request #140 from TransactionProcessing/task/#104_resendsmsmessage
Resend SMS Messages
2 parents 031bfd9 + 2e738d2 commit 88d273c

File tree

21 files changed

+442
-86
lines changed

21 files changed

+442
-86
lines changed

MessagingService.BusinessLogic.Tests/Mediator/DummyMessagingDomainService.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,8 @@ public async Task ResendEmailMessage(Guid connectionIdentifier,
3535
Guid messageId,
3636
CancellationToken cancellationToken) {
3737
}
38+
39+
public async Task ResendSMSMessage(Guid connectionIdentifier, Guid messageId, CancellationToken cancellationToken){
40+
}
3841
}
3942
}

MessagingService.BusinessLogic.Tests/RequestHandlers/MessagingRequestHandlerTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,19 @@ public void MessagingRequestHandler_SendSMSRequest_IsHandled()
5656
{
5757
await handler.Handle(command, CancellationToken.None);
5858
});
59+
}
60+
61+
[Fact]
62+
public void MessagingRequestHandler_ResendSMSRequest_IsHandled()
63+
{
64+
Mock<IMessagingDomainService> messagingDomainService = new Mock<IMessagingDomainService>();
65+
MessagingRequestHandler handler = new MessagingRequestHandler(messagingDomainService.Object);
66+
67+
ResendSMSRequest command = TestData.ResendSMSRequest;
5968

69+
Should.NotThrow(async () => {
70+
await handler.Handle(command, CancellationToken.None);
71+
});
6072
}
6173
}
6274
}

MessagingService.BusinessLogic.Tests/Requests/RequestTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,14 @@ public void ResendEmailRequest_CanBeCreated_IsCreated() {
6666
request.ConnectionIdentifier.ShouldBe(TestData.ConnectionIdentifier);
6767
request.MessageId.ShouldBe(TestData.MessageId);
6868
}
69+
70+
[Fact]
71+
public void ResendSMSRequest_CanBeCreated_IsCreated()
72+
{
73+
ResendSMSRequest request = ResendSMSRequest.Create(TestData.ConnectionIdentifier, TestData.MessageId);
74+
request.ShouldNotBeNull();
75+
request.ConnectionIdentifier.ShouldBe(TestData.ConnectionIdentifier);
76+
request.MessageId.ShouldBe(TestData.MessageId);
77+
}
6978
}
7079
}

MessagingService.BusinessLogic.Tests/Services/MessagingDomainServiceTests.cs

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,58 @@ await messagingDomainService.ResendEmailMessage(TestData.ConnectionIdentifier,
142142
CancellationToken.None);
143143
}
144144

145+
[Fact]
146+
public async Task MessagingDomainService_ResendEmailMessage_APICallFailed_MessageFailed()
147+
{
148+
Mock<IAggregateRepository<EmailAggregate, DomainEvent>> emailAggregateRepository = new Mock<IAggregateRepository<EmailAggregate, DomainEvent>>();
149+
emailAggregateRepository.Setup(a => a.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.GetSentEmailAggregate);
150+
Mock<IAggregateRepository<SMSAggregate, DomainEvent>> smsAggregateRepository = new Mock<IAggregateRepository<SMSAggregate, DomainEvent>>();
151+
Mock<IEmailServiceProxy> emailServiceProxy = new Mock<IEmailServiceProxy>();
152+
emailServiceProxy
153+
.Setup(e => e.SendEmail(It.IsAny<Guid>(),
154+
It.IsAny<String>(),
155+
It.IsAny<List<String>>(),
156+
It.IsAny<String>(),
157+
It.IsAny<String>(),
158+
It.IsAny<Boolean>(),
159+
It.IsAny<List<EmailAttachment>>(),
160+
It.IsAny<CancellationToken>())).ReturnsAsync(TestData.FailedAPICallEmailServiceProxyResponse);
161+
Mock<ISMSServiceProxy> smsServiceProxy = new Mock<ISMSServiceProxy>();
162+
163+
MessagingDomainService messagingDomainService =
164+
new MessagingDomainService(emailAggregateRepository.Object, smsAggregateRepository.Object, emailServiceProxy.Object, smsServiceProxy.Object);
165+
166+
await messagingDomainService.ResendEmailMessage(TestData.ConnectionIdentifier,
167+
TestData.MessageId,
168+
CancellationToken.None);
169+
}
170+
171+
[Fact]
172+
public async Task MessagingDomainService_ResendEmailMessage_APIResponseError_MessageFailed()
173+
{
174+
Mock<IAggregateRepository<EmailAggregate, DomainEvent>> emailAggregateRepository = new Mock<IAggregateRepository<EmailAggregate, DomainEvent>>();
175+
emailAggregateRepository.Setup(a => a.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.GetSentEmailAggregate);
176+
Mock<IAggregateRepository<SMSAggregate, DomainEvent>> smsAggregateRepository = new Mock<IAggregateRepository<SMSAggregate, DomainEvent>>();
177+
Mock<IEmailServiceProxy> emailServiceProxy = new Mock<IEmailServiceProxy>();
178+
emailServiceProxy
179+
.Setup(e => e.SendEmail(It.IsAny<Guid>(),
180+
It.IsAny<String>(),
181+
It.IsAny<List<String>>(),
182+
It.IsAny<String>(),
183+
It.IsAny<String>(),
184+
It.IsAny<Boolean>(),
185+
It.IsAny<List<EmailAttachment>>(),
186+
It.IsAny<CancellationToken>())).ReturnsAsync(TestData.FailedEmailServiceProxyResponse);
187+
Mock<ISMSServiceProxy> smsServiceProxy = new Mock<ISMSServiceProxy>();
188+
189+
MessagingDomainService messagingDomainService =
190+
new MessagingDomainService(emailAggregateRepository.Object, smsAggregateRepository.Object, emailServiceProxy.Object, smsServiceProxy.Object);
191+
192+
await messagingDomainService.ResendEmailMessage(TestData.ConnectionIdentifier,
193+
TestData.MessageId,
194+
CancellationToken.None);
195+
}
196+
145197
[Fact]
146198
public async Task MessagingDomainService_SendSMSMessage_MessageSent()
147199
{
@@ -167,5 +219,71 @@ await messagingDomainService.SendSMSMessage(TestData.ConnectionIdentifier,
167219
CancellationToken.None);
168220
}
169221

222+
[Fact]
223+
public async Task MessagingDomainService_ReSendSMSMessage_MessageSent()
224+
{
225+
Mock<IAggregateRepository<EmailAggregate, DomainEvent>> emailAggregateRepository = new Mock<IAggregateRepository<EmailAggregate, DomainEvent>>();
226+
Mock<IAggregateRepository<SMSAggregate, DomainEvent>> smsAggregateRepository = new Mock<IAggregateRepository<SMSAggregate, DomainEvent>>();
227+
smsAggregateRepository.Setup(a => a.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.GetSentSMSAggregate);
228+
Mock<IEmailServiceProxy> emailServiceProxy = new Mock<IEmailServiceProxy>();
229+
Mock<ISMSServiceProxy> smsServiceProxy = new Mock<ISMSServiceProxy>();
230+
smsServiceProxy
231+
.Setup(e => e.SendSMS(It.IsAny<Guid>(),
232+
It.IsAny<String>(),
233+
It.IsAny<String>(),
234+
It.IsAny<String>(),
235+
It.IsAny<CancellationToken>())).ReturnsAsync(TestData.SuccessfulSMSServiceProxyResponse);
236+
MessagingDomainService messagingDomainService =
237+
new MessagingDomainService(emailAggregateRepository.Object, smsAggregateRepository.Object, emailServiceProxy.Object, smsServiceProxy.Object);
238+
239+
await messagingDomainService.ResendSMSMessage(TestData.ConnectionIdentifier,
240+
TestData.MessageId,
241+
CancellationToken.None);
242+
}
243+
244+
[Fact]
245+
public async Task MessagingDomainService_ReSendSMSMessage_APICallFailed_MessageFailed()
246+
{
247+
Mock<IAggregateRepository<EmailAggregate, DomainEvent>> emailAggregateRepository = new Mock<IAggregateRepository<EmailAggregate, DomainEvent>>();
248+
Mock<IAggregateRepository<SMSAggregate, DomainEvent>> smsAggregateRepository = new Mock<IAggregateRepository<SMSAggregate, DomainEvent>>();
249+
smsAggregateRepository.Setup(a => a.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.GetSentSMSAggregate);
250+
Mock<IEmailServiceProxy> emailServiceProxy = new Mock<IEmailServiceProxy>();
251+
Mock<ISMSServiceProxy> smsServiceProxy = new Mock<ISMSServiceProxy>();
252+
smsServiceProxy
253+
.Setup(e => e.SendSMS(It.IsAny<Guid>(),
254+
It.IsAny<String>(),
255+
It.IsAny<String>(),
256+
It.IsAny<String>(),
257+
It.IsAny<CancellationToken>())).ReturnsAsync(TestData.FailedAPICallSMSServiceProxyResponse);
258+
MessagingDomainService messagingDomainService =
259+
new MessagingDomainService(emailAggregateRepository.Object, smsAggregateRepository.Object, emailServiceProxy.Object, smsServiceProxy.Object);
260+
261+
await messagingDomainService.ResendSMSMessage(TestData.ConnectionIdentifier,
262+
TestData.MessageId,
263+
CancellationToken.None);
264+
}
265+
266+
[Fact]
267+
public async Task MessagingDomainService_ReSendSMSMessage_APIResponseError_MessageFailed()
268+
{
269+
Mock<IAggregateRepository<EmailAggregate, DomainEvent>> emailAggregateRepository = new Mock<IAggregateRepository<EmailAggregate, DomainEvent>>();
270+
Mock<IAggregateRepository<SMSAggregate, DomainEvent>> smsAggregateRepository = new Mock<IAggregateRepository<SMSAggregate, DomainEvent>>();
271+
smsAggregateRepository.Setup(a => a.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.GetSentSMSAggregate);
272+
Mock<IEmailServiceProxy> emailServiceProxy = new Mock<IEmailServiceProxy>();
273+
Mock<ISMSServiceProxy> smsServiceProxy = new Mock<ISMSServiceProxy>();
274+
smsServiceProxy
275+
.Setup(e => e.SendSMS(It.IsAny<Guid>(),
276+
It.IsAny<String>(),
277+
It.IsAny<String>(),
278+
It.IsAny<String>(),
279+
It.IsAny<CancellationToken>())).ReturnsAsync(TestData.FailedSMSServiceProxyResponse);
280+
MessagingDomainService messagingDomainService =
281+
new MessagingDomainService(emailAggregateRepository.Object, smsAggregateRepository.Object, emailServiceProxy.Object, smsServiceProxy.Object);
282+
283+
await messagingDomainService.ResendSMSMessage(TestData.ConnectionIdentifier,
284+
TestData.MessageId,
285+
CancellationToken.None);
286+
}
287+
170288
}
171289
}

MessagingService.BusinessLogic/RequestHandlers/MessagingRequestHandler.cs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
///
1414
/// </summary>
1515
/// <seealso cref="MediatR.IRequestHandler{MessagingService.BusinessLogic.Requests.SendEmailRequest, System.String}" />
16-
public class MessagingRequestHandler : IRequestHandler<SendEmailRequest, String>,
17-
IRequestHandler<SendSMSRequest, String>,
18-
IRequestHandler<ResendEmailRequest,String>
16+
public class MessagingRequestHandler : IRequestHandler<SendEmailRequest>,
17+
IRequestHandler<SendSMSRequest>,
18+
IRequestHandler<ResendEmailRequest>,
19+
IRequestHandler<ResendSMSRequest>
1920
{
2021
#region Fields
2122

@@ -49,7 +50,7 @@ public MessagingRequestHandler(IMessagingDomainService messagingDomainService)
4950
/// <returns>
5051
/// Response from the request
5152
/// </returns>
52-
public async Task<String> Handle(SendEmailRequest request,
53+
public async Task<Unit> Handle(SendEmailRequest request,
5354
CancellationToken cancellationToken){
5455
List<EmailAttachment> attachments = new List<Models.EmailAttachment>();
5556

@@ -71,28 +72,28 @@ await this.MessagingDomainService.SendEmailMessage(request.ConnectionIdentifier,
7172
attachments,
7273
cancellationToken);
7374

74-
return string.Empty;
75+
return Unit.Value;
7576
}
7677

77-
public async Task<String> Handle(SendSMSRequest request,
78-
CancellationToken cancellationToken)
78+
public async Task<Unit> Handle(SendSMSRequest request,
79+
CancellationToken cancellationToken)
7980
{
8081
await this.MessagingDomainService.SendSMSMessage(request.ConnectionIdentifier,
8182
request.MessageId,
8283
request.Sender,
8384
request.Destination,
8485
request.Message,
8586
cancellationToken);
86-
return string.Empty;
87+
return Unit.Value;
8788
}
8889

8990
#endregion
9091

91-
public async Task<String> Handle(ResendEmailRequest request,
92-
CancellationToken cancellationToken) {
92+
public async Task<Unit> Handle(ResendEmailRequest request,
93+
CancellationToken cancellationToken) {
9394
await this.MessagingDomainService.ResendEmailMessage(request.ConnectionIdentifier, request.MessageId, cancellationToken);
9495

95-
return String.Empty;
96+
return Unit.Value;
9697
}
9798

9899
private Models.FileType ConvertFileType(FileType emailAttachmentFileType)
@@ -105,5 +106,11 @@ private Models.FileType ConvertFileType(FileType emailAttachmentFileType)
105106
return Models.FileType.None;
106107
}
107108
}
109+
110+
public async Task<Unit> Handle(ResendSMSRequest request, CancellationToken cancellationToken){
111+
await this.MessagingDomainService.ResendSMSMessage(request.ConnectionIdentifier, request.MessageId, cancellationToken);
112+
113+
return Unit.Value;
114+
}
108115
}
109116
}

MessagingService.BusinessLogic/Requests/ResendEmailRequest.cs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using System;
44
using MediatR;
55

6-
public class ResendEmailRequest : IRequest<String>
6+
public class ResendEmailRequest : IRequest
77
{
88
#region Constructors
99

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

1919
#region Properties
2020

21-
/// <summary>
22-
/// Gets the connection identifier.
23-
/// </summary>
24-
/// <value>
25-
/// The connection identifier.
26-
/// </value>
2721
public Guid ConnectionIdentifier { get; }
2822

29-
/// <summary>
30-
/// Gets the message identifier.
31-
/// </summary>
32-
/// <value>
33-
/// The message identifier.
34-
/// </value>
3523
public Guid MessageId { get; }
3624

3725
#endregion
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
namespace MessagingService.BusinessLogic.Requests;
2+
3+
using System;
4+
using MediatR;
5+
6+
public class ResendSMSRequest : IRequest
7+
{
8+
#region Constructors
9+
10+
private ResendSMSRequest(Guid connectionIdentifier,
11+
Guid messageId)
12+
{
13+
this.ConnectionIdentifier = connectionIdentifier;
14+
this.MessageId = messageId;
15+
}
16+
17+
#endregion
18+
19+
#region Properties
20+
21+
public Guid ConnectionIdentifier { get; }
22+
23+
public Guid MessageId { get; }
24+
25+
#endregion
26+
27+
#region Methods
28+
29+
public static ResendSMSRequest Create(Guid connectionIdentifier,
30+
Guid messageId)
31+
{
32+
return new ResendSMSRequest(connectionIdentifier, messageId);
33+
}
34+
35+
#endregion
36+
}

MessagingService.BusinessLogic/Requests/SendEmailRequest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
///
1010
/// </summary>
1111
/// <seealso cref="MediatR.IRequest{System.String}" />
12-
public class SendEmailRequest : IRequest<String>
12+
public class SendEmailRequest : IRequest
1313
{
1414
#region Constructors
1515

MessagingService.BusinessLogic/Requests/SendSMSRequest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
///
88
/// </summary>
99
/// <seealso cref="MediatR.IRequest{System.String}" />
10-
public class SendSMSRequest : IRequest<String>
10+
public class SendSMSRequest : IRequest
1111
{
1212
#region Constructors
1313

MessagingService.BusinessLogic/Services/IMessagingDomainService.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ Task ResendEmailMessage(Guid connectionIdentifier,
3434
Guid messageId,
3535
CancellationToken cancellationToken);
3636

37+
Task ResendSMSMessage(Guid connectionIdentifier,
38+
Guid messageId,
39+
CancellationToken cancellationToken);
40+
3741
#endregion
3842
}
3943
}

0 commit comments

Comments
 (0)