public async Task MissingToken_Test() { var configuration = DictionaryReplacementNotificationContent.DefaultConfiguration; var tokenStart = configuration.TokenStart; var tokenEnd = configuration.TokenEnd; var template = new StringNotificationContent($"Hi {tokenStart}firstName{tokenEnd},\nYou have a thing due on {tokenStart}dueDate{tokenEnd}."); var replacements = new Dictionary <string, string> { ["dueDate"] = "20/4/2018", }; var expected = "Hi [INVALID_TOKEN:firstName],\nYou have a thing due on 20/4/2018."; var content = new DictionaryReplacementNotificationContent(configuration, template, replacements); using (var tw = new StringWriter()) { await content.ExecuteAsync(tw); var actual = tw.ToString(); Assert.Equal(expected, actual); } }
public async Task NestedTemplate_Test() { var configuration = DictionaryReplacementNotificationContent.DefaultConfiguration; var tokenStart = configuration.TokenStart; var tokenEnd = configuration.TokenEnd; var template = new StringNotificationContent($"Hi {tokenStart}name{tokenEnd},\nYou have a thing due on {tokenStart}dueDate{tokenEnd}."); var replacements = new Dictionary <string, string> { ["name"] = $"{tokenStart}currentUserFirstName{tokenEnd} {tokenStart}currentUserSurname{tokenEnd}", ["dueDate"] = "20/4/2018", ["currentUserFirstName"] = "Joe", ["currentUserSurname"] = "Bloggs", }; var expected = "Hi Joe Bloggs,\nYou have a thing due on 20/4/2018."; var content = new DictionaryReplacementNotificationContent(configuration, template, replacements); using (var tw = new StringWriter()) { await content.ExecuteAsync(tw); var actual = tw.ToString(); Assert.Equal(expected, actual); } }
public async Task DeliverSimpleEmail_Test() { var sender = new EmailNotificationContact("*****@*****.**", "Joe Bloggs"); var content = new StringNotificationContent("Hi Joe,\nYou have a thing due on 20/4/2018."); var notification = new Notification(sender, content); var notificationDelivery = new EmailNotificationDelivery(DateTimeOffset.Now, 3); notificationDelivery.Recipients.Add(new EmailNotificationContact("*****@*****.**", "Mary Jones")); var emailServiceMock = new Mock <IEmailService>(); emailServiceMock .Setup(m => m.DeliverAsync(It.IsAny <EmailNotificationContact>(), It.IsAny <EmailNotificationContact[]>(), It.IsAny <EmailNotificationContact[]>(), It.IsAny <EmailNotificationContact[]>(), It.IsAny <Stream>(), It.IsAny <NotificationAttachment[]>())) .Returns(() => { return(Task.FromResult(new EmailDeliveryResult { NotificationDeliveryResult = NotificationDeliveryResult.Delivered, ResultMessage = "OK" })); }); var emailDeliveryService = new EmailDeliveryService(emailServiceMock.Object); var attempt = await emailDeliveryService.DeliverAsync(notification, notificationDelivery); }
public async Task LotsOfSimpleTemplate_Test() { var configuration = DictionaryReplacementNotificationContent.DefaultConfiguration; var templateResult = this.Get_LotsOfSimpleTemplate_Test_Template(configuration); var template = new StringNotificationContent(templateResult.Item1); var replacements = templateResult.Item2; var expected = templateResult.Item3; var content = new DictionaryReplacementNotificationContent(configuration, template, replacements); using (var tw = new StringWriter()) { await content.ExecuteAsync(tw); var actual = tw.ToString(); Assert.Equal(expected, actual); } }