-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/247-object-for-return
- Loading branch information
Showing
5 changed files
with
62 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -181,8 +181,19 @@ public async Task Post_ServiceReturnsError_ServerError() | |
public async Task Post_ServiceReturnsOrder_Accepted() | ||
{ | ||
// Arrange | ||
string expectedFromAddress = "[email protected]"; | ||
|
||
Mock<IEmailNotificationOrderService> serviceMock = new(); | ||
serviceMock.Setup(s => s.RegisterEmailNotificationOrder(It.IsAny<NotificationOrderRequest>())) | ||
.Callback<NotificationOrderRequest>(orderRequest => | ||
{ | ||
var emailTemplate = orderRequest.Templates | ||
.OfType<EmailTemplate>() | ||
.FirstOrDefault(); | ||
|
||
Assert.NotNull(emailTemplate); | ||
Assert.Equal(expectedFromAddress, emailTemplate.FromAddress); | ||
}) | ||
.ReturnsAsync((_order, null)); | ||
|
||
HttpClient client = GetTestClient(orderService: serviceMock.Object); | ||
|
@@ -207,6 +218,54 @@ public async Task Post_ServiceReturnsOrder_Accepted() | |
serviceMock.VerifyAll(); | ||
} | ||
|
||
[Fact] | ||
public async Task Post_OrderWithoutFromAddress_StringEmptyUsedAsServiceInput_Accepted() | ||
{ | ||
// Arrange | ||
Mock<IEmailNotificationOrderService> serviceMock = new(); | ||
|
||
serviceMock.Setup(s => s.RegisterEmailNotificationOrder(It.IsAny<NotificationOrderRequest>())) | ||
.Callback<NotificationOrderRequest>(orderRequest => | ||
{ | ||
var emailTemplate = orderRequest.Templates | ||
.OfType<EmailTemplate>() | ||
.FirstOrDefault(); | ||
|
||
Assert.NotNull(emailTemplate); | ||
Assert.Empty(emailTemplate.FromAddress); | ||
}) | ||
.ReturnsAsync((_order, null)); | ||
|
||
HttpClient client = GetTestClient(orderService: serviceMock.Object); | ||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", PrincipalUtil.GetOrgToken("ttd")); | ||
|
||
EmailNotificationOrderRequestExt request = new() | ||
{ | ||
Body = "email-body", | ||
ContentType = EmailContentType.Html, | ||
Recipients = new List<RecipientExt>() { new RecipientExt() { EmailAddress = "[email protected]" }, new RecipientExt() { EmailAddress = "[email protected]" } }, | ||
SendersReference = "senders-reference", | ||
RequestedSendTime = DateTime.UtcNow, | ||
Subject = "email-subject", | ||
}; | ||
|
||
HttpRequestMessage httpRequestMessage = new(HttpMethod.Post, _basePath) | ||
{ | ||
Content = new StringContent(request.Serialize(), Encoding.UTF8, "application/json") | ||
}; | ||
|
||
// Act | ||
HttpResponseMessage response = await client.SendAsync(httpRequestMessage); | ||
string actualOrderId = await response.Content.ReadAsStringAsync(); | ||
|
||
// Assert | ||
Assert.Equal(HttpStatusCode.Accepted, response.StatusCode); | ||
Assert.Equal("http://localhost:5090/notifications/api/v1/orders/" + _order.Id, response.Headers?.Location?.ToString()); | ||
Assert.Equal($"{_order.Id}", actualOrderId); | ||
|
||
serviceMock.VerifyAll(); | ||
} | ||
|
||
private HttpClient GetTestClient(IValidator<EmailNotificationOrderRequestExt>? validator = null, IEmailNotificationOrderService? orderService = null) | ||
{ | ||
if (validator == null) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,21 +71,6 @@ public void Validate_SendTimePassed_ReturnsFalse() | |
Assert.Contains(actual.Errors, a => a.ErrorMessage.Equals("Send time must be in the future. Leave blank to send immediately.")); | ||
} | ||
|
||
[Fact] | ||
public void Validate_FromAddressMissing_ReturnsFalse() | ||
{ | ||
var order = new EmailNotificationOrderRequestExt() | ||
{ | ||
Subject = "This is an email subject", | ||
Recipients = new List<RecipientExt>() { new RecipientExt() { Id = "16069412345", EmailAddress = "[email protected]" } }, | ||
Body = "This is an email body" | ||
}; | ||
|
||
var actual = _validator.Validate(order); | ||
Assert.False(actual.IsValid); | ||
Assert.Contains(actual.Errors, a => a.ErrorMessage.Equals("'From Address' must not be empty.")); | ||
} | ||
|
||
[Fact] | ||
public void Validate_SubjectMissing_ReturnsFalse() | ||
{ | ||
|