When_Create_Formatting_Comment_Is_Executed_And_Template_Content_Has_All_Parameters_Resolved_Then_Proper_Message_Is_Returned() { var template = new NotificationTemplateContent("test", Localization.Default, "content"); var result = _messageService.CreateFormattingComment(template); Assert.Contains("There were missing parameter values inside message:", result); }
public void CreateTemplate_UpdateContent() { var template = new NotificationTemplateContent("test", Localization.From("ru"), "Hello world"); Assert.Equal("Hello world", template.Content); Assert.Equal(0, template.Keys.Count); var text = "Hello ${PD::name}. Your code ${code}. Thank you ${PD::name}"; template.SetContent(text); Assert.Equal("test", template.Name); Assert.Equal("ru", template.Localization.ToString()); Assert.Equal(text, template.Content); Assert.Equal(2, template.Keys.Count); var key = template.Keys.FirstOrDefault(k => k.Key == "name"); Assert.NotNull(key); Assert.Equal("name", key.Key); Assert.Equal("PD", key.Namespace); key = template.Keys.FirstOrDefault(k => k.Key == "code"); Assert.NotNull(key); Assert.Equal("code", key.Key); Assert.Equal(string.Empty, key.Namespace); }
public void CreateTemplate_SimpleText() { var template = new NotificationTemplateContent("test", Localization.From("ru"), "Hello world"); Assert.Equal("test", template.Name); Assert.Equal("ru", template.Localization.ToString()); Assert.Equal("Hello world", template.Content); Assert.Equal(0, template.Keys.Count); }
internal string CreateFormattingComment(NotificationTemplateContent content) { var sb = new StringBuilder(); sb.AppendLine("There were missing parameter values inside message:"); content.Keys.ForEach(x => sb.AppendLine(x.ToString())); return(sb.ToString()); }
public void When_Get_Namespaces_Is_Executed_Expect_That_Only_Namespaces_Keys_Are_Extracted() { var data = new NotificationTemplateContent( "test", new Localization("en", ""), "test content ${testnamespace::testkey}"); var expectedResult = new List <string> { "testnamespace" }; var result = _messageService.GetNamespaces(data); Assert.Equal(result, expectedResult); }
internal void ValidateMessageFormatting(string message, CreateAuditMessageEvent createAuditMessageEvent) { // Check if there are any template parameters that are not changed // Easiest way is via new NotificationTemplateInfo // No need for specific template name and localization // We just need to check if there are keys :) var content = new NotificationTemplateContent("", Localization.Default, message); if (!content.Keys.Any()) { return; } createAuditMessageEvent.FormattingStatus = FormattingStatus.ValueNotFound; createAuditMessageEvent.FormattingComment = CreateFormattingComment(content); }
public async Task <NotificationTemplateContent> FindTemplateContentAsync(string templateName, Localization local) { var info = await _templateRepository.GetTemplateInfoAsync(templateName); if (info == null || !info.HasLocalization(local)) { return(null); } var content = await _templateContentRepository.GetContentAsync(info.Name, local); if (content == null) { return(null); } var result = new NotificationTemplateContent(info.Name, local, content); return(result); }
internal List <string> GetNamespaces(NotificationTemplateContent templateContent) => templateContent.Keys .Select(x => x.Namespace.ToLower()) .Where(x => !string.IsNullOrEmpty(x)) .Distinct() .ToList();