Skip to content

Commit 9e2e650

Browse files
Merge pull request #174 from TransactionProcessing/task/#173_use_results
upgrade service to use results
2 parents 86ad835 + 1a97ab5 commit 9e2e650

File tree

38 files changed

+507
-972
lines changed

38 files changed

+507
-972
lines changed
Lines changed: 27 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Text;
3+
using MediatR;
34

45
namespace MessagingService.BusinessLogic.Tests.DomainEventHanders
56
{
@@ -14,96 +15,69 @@ namespace MessagingService.BusinessLogic.Tests.DomainEventHanders
1415
using Testing;
1516
using Xunit;
1617

17-
public class EmailDomainEventHandlerTests
18-
{
18+
public class EmailDomainEventHandlerTests {
19+
private Mock<IMediator> Mediator;
20+
private Mock<IEmailServiceProxy> EmailServiceProxy;
21+
private EmailDomainEventHandler EmailDomainEventHandler;
22+
public EmailDomainEventHandlerTests() {
23+
this.Mediator = new Mock<IMediator>();
24+
this.EmailServiceProxy = new Mock<IEmailServiceProxy>();
25+
this.EmailDomainEventHandler =
26+
new EmailDomainEventHandler(this.Mediator.Object, this.EmailServiceProxy.Object);
27+
}
28+
1929
[Fact]
2030
public async Task EmailDomainEventHandler_Handle_ResponseReceivedFromProviderEvent_Delivered_EventIsHandled()
2131
{
22-
Mock<IAggregateRepository<EmailAggregate, DomainEvent>> aggregateRepository = new Mock<IAggregateRepository<EmailAggregate, DomainEvent>>();
23-
aggregateRepository.Setup(a => a.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.GetSentEmailAggregate);
24-
Mock<IEmailServiceProxy> emailServiceProxy = new Mock<IEmailServiceProxy>();
25-
emailServiceProxy.Setup(e => e.GetMessageStatus(It.IsAny<String>(), It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<CancellationToken>()))
32+
this.EmailServiceProxy.Setup(e => e.GetMessageStatus(It.IsAny<String>(), It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<CancellationToken>()))
2633
.ReturnsAsync(TestData.MessageStatusResponseDelivered);
27-
28-
EmailDomainEventHandler emailDomainEventHandler = new EmailDomainEventHandler(aggregateRepository.Object,
29-
emailServiceProxy.Object);
30-
31-
await emailDomainEventHandler.Handle(TestData.ResponseReceivedFromEmailProviderEvent, CancellationToken.None);
34+
35+
await this.EmailDomainEventHandler.Handle(TestData.ResponseReceivedFromEmailProviderEvent, CancellationToken.None);
3236
}
3337

3438
[Fact]
3539
public async Task EmailDomainEventHandler_Handle_ResponseReceivedFromProviderEvent_Failed_EventIsHandled()
3640
{
37-
Mock<IAggregateRepository<EmailAggregate, DomainEvent>> aggregateRepository = new Mock<IAggregateRepository<EmailAggregate, DomainEvent>>();
38-
aggregateRepository.Setup(a => a.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.GetSentEmailAggregate);
39-
Mock<IEmailServiceProxy> emailServiceProxy = new Mock<IEmailServiceProxy>();
40-
emailServiceProxy.Setup(e => e.GetMessageStatus(It.IsAny<String>(), It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<CancellationToken>()))
41+
this.EmailServiceProxy.Setup(e => e.GetMessageStatus(It.IsAny<String>(), It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<CancellationToken>()))
4142
.ReturnsAsync(TestData.MessageStatusResponseFailed);
42-
43-
EmailDomainEventHandler emailDomainEventHandler = new EmailDomainEventHandler(aggregateRepository.Object,
44-
emailServiceProxy.Object);
45-
46-
await emailDomainEventHandler.Handle(TestData.ResponseReceivedFromEmailProviderEvent, CancellationToken.None);
43+
44+
await this.EmailDomainEventHandler.Handle(TestData.ResponseReceivedFromEmailProviderEvent, CancellationToken.None);
4745
}
4846

4947
[Fact]
5048
public async Task EmailDomainEventHandler_Handle_ResponseReceivedFromProviderEvent_Rejected_EventIsHandled()
5149
{
52-
Mock<IAggregateRepository<EmailAggregate, DomainEvent>> aggregateRepository = new Mock<IAggregateRepository<EmailAggregate, DomainEvent>>();
53-
aggregateRepository.Setup(a => a.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.GetSentEmailAggregate);
54-
Mock<IEmailServiceProxy> emailServiceProxy = new Mock<IEmailServiceProxy>();
55-
emailServiceProxy.Setup(e => e.GetMessageStatus(It.IsAny<String>(), It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<CancellationToken>()))
50+
this.EmailServiceProxy.Setup(e => e.GetMessageStatus(It.IsAny<String>(), It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<CancellationToken>()))
5651
.ReturnsAsync(TestData.MessageStatusResponseRejected);
5752

58-
EmailDomainEventHandler emailDomainEventHandler = new EmailDomainEventHandler(aggregateRepository.Object,
59-
emailServiceProxy.Object);
60-
61-
await emailDomainEventHandler.Handle(TestData.ResponseReceivedFromEmailProviderEvent, CancellationToken.None);
53+
await this.EmailDomainEventHandler.Handle(TestData.ResponseReceivedFromEmailProviderEvent, CancellationToken.None);
6254
}
6355

6456
[Fact]
6557
public async Task EmailDomainEventHandler_Handle_ResponseReceivedFromProviderEvent_Bounced_EventIsHandled()
6658
{
67-
Mock<IAggregateRepository<EmailAggregate, DomainEvent>> aggregateRepository = new Mock<IAggregateRepository<EmailAggregate, DomainEvent>>();
68-
aggregateRepository.Setup(a => a.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.GetSentEmailAggregate);
69-
Mock<IEmailServiceProxy> emailServiceProxy = new Mock<IEmailServiceProxy>();
70-
emailServiceProxy.Setup(e => e.GetMessageStatus(It.IsAny<String>(), It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<CancellationToken>()))
59+
this.EmailServiceProxy.Setup(e => e.GetMessageStatus(It.IsAny<String>(), It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<CancellationToken>()))
7160
.ReturnsAsync(TestData.MessageStatusResponseBounced);
7261

73-
EmailDomainEventHandler emailDomainEventHandler = new EmailDomainEventHandler(aggregateRepository.Object,
74-
emailServiceProxy.Object);
75-
76-
await emailDomainEventHandler.Handle(TestData.ResponseReceivedFromEmailProviderEvent, CancellationToken.None);
62+
await this.EmailDomainEventHandler.Handle(TestData.ResponseReceivedFromEmailProviderEvent, CancellationToken.None);
7763
}
7864

7965
[Fact]
8066
public async Task EmailDomainEventHandler_Handle_ResponseReceivedFromProviderEvent_Spam_EventIsHandled()
8167
{
82-
Mock<IAggregateRepository<EmailAggregate, DomainEvent>> aggregateRepository = new Mock<IAggregateRepository<EmailAggregate, DomainEvent>>();
83-
aggregateRepository.Setup(a => a.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.GetSentEmailAggregate);
84-
Mock<IEmailServiceProxy> emailServiceProxy = new Mock<IEmailServiceProxy>();
85-
emailServiceProxy.Setup(e => e.GetMessageStatus(It.IsAny<String>(), It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<CancellationToken>()))
68+
this.EmailServiceProxy.Setup(e => e.GetMessageStatus(It.IsAny<String>(), It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<CancellationToken>()))
8669
.ReturnsAsync(TestData.MessageStatusResponseSpam);
8770

88-
EmailDomainEventHandler emailDomainEventHandler = new EmailDomainEventHandler(aggregateRepository.Object,
89-
emailServiceProxy.Object);
90-
91-
await emailDomainEventHandler.Handle(TestData.ResponseReceivedFromEmailProviderEvent, CancellationToken.None);
71+
await this.EmailDomainEventHandler.Handle(TestData.ResponseReceivedFromEmailProviderEvent, CancellationToken.None);
9272
}
9373

9474
[Fact]
9575
public async Task EmailDomainEventHandler_Handle_ResponseReceivedFromProviderEvent_Unknown_EventIsHandled()
9676
{
97-
Mock<IAggregateRepository<EmailAggregate, DomainEvent>> aggregateRepository = new Mock<IAggregateRepository<EmailAggregate, DomainEvent>>();
98-
aggregateRepository.Setup(a => a.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.GetSentEmailAggregate);
99-
Mock<IEmailServiceProxy> emailServiceProxy = new Mock<IEmailServiceProxy>();
100-
emailServiceProxy.Setup(e => e.GetMessageStatus(It.IsAny<String>(), It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<CancellationToken>()))
77+
this.EmailServiceProxy.Setup(e => e.GetMessageStatus(It.IsAny<String>(), It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<CancellationToken>()))
10178
.ReturnsAsync(TestData.MessageStatusResponseUnknown);
102-
103-
EmailDomainEventHandler emailDomainEventHandler = new EmailDomainEventHandler(aggregateRepository.Object,
104-
emailServiceProxy.Object);
105-
106-
await emailDomainEventHandler.Handle(TestData.ResponseReceivedFromEmailProviderEvent, CancellationToken.None);
79+
80+
await this.EmailDomainEventHandler.Handle(TestData.ResponseReceivedFromEmailProviderEvent, CancellationToken.None);
10781
}
10882
}
10983
}

MessagingService.BusinessLogic.Tests/DomainEventHanders/SMSDomainEventHandlerTests.cs

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -15,67 +15,55 @@ namespace MessagingService.BusinessLogic.Tests.DomainEventHanders
1515
using SMSMessageAggregate;
1616
using Testing;
1717
using Xunit;
18+
using MediatR;
1819

1920
public class SMSDomainEventHandlerTests
2021
{
22+
private Mock<IMediator> Mediator;
23+
private Mock<ISMSServiceProxy> SMSServiceProxy;
24+
private SMSDomainEventHandler SMSDomainEventHandler;
25+
public SMSDomainEventHandlerTests()
26+
{
27+
this.Mediator = new Mock<IMediator>();
28+
this.SMSServiceProxy = new Mock<ISMSServiceProxy>();
29+
this.SMSDomainEventHandler =
30+
new SMSDomainEventHandler(this.Mediator.Object, this.SMSServiceProxy.Object);
31+
}
32+
2133
[Fact]
2234
public async Task SMSDomainEventHandler_Handle_ResponseReceivedFromProviderEvent_Delivered_EventIsHandled()
2335
{
24-
Mock<IAggregateRepository<SMSAggregate, DomainEvent>> aggregateRepository = new Mock<IAggregateRepository<SMSAggregate, DomainEvent>>();
25-
aggregateRepository.Setup(a => a.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.GetSentSMSAggregate);
26-
Mock<ISMSServiceProxy> smsServiceProxy = new Mock<ISMSServiceProxy>();
27-
smsServiceProxy.Setup(e => e.GetMessageStatus(It.IsAny<String>(), It.IsAny<CancellationToken>()))
36+
this.SMSServiceProxy.Setup(e => e.GetMessageStatus(It.IsAny<String>(), It.IsAny<CancellationToken>()))
2837
.ReturnsAsync(TestData.SMSMessageStatusResponseDelivered);
29-
30-
SMSDomainEventHandler smsDomainEventHandler = new SMSDomainEventHandler(aggregateRepository.Object,
31-
smsServiceProxy.Object);
32-
33-
await smsDomainEventHandler.Handle(TestData.ResponseReceivedFromSMSProviderEvent, CancellationToken.None);
38+
39+
await SMSDomainEventHandler.Handle(TestData.ResponseReceivedFromSMSProviderEvent, CancellationToken.None);
3440
}
3541

3642
[Fact]
3743
public async Task SMSDomainEventHandler_Handle_ResponseReceivedFromProviderEvent_Expired_EventIsHandled()
3844
{
39-
Mock<IAggregateRepository<SMSAggregate, DomainEvent>> aggregateRepository = new Mock<IAggregateRepository<SMSAggregate, DomainEvent>>();
40-
aggregateRepository.Setup(a => a.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.GetSentSMSAggregate);
41-
Mock<ISMSServiceProxy> smsServiceProxy = new Mock<ISMSServiceProxy>();
42-
smsServiceProxy.Setup(e => e.GetMessageStatus(It.IsAny<String>(), It.IsAny<CancellationToken>()))
45+
this.SMSServiceProxy.Setup(e => e.GetMessageStatus(It.IsAny<String>(), It.IsAny<CancellationToken>()))
4346
.ReturnsAsync(TestData.SMSMessageStatusResponseExpired);
44-
45-
SMSDomainEventHandler smsDomainEventHandler = new SMSDomainEventHandler(aggregateRepository.Object,
46-
smsServiceProxy.Object);
47-
48-
await smsDomainEventHandler.Handle(TestData.ResponseReceivedFromSMSProviderEvent, CancellationToken.None);
47+
48+
await SMSDomainEventHandler.Handle(TestData.ResponseReceivedFromSMSProviderEvent, CancellationToken.None);
4949
}
5050

5151
[Fact]
5252
public async Task SMSDomainEventHandler_Handle_ResponseReceivedFromProviderEvent_Rejected_EventIsHandled()
5353
{
54-
Mock<IAggregateRepository<SMSAggregate, DomainEvent>> aggregateRepository = new Mock<IAggregateRepository<SMSAggregate, DomainEvent>>();
55-
aggregateRepository.Setup(a => a.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.GetSentSMSAggregate);
56-
Mock<ISMSServiceProxy> smsServiceProxy = new Mock<ISMSServiceProxy>();
57-
smsServiceProxy.Setup(e => e.GetMessageStatus(It.IsAny<String>(), It.IsAny<CancellationToken>()))
54+
this.SMSServiceProxy.Setup(e => e.GetMessageStatus(It.IsAny<String>(), It.IsAny<CancellationToken>()))
5855
.ReturnsAsync(TestData.SMSMessageStatusResponseRejected);
5956

60-
SMSDomainEventHandler smsDomainEventHandler = new SMSDomainEventHandler(aggregateRepository.Object,
61-
smsServiceProxy.Object);
62-
63-
await smsDomainEventHandler.Handle(TestData.ResponseReceivedFromSMSProviderEvent, CancellationToken.None);
57+
await SMSDomainEventHandler.Handle(TestData.ResponseReceivedFromSMSProviderEvent, CancellationToken.None);
6458
}
6559

6660
[Fact]
6761
public async Task SMSDomainEventHandler_Handle_ResponseReceivedFromProviderEvent_Undelivered_EventIsHandled()
6862
{
69-
Mock<IAggregateRepository<SMSAggregate, DomainEvent>> aggregateRepository = new Mock<IAggregateRepository<SMSAggregate, DomainEvent>>();
70-
aggregateRepository.Setup(a => a.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.GetSentSMSAggregate);
71-
Mock<ISMSServiceProxy> smsServiceProxy = new Mock<ISMSServiceProxy>();
72-
smsServiceProxy.Setup(e => e.GetMessageStatus(It.IsAny<String>(), It.IsAny<CancellationToken>()))
63+
this.SMSServiceProxy.Setup(e => e.GetMessageStatus(It.IsAny<String>(), It.IsAny<CancellationToken>()))
7364
.ReturnsAsync(TestData.SMSMessageStatusResponseUndelivered);
7465

75-
SMSDomainEventHandler smsDomainEventHandler = new SMSDomainEventHandler(aggregateRepository.Object,
76-
smsServiceProxy.Object);
77-
78-
await smsDomainEventHandler.Handle(TestData.ResponseReceivedFromSMSProviderEvent, CancellationToken.None);
66+
await this.SMSDomainEventHandler.Handle(TestData.ResponseReceivedFromSMSProviderEvent, CancellationToken.None);
7967
}
8068
}
8169
}

MessagingService.BusinessLogic.Tests/Mediator/DummyMessagingDomainService.cs

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Linq;
55
using System.Text;
66
using System.Threading.Tasks;
7+
using SimpleResults;
78

89
namespace MessagingService.BusinessLogic.Tests.Mediator
910
{
@@ -12,31 +13,26 @@ namespace MessagingService.BusinessLogic.Tests.Mediator
1213

1314
public class DummyMessagingDomainService : IMessagingDomainService
1415
{
15-
public async Task SendEmailMessage(Guid connectionIdentifier,
16-
Guid messageId,
17-
String fromAddress,
18-
List<String> toAddresses,
19-
String subject,
20-
String body,
21-
Boolean isHtml,
22-
List<EmailAttachment> attachments,
23-
CancellationToken cancellationToken) {
24-
}
16+
public async Task<Result> SendEmailMessage(Guid connectionIdentifier,
17+
Guid messageId,
18+
String fromAddress,
19+
List<String> toAddresses,
20+
String subject,
21+
String body,
22+
Boolean isHtml,
23+
List<EmailAttachment> attachments,
24+
CancellationToken cancellationToken) => Result.Success();
25+
26+
public async Task<Result> SendSMSMessage(Guid connectionIdentifier,
27+
Guid messageId,
28+
String sender,
29+
String destination,
30+
String message,
31+
CancellationToken cancellationToken) => Result.Success();
2532

26-
public async Task SendSMSMessage(Guid connectionIdentifier,
27-
Guid messageId,
28-
String sender,
29-
String destination,
30-
String message,
31-
CancellationToken cancellationToken) {
32-
}
33-
34-
public async Task ResendEmailMessage(Guid connectionIdentifier,
35-
Guid messageId,
36-
CancellationToken cancellationToken) {
37-
}
38-
39-
public async Task ResendSMSMessage(Guid connectionIdentifier, Guid messageId, CancellationToken cancellationToken){
40-
}
33+
public async Task<Result> ResendEmailMessage(Guid connectionIdentifier,
34+
Guid messageId,
35+
CancellationToken cancellationToken) => Result.Success();
36+
public async Task<Result> ResendSMSMessage(Guid connectionIdentifier, Guid messageId, CancellationToken cancellationToken) => Result.Success();
4137
}
4238
}

MessagingService.BusinessLogic.Tests/Mediator/MediatorTests.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ public class MediatorTests
2323
private List<IBaseRequest> Requests = new List<IBaseRequest>();
2424

2525
public MediatorTests() {
26-
this.Requests.Add(TestData.ResendEmailRequest);
27-
this.Requests.Add(TestData.SendEmailRequestNoAttachments);
28-
this.Requests.Add(TestData.SendSMSRequest);
26+
this.Requests.Add(TestData.ResendEmailCommand);
27+
this.Requests.Add(TestData.SendEmailCommand);
28+
this.Requests.Add(TestData.SendSMSCommand);
29+
this.Requests.Add(TestData.ResendSMSCommand);
2930
}
3031

3132
[Fact]

0 commit comments

Comments
 (0)