11using System ;
22using System . Text ;
3+ using MediatR ;
34
45namespace 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}
0 commit comments