From c66773921fb73f8692b8e25c28b437e38d3459a8 Mon Sep 17 00:00:00 2001 From: nbitounis Date: Tue, 2 Jun 2020 17:48:45 +0300 Subject: [PATCH] The service can now receive bounce events. --- .../Factories/DbSesBounceEventFactory.cs | 32 +++++++++++++++++ .../Models/SesBounceEvent.cs | 12 +++++++ .../Models/SesBounceEventModel.cs | 8 +++++ .../Services/Interfaces/ISearchService.cs | 1 + .../Services/NotificationService.cs | 15 ++++++++ .../Services/SearchService.cs | 10 ++++++ .../Factories/DbSesBounceEventFactoryTests.cs | 31 ++++++++++++++++ .../Helpers/TestHelpers.cs | 18 ++++++++++ .../Services/NotificationServiceTests.cs | 36 ++++++++++++++----- .../Services/SearchServiceTests.cs | 10 +++--- 10 files changed, 160 insertions(+), 13 deletions(-) create mode 100644 Projects/SesNotifications.App/Factories/DbSesBounceEventFactory.cs create mode 100644 Projects/SesNotifications.App/Models/SesBounceEvent.cs create mode 100644 Projects/SesNotifications.App/Models/SesBounceEventModel.cs create mode 100644 Tests/SesNotifications.App.Tests/Factories/DbSesBounceEventFactoryTests.cs diff --git a/Projects/SesNotifications.App/Factories/DbSesBounceEventFactory.cs b/Projects/SesNotifications.App/Factories/DbSesBounceEventFactory.cs new file mode 100644 index 0000000..12c303e --- /dev/null +++ b/Projects/SesNotifications.App/Factories/DbSesBounceEventFactory.cs @@ -0,0 +1,32 @@ +using SesNotifications.App.Models; +using System; +using System.Linq; +using SesBounceEvent = SesNotifications.DataAccess.Entities.SesBounceEvent; + +namespace SesNotifications.App.Factories +{ + public static class DbSesBounceEventFactory + { + public static SesBounceEvent Create(this SesBounceEventModel bounce, long notificationId) + { + return new SesBounceEvent + { + Id = notificationId, + NotificationId = notificationId, + NotificationType = "Bounce", + SentAt = Convert.ToDateTime(bounce.Mail.Timestamp), + MessageId = bounce.Mail.MessageId, + Source = bounce.Mail.Source, + SourceArn = bounce.Mail.SourceArn, + SourceIp = bounce.Mail.SourceIp, + SendingAccountId = bounce.Mail.SendingAccountId, + BounceType = bounce.Bounce.BounceType, + BounceSubType = bounce.Bounce.BounceSubType, + CreatedAt = Convert.ToDateTime(bounce.Bounce.Timestamp), + FeedbackId = bounce.Bounce.FeedbackId, + ReportingMta = bounce.Bounce.ReportingMta, + BouncedRecipients = string.Join(',', bounce.Bounce.BouncedRecipients.Select(x => x.EmailAddress).ToArray()) + }; + } + } +} \ No newline at end of file diff --git a/Projects/SesNotifications.App/Models/SesBounceEvent.cs b/Projects/SesNotifications.App/Models/SesBounceEvent.cs new file mode 100644 index 0000000..0216bf1 --- /dev/null +++ b/Projects/SesNotifications.App/Models/SesBounceEvent.cs @@ -0,0 +1,12 @@ +namespace SesNotifications.App.Models +{ + public class SesBounceEvent + { + public virtual string BounceType { get; set; } + public virtual string BounceSubType { get; set; } + public virtual SesBouncedRecipient[] BouncedRecipients { get; set; } + public virtual string Timestamp { get; set; } + public virtual string FeedbackId { get; set; } + public virtual string ReportingMta { get; set; } + } +} \ No newline at end of file diff --git a/Projects/SesNotifications.App/Models/SesBounceEventModel.cs b/Projects/SesNotifications.App/Models/SesBounceEventModel.cs new file mode 100644 index 0000000..c47c502 --- /dev/null +++ b/Projects/SesNotifications.App/Models/SesBounceEventModel.cs @@ -0,0 +1,8 @@ +namespace SesNotifications.App.Models +{ + public class SesBounceEventModel : Ses + { + public virtual SesMail Mail { get; set; } + public virtual SesBounceEvent Bounce { get; set; } + } +} \ No newline at end of file diff --git a/Projects/SesNotifications.App/Services/Interfaces/ISearchService.cs b/Projects/SesNotifications.App/Services/Interfaces/ISearchService.cs index a910578..21301a6 100644 --- a/Projects/SesNotifications.App/Services/Interfaces/ISearchService.cs +++ b/Projects/SesNotifications.App/Services/Interfaces/ISearchService.cs @@ -14,6 +14,7 @@ public interface ISearchService IList FindOpenEvents(string email, DateTime start, DateTime end); IList FindSendEvents(string email, DateTime start, DateTime end); IList FindDeliveryEvents(string email, DateTime start, DateTime end); + IList FindBounceEventsEvents(string email, DateTime start, DateTime end); IList FindRaw(DateTime start, DateTime end); SesNotification FindRaw(long id); } diff --git a/Projects/SesNotifications.App/Services/NotificationService.cs b/Projects/SesNotifications.App/Services/NotificationService.cs index 3ee49e4..fb18691 100644 --- a/Projects/SesNotifications.App/Services/NotificationService.cs +++ b/Projects/SesNotifications.App/Services/NotificationService.cs @@ -24,6 +24,7 @@ public class NotificationService : INotificationService private readonly ISesOpensEventsRepository _sesOpensEventsRepository; private readonly ISesSendEventsRepository _sesSendEventsRepository; private readonly ISesDeliveryEventsRepository _sesDeliveryEventsRepository; + private readonly ISesBounceEventsRepository _sesBounceEventsRepository; private readonly ILogger _logger; public NotificationService(INotificationsRepository notificationsRepository, @@ -33,6 +34,7 @@ public NotificationService(INotificationsRepository notificationsRepository, ISesOpensEventsRepository sesOpensEventsRepository, ISesSendEventsRepository sesSendEventsRepository, ISesDeliveryEventsRepository sesDeliveryEventsRepository, + ISesBounceEventsRepository sesBounceEventsRepository, ILogger logger) { _notificationsRepository = notificationsRepository; @@ -43,6 +45,7 @@ public NotificationService(INotificationsRepository notificationsRepository, _sesSendEventsRepository = sesSendEventsRepository; _sesDeliveriesRepository = sesDeliveriesRepository; _sesDeliveryEventsRepository = sesDeliveryEventsRepository; + _sesBounceEventsRepository = sesBounceEventsRepository; _logger = logger; } @@ -101,12 +104,24 @@ private void HandleNotificationInternal(string content) case Delivery: HandleDeliveryEvent(content); break; + case Bounce: + HandleBounceEvent(content); + break; default: throw new NotSupportedException($"Unsupported message {content.Substring(0, 50)}..."); } } } + private void HandleBounceEvent(string content) + { + var bounceEvent = JsonConvert.DeserializeObject(content); + + var notification = SaveNotification(bounceEvent.Mail, content); + + _sesBounceEventsRepository.Save(bounceEvent.Create(notification.Id)); + } + private void HandleDeliveryEvent(string content) { var delivery = JsonConvert.DeserializeObject(content); diff --git a/Projects/SesNotifications.App/Services/SearchService.cs b/Projects/SesNotifications.App/Services/SearchService.cs index 27e509e..61c455a 100644 --- a/Projects/SesNotifications.App/Services/SearchService.cs +++ b/Projects/SesNotifications.App/Services/SearchService.cs @@ -18,6 +18,7 @@ public class SearchService : ISearchService private readonly ISesOpensEventsRepository _sesOpensEventsRepository; private readonly ISesSendEventsRepository _sesSendEventsRepository; private readonly ISesDeliveryEventsRepository _sesDeliveryEventsRepository; + private readonly ISesBounceEventsRepository _sesBounceEventsRepository; private readonly ILogger _logger; public SearchService(INotificationsRepository notificationsRepository, @@ -27,6 +28,7 @@ public SearchService(INotificationsRepository notificationsRepository, ISesOpensEventsRepository sesOpensEventsRepository, ISesSendEventsRepository sesSendEventsRepository, ISesDeliveryEventsRepository sesDeliveryEventsRepository, + ISesBounceEventsRepository sesBounceEventsRepository, ILogger logger) { _notificationsRepository = notificationsRepository; @@ -36,6 +38,7 @@ public SearchService(INotificationsRepository notificationsRepository, _sesOpensEventsRepository = sesOpensEventsRepository; _sesSendEventsRepository = sesSendEventsRepository; _sesDeliveryEventsRepository = sesDeliveryEventsRepository; + _sesBounceEventsRepository = sesBounceEventsRepository; _logger = logger; } @@ -81,6 +84,13 @@ public IList FindDeliveryEvents(string email, DateTime start, : _sesDeliveryEventsRepository.FindByRecipientAndSentDateRange($"%{email}%", start, end); } + public IList FindBounceEventsEvents(string email, DateTime start, DateTime end) + { + return string.IsNullOrEmpty(email) + ? _sesBounceEventsRepository.FindBySentDateRange(start, end) + : _sesBounceEventsRepository.FindByRecipientAndSentDateRange($"%{email}%", start, end); + } + public IList FindRaw(DateTime start, DateTime end) { return _notificationsRepository.FindBySentDateRange(start, end); diff --git a/Tests/SesNotifications.App.Tests/Factories/DbSesBounceEventFactoryTests.cs b/Tests/SesNotifications.App.Tests/Factories/DbSesBounceEventFactoryTests.cs new file mode 100644 index 0000000..319c034 --- /dev/null +++ b/Tests/SesNotifications.App.Tests/Factories/DbSesBounceEventFactoryTests.cs @@ -0,0 +1,31 @@ +using System; +using System.Linq; +using SesNotifications.App.Factories; +using SesNotifications.App.Tests.Helpers; +using Xunit; + +namespace SesNotifications.App.Tests.Factories +{ + public class DbSesBounceEventFactoryTests + { + [Fact] + public void Verify() + { + var dt = DateTime.UtcNow; + var bounce = TestHelpers.GetSesBounceEventModel(dt); + + var sesBounce = bounce.Create(1); + + Assert.Equal(sesBounce.BouncedRecipients, string.Join(',', bounce.Bounce.BouncedRecipients.Select(x => x.EmailAddress).ToArray())); + Assert.Equal(sesBounce.BounceSubType, bounce.Bounce.BounceSubType); + Assert.Equal(sesBounce.BounceType, bounce.Bounce.BounceType); + Assert.Equal(sesBounce.CreatedAt.Iso8601(), dt.Iso8601()); + Assert.Equal(sesBounce.FeedbackId, bounce.Bounce.FeedbackId); + Assert.Equal(sesBounce.ReportingMta, bounce.Bounce.ReportingMta); + Assert.Equal(sesBounce.SourceArn, bounce.Mail.SourceArn); + Assert.Equal(sesBounce.NotificationType, bounce.NotificationType); + Assert.Equal(1, sesBounce.NotificationId); + Assert.Equal(sesBounce.MessageId, bounce.Mail.MessageId); + } + } +} diff --git a/Tests/SesNotifications.App.Tests/Helpers/TestHelpers.cs b/Tests/SesNotifications.App.Tests/Helpers/TestHelpers.cs index fa74150..bd1cc6b 100644 --- a/Tests/SesNotifications.App.Tests/Helpers/TestHelpers.cs +++ b/Tests/SesNotifications.App.Tests/Helpers/TestHelpers.cs @@ -90,6 +90,24 @@ public static SesBounceModel GetSesBounceModel(DateTime dt) }; } + public static SesBounceEventModel GetSesBounceEventModel(DateTime dt) + { + return new SesBounceEventModel + { + NotificationType = "Bounce", + Mail = GetSesMail(dt), + Bounce = new SesBounceEvent + { + BouncedRecipients = new[] { new SesBouncedRecipient { EmailAddress = "address" } }, + ReportingMta = null, + BounceSubType = "bounce_sub_type", + Timestamp = dt.Iso8601(), + FeedbackId = "feedback_id", + BounceType = "bounce_type" + } + }; + } + public static SesOpenEventModel GetSesOpenModel(DateTime dt) { return new SesOpenEventModel diff --git a/Tests/SesNotifications.App.Tests/Services/NotificationServiceTests.cs b/Tests/SesNotifications.App.Tests/Services/NotificationServiceTests.cs index 7817c53..d1a004a 100644 --- a/Tests/SesNotifications.App.Tests/Services/NotificationServiceTests.cs +++ b/Tests/SesNotifications.App.Tests/Services/NotificationServiceTests.cs @@ -22,7 +22,7 @@ public void VerifyDelivery() mockSesDeliveries.Setup(x => x.Save(It.IsAny())); var service = new NotificationService(mockNotifications.Object, null, null, mockSesDeliveries.Object, - null, null, null, mockLogger.Object); + null, null, null, null, mockLogger.Object); service.HandleNotification(Delivery); @@ -41,7 +41,7 @@ public void VerifyBounce() mockSesBounces.Setup(x => x.Save(It.IsAny())); var service = new NotificationService(mockNotifications.Object, mockSesBounces.Object, null, null, - null, null, null, mockLogger.Object); + null, null, null, null, mockLogger.Object); service.HandleNotification(Bounce); @@ -60,7 +60,7 @@ public void VerifyComplaints() mockSesComplaints.Setup(x => x.Save(It.IsAny())); var service = new NotificationService(mockNotifications.Object, null, mockSesComplaints.Object, null, - null, null, null, mockLogger.Object); + null, null, null, null, mockLogger.Object); service.HandleNotification(Complaint); @@ -79,7 +79,7 @@ public void VerifyOpenEvents() mockSesOpens.Setup(x => x.Save(It.IsAny())); var service = new NotificationService(mockNotifications.Object, null, null, null, - mockSesOpens.Object, null, null, mockLogger.Object); + mockSesOpens.Object, null, null, null, mockLogger.Object); service.HandleNotification(OpenEvent); @@ -98,7 +98,7 @@ public void VerifySendEvents() mockSesSends.Setup(x => x.Save(It.IsAny())); var service = new NotificationService(mockNotifications.Object, null, null, null, - null, mockSesSends.Object, null, mockLogger.Object); + null, mockSesSends.Object, null, null, mockLogger.Object); service.HandleNotification(SendEvent); @@ -117,7 +117,7 @@ public void VerifyDeliveryEvents() mockSesDeliveries.Setup(x => x.Save(It.IsAny())); var service = new NotificationService(mockNotifications.Object, null, null, null, - null, null, mockSesDeliveries.Object, mockLogger.Object); + null, null, mockSesDeliveries.Object, null, mockLogger.Object); service.HandleNotification(DeliveryEvent); @@ -125,12 +125,31 @@ public void VerifyDeliveryEvents() mockSesDeliveries.Verify(x => x.Save(It.IsAny()), Times.Exactly(1)); } + [Fact] + public void VerifyBounceEvents() + { + var mockNotifications = new Mock(MockBehavior.Strict); + var mockSesBounceEvents = new Mock(MockBehavior.Strict); + var mockLogger = new Mock>(MockBehavior.Loose); + + mockNotifications.Setup(x => x.Save(It.IsAny())); + mockSesBounceEvents.Setup(x => x.Save(It.IsAny())); + + var service = new NotificationService(mockNotifications.Object, null, null, null, + null, null, null, mockSesBounceEvents.Object, mockLogger.Object); + + service.HandleNotification(BounceEvent); + + mockNotifications.Verify(x => x.Save(It.IsAny()), Times.Exactly(1)); + mockSesBounceEvents.Verify(x => x.Save(It.IsAny()), Times.Exactly(1)); + } + [Fact] public void VerifyInvalidException() { var mockLogger = new Mock>(MockBehavior.Loose); - var service = new NotificationService(null, null, null, null, null, null, null, mockLogger.Object); + var service = new NotificationService(null, null, null, null, null, null, null, null, mockLogger.Object); Assert.Throws(() => service.HandleNotification(NotJson)); } @@ -140,7 +159,7 @@ public void VerifyUnsupportedException() { var mockLogger = new Mock>(MockBehavior.Loose); - var service = new NotificationService(null, null, null, null, null, null, null, mockLogger.Object); + var service = new NotificationService(null, null, null, null, null, null, null, null, mockLogger.Object); Assert.Throws(() => service.HandleNotification(Invalid)); } @@ -152,6 +171,7 @@ public void VerifyUnsupportedException() private const string OpenEvent = "{\"eventType\": \"open\",\"mail\": {\"timestamp\": \"2020-05-08T08:42:19.146Z\",\"source\": \"d.test+python@test.gr\",\"sendingAccountId\": \"257120724488\",\"messageId\": \"01070171f3731a8a-8ab938e9-787d-4165-b967-fdb2abec1fc7-000000\",\"destination\": [\"mr.test@gmail.com\"],\"headersTruncated\": false,\"headers\": [{\"name\": \"Received\",\"value\": \"from [127.0.1.1] ([11.111.111.68]) by email-smtp.amazonaws.com with SMTP (SimpleEmailService-d-GG6TMY8U3) id 4E25Kp3rgG6djvRHUmZH for mr.test@gmail.com; Fri, 08 May 2020 08:42:19 +0000 (UTC)\"},{\"name\": \"Content-Type\",\"value\": \"multipart/alternative\"},{\"name\": \"MIME-Version\",\"value\": \"1.0\"},{\"name\": \"Subject\",\"value\": \"Amazon SES Test (Python smtplib) staging\"},{\"name\": \"From\",\"value\": \"Dimos Python script \"},{\"name\": \"To\",\"value\": \"mr.test@gmail.com\"},{\"name\": \"X-SES-CONFIGURATION-SET\",\"value\": \"ses-to-sqs\"},{\"name\": \"Message-ID\",\"value\": \"null\"}],\"commonHeaders\": {\"from\": [\"Dimos Python script \"],\"to\": [\"mr.test@gmail.com\"],\"messageId\": \"01070171f3731a8a-8ab938e9-787d-4165-b967-fdb2abec1fc7-000000\",\"subject\": \"Amazon SES Test (Python smtplib) staging\"},\"tags\": {\"ses:operation\": [\"SendSmtpEmail\"],\"ses:configuration-set\": [\"ses-to-sqs\"],\"ses:source-ip\": [\"11.111.112.61\"],\"ses:from-domain\": [\"test.gr\"],\"ses:caller-identity\": [\"ses-smtp-notificator\"]}},\"open\": {\"timestamp\": \"2020-05-08T08:56:46.917Z\",\"userAgent\": \"Mozilla/5.0 (Windows NT 5.1; rv:11.0) Gecko Firefox/11.0 (via ggpht.com GoogleImageProxy)\",\"ipAddress\": \"11.111.11.111\"}}"; private const string SendEvent = "{\"eventType\":\"send\",\"mail\":{\"timestamp\":\"2020-05-29T15:26:26.221Z\",\"source\":\"tester+python@xe.gr\",\"sourceArn\":\"arn:aws:ses:eu-central-1:234567890:identity/test.com\",\"sendingAccountId\":\"234567890\",\"messageId\":\"01070172610aa1ad-ffae92b5-dd4d-42e5-aa72-e75d9cd4a995-000000\",\"destination\":[\"tester@gmail.com\"],\"headersTruncated\":false,\"headers\":[{\"name\":\"Received\",\"value\":\"from [127.0.1.1] (ppp-12-34-56-78.home.test.com [12.34.567.222]) by email-smtp.amazonaws.com with SMTP (SimpleEmailService-d-32P1K87U3) id f4qxpujfRBhaohG8QqoE for test@gmail.com; Fri, 29 May 2020 15:26:26 +0000 (UTC)\"},{\"name\":\"Content-Type\",\"value\":\"multipart/alternative; boundary=1497643119139888747\"},{\"name\":\"MIME-Version\",\"value\":\"1.0\"},{\"name\":\"Subject\",\"value\":\"Amazon SES Test (Python smtplib) prod with configset\"},{\"name\":\"From\",\"value\":\"Python script \"},{\"name\":\"To\",\"value\":\"tester@gmail.com\"},{\"name\":\"X-SES-CONFIGURATION-SET\",\"value\":\"ses-events\"}],\"commonHeaders\":{\"from\":[\"Python script \"],\"to\":[\"tester@gmail.com\"],\"messageId\":\"01070172610aa1ad-ffae92b5-dd4d-42e5-aa72-e75d9cd4a995-000000\",\"subject\":\"Amazon SES Test (Python smtplib) prod with configset\"},\"tags\":{\"ses:operation\":[\"SendSmtpEmail\"],\"ses:configuration-set\":[\"ses-events\"],\"ses:source-ip\":[\"12.34.567.156\"],\"ses:from-domain\":[\"test.com\"],\"ses:caller-identity\":[\"ses-smtp-notificator\"]}},\"send\":{}}"; private const string DeliveryEvent = "{\"eventType\": \"Delivery\",\"mail\": {\"timestamp\": \"2020-05-29T15:26:26.221Z\",\"source\": \"test+python@test.com\",\"sourceArn\": \"arn:aws:ses:eu-central-1:1234567:identity/test.com\",\"sendingAccountId\": \"1234567\",\"messageId\": \"01070172610aa1ad-ffae92b5-dd4d-42e5-aa72-e75d9cd4a995-000000\",\"destination\": [\"tester@gmail.com\"],\"headersTruncated\": false,\"headers\": [{\"name\": \"Received\",\"value\": \"from [127.0.1.1] (ppp-12-34-56-156.home.test.gr [12.34.56.156]) by email-smtp.amazonaws.com with SMTP (SimpleEmailService-d-32P1K87U3) id f4qxpujfRBhaohG8QqoE for tester@gmail.com; Fri, 29 May 2020 15:26:26 +0000 (UTC)\"},{\"name\": \"Content-Type\",\"value\": \"multipart/alternative; boundary=\"},{\"name\": \"MIME-Version\",\"value\": \"1.0\"},{\"name\": \"Subject\",\"value\": \"Amazon SES Test (Python smtplib) prod with configset\"},{\"name\": \"From\",\"value\": \"Python script \"},{\"name\": \"To\",\"value\": \"tester@gmail.com\"},{\"name\": \"X-SES-CONFIGURATION-SET\",\"value\": \"ses-events\"}],\"commonHeaders\": {\"from\": [\"Python script \"],\"to\": [\"tester@gmail.com\"],\"messageId\": \"01070172610aa1ad-ffae92b5-dd4d-42e5-aa72-e75d9cd4a995-000000\",\"subject\": \"Amazon SES Test (Python smtplib) prod with configset\"},\"tags\": {\"ses:operation\": [\"SendSmtpEmail\"],\"ses:configuration-set\": [\"ses-events\"],\"ses:source-ip\": [\"12.34.56.156\"],\"ses:from-domain\": [\"test.com\"],\"ses:caller-identity\": [\"ses-smtp-notificator\"],\"ses:outgoing-ip\": [\"12.34.56.14\"]}},\"delivery\": {\"timestamp\": \"2020-05-29T15:26:27.213Z\",\"processingTimeMillis\": 992,\"recipients\": [\"tester@gmail.com\"],\"smtpResponse\": \"250 2.0.0 OK 1590765987 s15si9015272wru.411 - gsmtp\",\"reportingMTA\": \"b224-14.smtp-out.eu-central-1.amazonses.com\"}}"; + private const string BounceEvent = "{\"eventType\": \"Bounce\",\"bounce\": {\"bounceType\": \"Permanent\",\"bounceeventsubType\": \"General\",\"bouncedRecipients\": [{\"emailAddress\": \"test@yahoo.com\",\"action\": \"failed\",\"status\": \"5.3.0\",\"diagnosticCode\": \"smtp; 554 delivery error: dd Not a valid recipient - atlas315.free.mail.gq1.yahoo.com\"}],\"timestamp\": \"2020-06-02T08:04:52.060Z\",\"feedbackId\": \"01070172740fcbc1-cc43bef4-eaf5-460b-aa47-41910ab05099-000000\",\"reportingMTA\": \"dsn; b224-14.smtp-out.eu-central-1.amazonses.com\"},\"mail\": {\"timestamp\": \"2020-06-02T08:04:46.772Z\",\"source\": \"test@test.gr\",\"sourceArn\": \"arn:aws:ses:eu-central-1:1234:test/test.gr\",\"sendingAccountId\": \"1234\",\"messageId\": \"01070172740fb834-c0f58d01-b6f6-458f-89a2-7694aea437b2-000000\",\"destination\": [\"test@yahoo.com\"],\"headersTruncated\": false,\"headers\": [{\"name\": \"Received\",\"value\": \"from null (ec2-52-29-236-139.eu-central-1.compute.amazonaws.com [12.34.56.139]) by email-smtp.amazonaws.com with SMTP (SimpleEmailService-d-XP34IN8U3) id JFiE9K60L712ZGOWfPoE for test@yahoo.com; Tue, 02 Jun 2020 08:04:46 +0000 (UTC)\"},{\"name\": \"Date\",\"value\": \"Tue, 2 Jun 2020 11:04:46 +0300 (EEST)\"},{\"name\": \"From\",\"value\": \"test.gr \"},{\"name\": \"Reply-To\",\"value\": \"test.gr \"},{\"name\": \"To\",\"value\": \"test@yahoo.com\"},{\"name\": \"Message-ID\",\"value\": \"<1900819414.290.1591085086760@ip-10-200-12-205.eu-central-1.compute.internal>\"},{\"name\": \"Subject\",\"value\": \"Test\"},{\"name\": \"MIME-Version\",\"value\": \"1.0\"},{\"name\": \"Content-Type\",\"value\": \"multipart/mixed; boundary\"},{\"name\": \"X-SES-CONFIGURATION-SET\",\"value\": \"ses-events\"}],\"commonHeaders\": {\"from\": [\"test.gr \"],\"replyTo\": [\"test.gr \"],\"date\": \"Tue, 2 Jun 2020 11:04:46 +0300 (EEST)\",\"to\": [\"test@yahoo.com\"],\"messageId\": \"01070172740fb834-c0f58d01-b6f6-458f-89a2-7694aea437b2-000000\",\"subject\": \"test\"},\"tags\": {\"ses:operation\": [\"SendSmtpEmail\"],\"ses:configuration-set\": [\"ses-events\"],\"ses:source-ip\": [\"12.34.56.139\"],\"ses:from-domain\": [\"test.gr\"],\"ses:caller-identity\": [\"ses-smtp-notificator\"]}}}"; private const string Invalid = "{ \"notificationType\":\"SomethingElse\", \"mail\":{ \"timestamp\":\"2016-01-27T14:59:38.237Z\", \"messageId\":\"0000014644fe5ef6-9a483358-9170-4cb4-a269-f5dcdf415321-000000\", \"source\":\"john@example.com\", \"sourceArn\": \"arn:aws:ses:us-west-2:888888888888:identity/example.com\", \"sourceIp\": \"127.0.3.0\", \"sendingAccountId\":\"123456789012\", \"destination\":[ \"jane@example.com\" ], \"headersTruncated\":false, \"headers\":[ { \"name\":\"From\", \"value\":\"\\\"John Doe\\\" \" }, { \"name\":\"To\", \"value\":\"\\\"Jane Doe\\\" \" }, { \"name\":\"Message-ID\", \"value\":\"custom-message-ID\" }, { \"name\":\"Subject\", \"value\":\"Hello\" }, { \"name\":\"Content-Type\", \"value\":\"text/plain; charset=\\\"UTF-8\\\"\" }, { \"name\":\"Content-Transfer-Encoding\", \"value\":\"base64\" }, { \"name\":\"Date\", \"value\":\"Wed, 27 Jan 2016 14:58:45 +0000\" } ], \"commonHeaders\":{ \"from\":[ \"John Doe \" ], \"date\":\"Wed, 27 Jan 2016 14:58:45 +0000\", \"to\":[ \"Jane Doe \" ], \"messageId\":\"custom-message-ID\", \"subject\":\"Hello\" } }, \"delivery\":{ \"timestamp\":\"2016-01-27T14:59:38.237Z\", \"recipients\":[\"jane@example.com\"], \"processingTimeMillis\":546, \"reportingMTA\":\"a8-70.smtp-out.amazonses.com\", \"smtpResponse\":\"250 ok: Message 64111812 accepted\", \"remoteMtaIp\":\"127.0.2.0\" } }"; private const string NotJson = "some string"; } diff --git a/Tests/SesNotifications.App.Tests/Services/SearchServiceTests.cs b/Tests/SesNotifications.App.Tests/Services/SearchServiceTests.cs index 0c0ebf6..9431a32 100644 --- a/Tests/SesNotifications.App.Tests/Services/SearchServiceTests.cs +++ b/Tests/SesNotifications.App.Tests/Services/SearchServiceTests.cs @@ -25,7 +25,7 @@ public void VerifyFindDeliveries(string email, bool expectedMailQuery) var mockLogger = new Mock>(MockBehavior.Loose); var service = new SearchService(null, null, null, mockSesDeliveries.Object, null, null, null, - mockLogger.Object); + null, mockLogger.Object); service.FindDeliveries(email, DateTime.UtcNow.AddDays(-30), DateTime.UtcNow.AddDays(1)); @@ -50,7 +50,7 @@ public void VerifyFindBounces(string email, bool expectedMailQuery) var mockLogger = new Mock>(MockBehavior.Loose); var service = new SearchService(null, mockSesBounces.Object, null, null, null, null, null, - mockLogger.Object); + null, mockLogger.Object); service.FindBounces(email, DateTime.UtcNow.AddDays(-30), DateTime.UtcNow.AddDays(1)); @@ -75,7 +75,7 @@ public void VerifyFindComplaints(string email, bool expectedMailQuery) var mockLogger = new Mock>(MockBehavior.Loose); var service = new SearchService(null, null, mockSesComplaints.Object, null, null, null, null, - mockLogger.Object); + null, mockLogger.Object); service.FindComplaints(email, DateTime.UtcNow.AddDays(-30), DateTime.UtcNow.AddDays(1)); @@ -95,7 +95,7 @@ public void VerifyFindRaw() var mockLogger = new Mock>(MockBehavior.Loose); var service = new SearchService(mockNotifications.Object, null, null, null, null, null, null, - mockLogger.Object); + null, mockLogger.Object); service.FindRaw(DateTime.UtcNow.AddDays(-30), DateTime.UtcNow.AddDays(1)); @@ -110,7 +110,7 @@ public void VerifyFindOneRaw() var mockLogger = new Mock>(MockBehavior.Loose); var service = new SearchService(mockNotifications.Object, null, null, null, null, null, null, - mockLogger.Object); + null, mockLogger.Object); service.FindRaw(1);