diff --git a/src/Altinn.Notifications.Core/Services/EmailOrderProcessingService.cs b/src/Altinn.Notifications.Core/Services/EmailOrderProcessingService.cs
index 54288bdd..dab28984 100644
--- a/src/Altinn.Notifications.Core/Services/EmailOrderProcessingService.cs
+++ b/src/Altinn.Notifications.Core/Services/EmailOrderProcessingService.cs
@@ -45,7 +45,12 @@ public async Task ProcessOrder(NotificationOrder order)
///
public async Task ProcessOrderWithoutAddressLookup(NotificationOrder order, List recipients)
{
- var emailTemplate = order.Templates[0] as EmailTemplate;
+ EmailTemplate? emailTemplate = null;
+ if (order.Templates.Count > 0)
+ {
+ emailTemplate = order.Templates[0] as EmailTemplate;
+ }
+
foreach (Recipient recipient in recipients)
{
await _emailService.CreateNotification(order.Id, order.RequestedSendTime, recipient, order.IgnoreReservation ?? false, emailTemplate?.Body, emailTemplate?.Subject);
@@ -66,7 +71,12 @@ public async Task ProcessOrderRetry(NotificationOrder order)
///
public async Task ProcessOrderRetryWithoutAddressLookup(NotificationOrder order, List recipients)
{
- var emailTemplate = order.Templates[0] as EmailTemplate;
+ EmailTemplate? emailTemplate = null;
+ if (order.Templates.Count > 0)
+ {
+ emailTemplate = order.Templates[0] as EmailTemplate;
+ }
+
List emailRecipients = await _emailNotificationRepository.GetRecipients(order.Id);
foreach (Recipient recipient in recipients)
diff --git a/test/Altinn.Notifications.Tests/Notifications.Core/TestingModels/NotificationOrderTests.cs b/test/Altinn.Notifications.Tests/Notifications.Core/TestingModels/NotificationOrderTests.cs
index 8cbe32c3..694e6b56 100644
--- a/test/Altinn.Notifications.Tests/Notifications.Core/TestingModels/NotificationOrderTests.cs
+++ b/test/Altinn.Notifications.Tests/Notifications.Core/TestingModels/NotificationOrderTests.cs
@@ -80,11 +80,11 @@ public NotificationOrderTests()
new JsonObject()
{
{ "$", "email" },
- { "type", "Email" },
+ { "body", "email-body" },
+ { "contentType", "Html" },
{ "fromAddress", "sender@domain.com" },
{ "subject", "email-subject" },
- { "body", "email-body" },
- { "contentType", "Html" }
+ { "type", "Email" }
}
}
},
@@ -93,12 +93,6 @@ public NotificationOrderTests()
{
new JsonObject()
{
- {
- "nationalIdentityNumber", "nationalidentitynumber"
- },
- {
- "isReserved", false
- },
{
"addressInfo", new JsonArray()
{
@@ -109,10 +103,16 @@ public NotificationOrderTests()
{ "emailAddress", "recipient1@domain.com" }
}
}
+ },
+ {
+ "isReserved", false
+ },
+ {
+ "nationalIdentityNumber", "nationalidentitynumber"
}
}
}
- }
+ }
}.ToJsonString();
}
diff --git a/test/Altinn.Notifications.Tests/Notifications.Core/TestingServices/EmailNotificationServiceTests.cs b/test/Altinn.Notifications.Tests/Notifications.Core/TestingServices/EmailNotificationServiceTests.cs
index 1dfc7996..d1b79c3e 100644
--- a/test/Altinn.Notifications.Tests/Notifications.Core/TestingServices/EmailNotificationServiceTests.cs
+++ b/test/Altinn.Notifications.Tests/Notifications.Core/TestingServices/EmailNotificationServiceTests.cs
@@ -8,6 +8,7 @@
using Altinn.Notifications.Core.Models;
using Altinn.Notifications.Core.Models.Address;
using Altinn.Notifications.Core.Models.Notification;
+using Altinn.Notifications.Core.Models.Recipients;
using Altinn.Notifications.Core.Persistence;
using Altinn.Notifications.Core.Services;
using Altinn.Notifications.Core.Services.Interfaces;
@@ -313,7 +314,9 @@ private static EmailNotificationService GetTestService(IEmailNotificationReposit
if (keywordsService == null)
{
- keywordsService = new Mock().Object;
+ var keywordsServiceMock = new Mock();
+ keywordsServiceMock.Setup(e => e.ReplaceKeywordsAsync(It.IsAny())).ReturnsAsync((EmailRecipient recipient) => recipient);
+ keywordsService = keywordsServiceMock.Object;
}
return new EmailNotificationService(guidService.Object, dateTimeService.Object, repo, producer, Options.Create(new KafkaSettings { EmailQueueTopicName = _emailQueueTopicName }), keywordsService);
diff --git a/test/Altinn.Notifications.Tests/Notifications.Core/TestingServices/SmsNotificationServiceTests.cs b/test/Altinn.Notifications.Tests/Notifications.Core/TestingServices/SmsNotificationServiceTests.cs
index 8d0f658d..de2f5a4e 100644
--- a/test/Altinn.Notifications.Tests/Notifications.Core/TestingServices/SmsNotificationServiceTests.cs
+++ b/test/Altinn.Notifications.Tests/Notifications.Core/TestingServices/SmsNotificationServiceTests.cs
@@ -8,6 +8,7 @@
using Altinn.Notifications.Core.Models;
using Altinn.Notifications.Core.Models.Address;
using Altinn.Notifications.Core.Models.Notification;
+using Altinn.Notifications.Core.Models.Recipients;
using Altinn.Notifications.Core.Persistence;
using Altinn.Notifications.Core.Services;
using Altinn.Notifications.Core.Services.Interfaces;
@@ -306,7 +307,9 @@ private static SmsNotificationService GetTestService(ISmsNotificationRepository?
if (keywordsService == null)
{
- keywordsService = new Mock().Object;
+ var keywordsServiceMock = new Mock();
+ keywordsServiceMock.Setup(e => e.ReplaceKeywordsAsync(It.IsAny())).ReturnsAsync((SmsRecipient recipient) => recipient);
+ keywordsService = keywordsServiceMock.Object;
}
return new SmsNotificationService(guidService.Object, dateTimeService.Object, repo, producer, Options.Create(new KafkaSettings { SmsQueueTopicName = _smsQueueTopicName }), keywordsService);