public void NotificationMailFormatterNormal() { var notificationMailFormatter = new NotificationMailFormatter { Salutation = "John", TableTitle = "Table title", Template = "{TableTitle}|{Salutation}|{Items}" }; var items = new System.Collections.Generic.List <NotificationEntry> { new NotificationEntry() { Code = "Code 1", Description = "Description 1", Duedate = new System.DateTime(2021, 4, 3), Enddate = new System.DateTime(2021, 4, 3), ExpectedAction = "The action", ID = 1, NotificationType = "Contract", Salutation = "John", Startdate = new System.DateTime(2021, 4, 2), SubscriptionID = "*****@*****.**", URL = "http://www.google.com/" }, new NotificationEntry() { Code = "Code 2", Description = "Description 2", Duedate = new System.DateTime(2021, 4, 3), Enddate = new System.DateTime(2021, 4, 3), ExpectedAction = "The action", ID = 1, NotificationType = "Contract", Salutation = "John", Startdate = new System.DateTime(2021, 4, 2), SubscriptionID = "*****@*****.**", URL = "http://www.google.com/" } }; var message = notificationMailFormatter.FormatMessage(items); var messageParts = message.Split('|'); Assert.AreEqual("Table title", messageParts[0]); Assert.AreEqual("John", messageParts[1]); Assert.IsTrue(messageParts[2].Contains("Code 1")); Assert.IsTrue(messageParts[2].Contains("Code 2")); }
public void NotificationMailFormatterNoTemplate() { var notificationMailFormatter = new NotificationMailFormatter { Salutation = "John", TableTitle = "Table title" }; var items = new System.Collections.Generic.List <NotificationEntry> { new NotificationEntry() { Code = "Code 1", Description = "Description 1", Duedate = new System.DateTime(2021, 4, 3), Enddate = new System.DateTime(2021, 4, 3), ExpectedAction = "The action", ID = 1, NotificationType = "Contract", Salutation = "John", Startdate = new System.DateTime(2021, 4, 2), SubscriptionID = "*****@*****.**", URL = "http://www.google.com/" }, new NotificationEntry() { Code = "Code 2", Description = "Description 2", Duedate = new System.DateTime(2021, 4, 3), Enddate = new System.DateTime(2021, 4, 3), ExpectedAction = "The action", ID = 1, NotificationType = "Contract", Salutation = "John", Startdate = new System.DateTime(2021, 4, 2), SubscriptionID = "*****@*****.**", URL = "http://www.google.com/" } }; var message = notificationMailFormatter.FormatMessage(items); Assert.AreEqual(string.Empty, message); }
public void SendmailForJob(string subscriber, string subject, string title) { var allItems = new List <Models.NotificationEntry>(); GetItemsFromNotificationGroup(allItems, subscriber); var items = DBContext.NotificationEntries.Where(n => n.NotificationType == NotificationType && n.SubscriptionID == subscriber ); allItems.AddRange(items); items = allItems.AsQueryable() .OrderBy(n => n.Duedate) .ThenBy(n => n.Startdate) .ThenBy(n => n.Enddate); if (items.Any()) { Logger.LogDebug($"Found {items.Count()} {NotificationType} items for subscriber {subscriber}."); INotificationFormatter formatter = new NotificationMailFormatter { Template = MailTemplate, TableTitle = title, Salutation = items.First(n => !string.IsNullOrEmpty(n.Salutation))?.Salutation ?? "team member" }; var message = formatter.FormatMessage(items.ToList()); Transmitter.Recipient = subscriber; Transmitter.Transmit(subject, message); } else { Logger.LogInformation($"No {NotificationType} items for subscriber {subscriber}."); } }