/// <summary>
        /// Sends the email message.
        /// </summary>
        /// <param name="connectionIdentifier">The connection identifier.</param>
        /// <param name="messageId">The message identifier.</param>
        /// <param name="fromAddress">From address.</param>
        /// <param name="toAddresses">To addresses.</param>
        /// <param name="subject">The subject.</param>
        /// <param name="body">The body.</param>
        /// <param name="isHtml">if set to <c>true</c> [is HTML].</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        public async Task SendEmailMessage(Guid connectionIdentifier,
                                           Guid messageId,
                                           String fromAddress,
                                           List <String> toAddresses,
                                           String subject,
                                           String body,
                                           Boolean isHtml,
                                           CancellationToken cancellationToken)
        {
            // Rehydrate Email Message aggregate
            EmailAggregate emailAggregate = await this.EmailAggregateRepository.GetLatestVersion(messageId, cancellationToken);

            // send message to provider (record event)
            emailAggregate.SendRequestToProvider(fromAddress, toAddresses, subject, body, isHtml);

            // Make call to Email provider here
            EmailServiceProxyResponse emailResponse =
                await this.EmailServiceProxy.SendEmail(messageId, fromAddress, toAddresses, subject, body, isHtml, cancellationToken);

            // response message from provider (record event)
            emailAggregate.ReceiveResponseFromProvider(emailResponse.RequestIdentifier, emailResponse.EmailIdentifier);

            // Save Changes to persistance
            await this.EmailAggregateRepository.SaveChanges(emailAggregate, cancellationToken);
        }
Beispiel #2
0
 public bool Send(EmailAggregate email)
 {
     _validator.ValidateAndThrow(email);
     _emailSenderService.Send(email);
     email.SetEmailStatus(EmailStatus.Sent);
     _repository.Save(email);
     return(true);
 }
Beispiel #3
0
        public static EmailAggregate GetSentEmailAggregate()
        {
            EmailAggregate emailAggregate = new EmailAggregate();

            emailAggregate.SendRequestToProvider(TestData.FromAddress, TestData.ToAddresses, TestData.Subject,
                                                 TestData.Body, TestData.IsHtmlTrue);
            emailAggregate.ReceiveResponseFromProvider(TestData.ProviderRequestReference, TestData.ProviderEmailReference);
            return(emailAggregate);
        }
Beispiel #4
0
        public void OneTimeSetUp()
        {
            _fixture = new Fixture();
            EmailAggregate email = _fixture.Create <EmailAggregate>();

            //
            _repositoryMock.Setup(r => r.Get(It.IsAny <Guid>())).Returns(email);
            _emailSenderServiceMock.Setup(e => e.Send(It.IsAny <EmailAggregate>())).Verifiable();
            _validatorMock.Setup(v => v.Validate(It.IsAny <EmailAggregate>())).Returns(true);
        }
Beispiel #5
0
        public void Should_Set_Email_Status()
        {
            //Arrange
            EmailAggregate emailAggregate = _fixture.Create <EmailAggregate>();

            //Act
            emailAggregate.SetEmailStatus(Common.EmailStatus.Sent);

            //Assert
            Assert.True(emailAggregate.Status == Common.EmailStatus.Sent);
        }
Beispiel #6
0
        public void EmailAggregate_MarkMessageAsDelivered_MessageMarkedAsDelivered()
        {
            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.MarkMessageAsDelivered(TestData.ProviderStatusDescription, TestData.DeliveredDateTime);

            emailAggregate.MessageStatus.ShouldBe(MessageStatus.Delivered);
        }
Beispiel #7
0
        public void EmailAggregate_ReceiveResponseFromProvider_ResponseReceived()
        {
            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.ProviderRequestReference.ShouldBe(TestData.ProviderRequestReference);
            emailAggregate.ProviderEmailReference.ShouldBe(TestData.ProviderEmailReference);
            emailAggregate.MessageStatus.ShouldBe(MessageStatus.Sent);
        }
Beispiel #8
0
        public void Should_Save_Email()
        {
            //Arrange
            _emailService = new EmailService(_repositoryMock.Object, _emailSenderServiceMock.Object, _validatorMock.Object);
            EmailAggregate emailAggregate = _fixture.Create <EmailAggregate>();
            //Act
            Guid     id         = _emailService.Save(emailAggregate);
            EmailDto savedEmail = _emailService.Get(id);

            //Assert
            Assert.IsNotNull(savedEmail);
        }
Beispiel #9
0
        public void EmailAggregate_SendRequestToProvider_RequestSent()
        {
            EmailAggregate emailAggregate = EmailAggregate.Create(TestData.MessageId);

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

            emailAggregate.FromAddress.ShouldBe(TestData.FromAddress);
            emailAggregate.Subject.ShouldBe(TestData.Subject);
            emailAggregate.Body.ShouldBe(TestData.Body);
            emailAggregate.IsHtml.ShouldBe(TestData.IsHtmlTrue);
            emailAggregate.MessageStatus.ShouldBe(MessageStatus.InProgress);
            // TODO: Get Recipients
        }
Beispiel #10
0
        public void EmailAggregate_SendRequestToProvider_RequestAlreadySent_ErrorThrown()
        {
            EmailAggregate emailAggregate = EmailAggregate.Create(TestData.MessageId);

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

            Should.Throw <InvalidOperationException>(() =>
            {
                emailAggregate.SendRequestToProvider(TestData.FromAddress,
                                                     TestData.ToAddresses,
                                                     TestData.Subject,
                                                     TestData.Body,
                                                     TestData.IsHtmlTrue);
            });
        }
Beispiel #11
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);
        }
Beispiel #12
0
        public void EmailAggregate_MarkMessageAsDelivered_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.MarkMessageAsDelivered(TestData.ProviderStatusDescription, TestData.DeliveredDateTime);
            });
        }
Beispiel #13
0
        public async Task <ActionResult <string> > Email(EmailRequest request)
        {
            EmailAggregate email = new EmailAggregate(request.Recipients, request.Sender, (EmailPriority)request.Priority, request.Message, request.Subject);

            return(Accepted(await Task.FromResult(_emailService.Save(email))));
        }
Beispiel #14
0
        public void EmailAggregate_CanBeCreated_IsCreated()
        {
            EmailAggregate emailAggregate = EmailAggregate.Create(TestData.MessageId);

            emailAggregate.MessageId.ShouldBe(TestData.MessageId);
        }
Beispiel #15
0
        public static EmailAggregate GetEmptyEmailAggregate()
        {
            EmailAggregate emailAggregate = new EmailAggregate();

            return(emailAggregate);
        }
Beispiel #16
0
 public void Send(EmailAggregate email)
 {
     throw new NotImplementedException();
 }
Beispiel #17
0
        public void Send(EmailAggregate email)
        {
            MailMessage message = new MailMessage(email.Sender, "test", email.Subject, email.Message);

            _smtpServer.Send(message);
        }
Beispiel #18
0
 public Guid Save(EmailAggregate email)
 {
     _validator.ValidateAndThrow(email);
     return(_repository.Save(email).Id);
 }