|
| 1 | +using System; |
| 2 | +using System.Text; |
| 3 | + |
| 4 | +namespace MessagingService.BusinessLogic.Tests.DomainEventHanders |
| 5 | +{ |
| 6 | + using System.Threading; |
| 7 | + using BusinessLogic.Services.EmailServices; |
| 8 | + using EmailMessageAggregate; |
| 9 | + using EventHandling; |
| 10 | + using Moq; |
| 11 | + using Shared.EventStore.EventStore; |
| 12 | + using System.Threading.Tasks; |
| 13 | + using Testing; |
| 14 | + using Xunit; |
| 15 | + |
| 16 | + public class EmailDomainEventHandlerTests |
| 17 | + { |
| 18 | + [Fact] |
| 19 | + public async Task EmailDomainEventHandler_Handle_ResponseReceivedFromProviderEvent_Delivered_EventIsHandled() |
| 20 | + { |
| 21 | + Mock<IAggregateRepository<EmailAggregate>> aggregateRepository = new Mock<IAggregateRepository<EmailAggregate>>(); |
| 22 | + aggregateRepository.Setup(a => a.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.GetSentEmailAggregate); |
| 23 | + Mock<IEmailServiceProxy> emailServiceProxy = new Mock<IEmailServiceProxy>(); |
| 24 | + emailServiceProxy.Setup(e => e.GetMessageStatus(It.IsAny<String>(), It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<CancellationToken>())) |
| 25 | + .ReturnsAsync(TestData.MessageStatusResponseDelivered); |
| 26 | + |
| 27 | + EmailDomainEventHandler emailDomainEventHandler = new EmailDomainEventHandler(aggregateRepository.Object, |
| 28 | + emailServiceProxy.Object); |
| 29 | + |
| 30 | + await emailDomainEventHandler.Handle(TestData.ResponseReceivedFromProviderEvent, CancellationToken.None); |
| 31 | + } |
| 32 | + |
| 33 | + [Fact] |
| 34 | + public async Task EmailDomainEventHandler_Handle_ResponseReceivedFromProviderEvent_Failed_EventIsHandled() |
| 35 | + { |
| 36 | + Mock<IAggregateRepository<EmailAggregate>> aggregateRepository = new Mock<IAggregateRepository<EmailAggregate>>(); |
| 37 | + aggregateRepository.Setup(a => a.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.GetSentEmailAggregate); |
| 38 | + Mock<IEmailServiceProxy> emailServiceProxy = new Mock<IEmailServiceProxy>(); |
| 39 | + emailServiceProxy.Setup(e => e.GetMessageStatus(It.IsAny<String>(), It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<CancellationToken>())) |
| 40 | + .ReturnsAsync(TestData.MessageStatusResponseFailed); |
| 41 | + |
| 42 | + EmailDomainEventHandler emailDomainEventHandler = new EmailDomainEventHandler(aggregateRepository.Object, |
| 43 | + emailServiceProxy.Object); |
| 44 | + |
| 45 | + await emailDomainEventHandler.Handle(TestData.ResponseReceivedFromProviderEvent, CancellationToken.None); |
| 46 | + } |
| 47 | + |
| 48 | + [Fact] |
| 49 | + public async Task EmailDomainEventHandler_Handle_ResponseReceivedFromProviderEvent_Rejected_EventIsHandled() |
| 50 | + { |
| 51 | + Mock<IAggregateRepository<EmailAggregate>> aggregateRepository = new Mock<IAggregateRepository<EmailAggregate>>(); |
| 52 | + aggregateRepository.Setup(a => a.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.GetSentEmailAggregate); |
| 53 | + Mock<IEmailServiceProxy> emailServiceProxy = new Mock<IEmailServiceProxy>(); |
| 54 | + emailServiceProxy.Setup(e => e.GetMessageStatus(It.IsAny<String>(), It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<CancellationToken>())) |
| 55 | + .ReturnsAsync(TestData.MessageStatusResponseRejected); |
| 56 | + |
| 57 | + EmailDomainEventHandler emailDomainEventHandler = new EmailDomainEventHandler(aggregateRepository.Object, |
| 58 | + emailServiceProxy.Object); |
| 59 | + |
| 60 | + await emailDomainEventHandler.Handle(TestData.ResponseReceivedFromProviderEvent, CancellationToken.None); |
| 61 | + } |
| 62 | + |
| 63 | + [Fact] |
| 64 | + public async Task EmailDomainEventHandler_Handle_ResponseReceivedFromProviderEvent_Bounced_EventIsHandled() |
| 65 | + { |
| 66 | + Mock<IAggregateRepository<EmailAggregate>> aggregateRepository = new Mock<IAggregateRepository<EmailAggregate>>(); |
| 67 | + aggregateRepository.Setup(a => a.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.GetSentEmailAggregate); |
| 68 | + Mock<IEmailServiceProxy> emailServiceProxy = new Mock<IEmailServiceProxy>(); |
| 69 | + emailServiceProxy.Setup(e => e.GetMessageStatus(It.IsAny<String>(), It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<CancellationToken>())) |
| 70 | + .ReturnsAsync(TestData.MessageStatusResponseBounced); |
| 71 | + |
| 72 | + EmailDomainEventHandler emailDomainEventHandler = new EmailDomainEventHandler(aggregateRepository.Object, |
| 73 | + emailServiceProxy.Object); |
| 74 | + |
| 75 | + await emailDomainEventHandler.Handle(TestData.ResponseReceivedFromProviderEvent, CancellationToken.None); |
| 76 | + } |
| 77 | + |
| 78 | + [Fact] |
| 79 | + public async Task EmailDomainEventHandler_Handle_ResponseReceivedFromProviderEvent_Spam_EventIsHandled() |
| 80 | + { |
| 81 | + Mock<IAggregateRepository<EmailAggregate>> aggregateRepository = new Mock<IAggregateRepository<EmailAggregate>>(); |
| 82 | + aggregateRepository.Setup(a => a.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.GetSentEmailAggregate); |
| 83 | + Mock<IEmailServiceProxy> emailServiceProxy = new Mock<IEmailServiceProxy>(); |
| 84 | + emailServiceProxy.Setup(e => e.GetMessageStatus(It.IsAny<String>(), It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<CancellationToken>())) |
| 85 | + .ReturnsAsync(TestData.MessageStatusResponseSpam); |
| 86 | + |
| 87 | + EmailDomainEventHandler emailDomainEventHandler = new EmailDomainEventHandler(aggregateRepository.Object, |
| 88 | + emailServiceProxy.Object); |
| 89 | + |
| 90 | + await emailDomainEventHandler.Handle(TestData.ResponseReceivedFromProviderEvent, CancellationToken.None); |
| 91 | + } |
| 92 | + |
| 93 | + [Fact] |
| 94 | + public async Task EmailDomainEventHandler_Handle_ResponseReceivedFromProviderEvent_Unknown_EventIsHandled() |
| 95 | + { |
| 96 | + Mock<IAggregateRepository<EmailAggregate>> aggregateRepository = new Mock<IAggregateRepository<EmailAggregate>>(); |
| 97 | + aggregateRepository.Setup(a => a.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.GetSentEmailAggregate); |
| 98 | + Mock<IEmailServiceProxy> emailServiceProxy = new Mock<IEmailServiceProxy>(); |
| 99 | + emailServiceProxy.Setup(e => e.GetMessageStatus(It.IsAny<String>(), It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<CancellationToken>())) |
| 100 | + .ReturnsAsync(TestData.MessageStatusResponseUnknown); |
| 101 | + |
| 102 | + EmailDomainEventHandler emailDomainEventHandler = new EmailDomainEventHandler(aggregateRepository.Object, |
| 103 | + emailServiceProxy.Object); |
| 104 | + |
| 105 | + await emailDomainEventHandler.Handle(TestData.ResponseReceivedFromProviderEvent, CancellationToken.None); |
| 106 | + } |
| 107 | + } |
| 108 | +} |
0 commit comments