/// <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); }
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); }
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); }); }
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); }
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); }