예제 #1
0
        public void EmailAggregate_MarkMessageAsFailed_IncorrectState_ErrorThrown(MessageStatus messageStatus)
        {
            EmailAggregate emailAggregate = EmailAggregate.Create(TestData.MessageId);

            emailAggregate.SendRequestToProvider(TestData.FromAddress, TestData.ToAddresses, TestData.Subject, TestData.Body, TestData.IsHtmlTrue);

            switch (messageStatus)
            {
            case MessageStatus.Delivered:
                emailAggregate.ReceiveResponseFromProvider(TestData.ProviderRequestReference, TestData.ProviderEmailReference);
                emailAggregate.MarkMessageAsDelivered(TestData.ProviderStatusDescription, TestData.DeliveredDateTime);
                break;

            case MessageStatus.Bounced:
                emailAggregate.ReceiveResponseFromProvider(TestData.ProviderRequestReference, TestData.ProviderEmailReference);
                emailAggregate.MarkMessageAsBounced(TestData.ProviderStatusDescription, TestData.BouncedDateTime);
                break;

            case MessageStatus.Failed:
                emailAggregate.ReceiveResponseFromProvider(TestData.ProviderRequestReference, TestData.ProviderEmailReference);
                emailAggregate.MarkMessageAsFailed(TestData.ProviderStatusDescription, TestData.FailedDateTime);
                break;

            case MessageStatus.Rejected:
                emailAggregate.ReceiveResponseFromProvider(TestData.ProviderRequestReference, TestData.ProviderEmailReference);
                emailAggregate.MarkMessageAsRejected(TestData.ProviderStatusDescription, TestData.RejectedDateTime);
                break;

            case MessageStatus.Spam:
                emailAggregate.ReceiveResponseFromProvider(TestData.ProviderRequestReference, TestData.ProviderEmailReference);
                emailAggregate.MarkMessageAsSpam(TestData.ProviderStatusDescription, TestData.SpamDateTime);
                break;

            case MessageStatus.NotSet:
                break;
            }

            Should.Throw <InvalidOperationException>(() =>
            {
                emailAggregate.MarkMessageAsFailed(TestData.ProviderStatusDescription, TestData.FailedDateTime);
            });
        }
예제 #2
0
        public void EmailAggregate_MarkMessageAsFailed_MessageMarkedAsFailed()
        {
            EmailAggregate emailAggregate = EmailAggregate.Create(TestData.MessageId);

            emailAggregate.SendRequestToProvider(TestData.FromAddress, TestData.ToAddresses, TestData.Subject, TestData.Body, TestData.IsHtmlTrue);
            emailAggregate.ReceiveResponseFromProvider(TestData.ProviderRequestReference, TestData.ProviderEmailReference);

            emailAggregate.MarkMessageAsFailed(TestData.ProviderStatusDescription, TestData.FailedDateTime);

            emailAggregate.MessageStatus.ShouldBe(MessageStatus.Failed);
        }
예제 #3
0
        /// <summary>
        /// Handles the specific domain event.
        /// </summary>
        /// <param name="domainEvent">The domain event.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        private async Task HandleSpecificDomainEvent(ResponseReceivedFromEmailProviderEvent domainEvent,
                                                     CancellationToken cancellationToken)
        {
            EmailAggregate emailAggregate = await this.AggregateRepository.GetLatestVersion(domainEvent.MessageId, cancellationToken);

            // Update the aggregate with the status request information

            // Get the message status from the provider
            MessageStatusResponse messageStatus = await this.EmailServiceProxy.GetMessageStatus(domainEvent.ProviderEmailReference,
                                                                                                domainEvent.EventTimestamp.DateTime,
                                                                                                domainEvent.EventTimestamp.DateTime,
                                                                                                cancellationToken);

            // Update the aggregate with the response
            switch (messageStatus.MessageStatus)
            {
            case MessageStatus.Failed:
                emailAggregate.MarkMessageAsFailed(messageStatus.ProviderStatusDescription, messageStatus.Timestamp);
                break;

            case MessageStatus.Rejected:
                emailAggregate.MarkMessageAsRejected(messageStatus.ProviderStatusDescription, messageStatus.Timestamp);
                break;

            case MessageStatus.Bounced:
                emailAggregate.MarkMessageAsBounced(messageStatus.ProviderStatusDescription, messageStatus.Timestamp);
                break;

            case MessageStatus.Spam:
                emailAggregate.MarkMessageAsSpam(messageStatus.ProviderStatusDescription, messageStatus.Timestamp);
                break;

            case MessageStatus.Delivered:
                emailAggregate.MarkMessageAsDelivered(messageStatus.ProviderStatusDescription, messageStatus.Timestamp);
                break;

            case MessageStatus.Unknown:
                break;
            }

            // Save the changes
            await this.AggregateRepository.SaveChanges(emailAggregate, cancellationToken);
        }