Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions MessagingService.DataTransferObjects/SendEmailRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
public class SendEmailRequest
{
#region Properties

public Guid? MessageId { get; set; }

/// <summary>
/// Gets or sets the body.
Expand Down
19 changes: 19 additions & 0 deletions MessagingService.EmailAggregate.Tests/EmailAggregateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,27 @@ public void EmailAggregate_SendRequestToProvider_RequestSent()
emailAggregate.Subject.ShouldBe(TestData.Subject);
emailAggregate.Body.ShouldBe(TestData.Body);
emailAggregate.IsHtml.ShouldBe(TestData.IsHtmlTrue);
emailAggregate.MessageStatus.ShouldBe(MessageStatus.InProgress);
// TODO: Get Recipients
}

[Fact]
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);
});
}

[Fact]
public void EmailAggregate_ReceiveResponseFromProvider_ResponseReceived()
{
Expand All @@ -41,6 +59,7 @@ public void EmailAggregate_ReceiveResponseFromProvider_ResponseReceived()

emailAggregate.ProviderRequestReference.ShouldBe(TestData.ProviderRequestReference);
emailAggregate.ProviderEmailReference.ShouldBe(TestData.ProviderEmailReference);
emailAggregate.MessageStatus.ShouldBe(MessageStatus.Sent);
}

[Fact]
Expand Down
7 changes: 6 additions & 1 deletion MessagingService.EmailMessageAggregate/EmailAggregate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ public void SendRequestToProvider(String fromAddress,
String body,
Boolean isHtml)
{
if (this.MessageStatus != MessageStatus.NotSet)
{
throw new InvalidOperationException("Cannot send a message to provider that has already been sent");
}

RequestSentToProviderEvent requestSentToProviderEvent = RequestSentToProviderEvent.Create(this.AggregateId, fromAddress, toAddresses, subject, body, isHtml);

this.ApplyAndPend(requestSentToProviderEvent);
Expand Down Expand Up @@ -327,7 +332,7 @@ private void PlayEvent(RequestSentToProviderEvent domainEvent)
this.Subject = domainEvent.Subject;
this.IsHtml = domainEvent.IsHtml;
this.FromAddress = domainEvent.FromAddress;
this.MessageStatus = MessageStatus.NotSet;
this.MessageStatus = MessageStatus.InProgress;

foreach (String domainEventToAddress in domainEvent.ToAddresses)
{
Expand Down
2 changes: 2 additions & 0 deletions MessagingService.EmailMessageAggregate/MessageStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public enum MessageStatus
/// </summary>
NotSet = 0,

InProgress,

/// <summary>
/// The sent
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion MessagingService/Controllers/EmailController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public async Task<IActionResult> PostEmail([FromBody] SendEmailRequestDTO sendEm
return this.Forbid();
}

Guid messageId = Guid.NewGuid();
Guid messageId = sendEmailRequest.MessageId.HasValue ? sendEmailRequest.MessageId.Value : Guid.NewGuid();

// Create the command
SendEmailRequest request = SendEmailRequest.Create(sendEmailRequest.ConnectionIdentifier,
Expand Down