using System.Net; using System.Text.RegularExpressions; namespace HrynCo.NotificationService.Web.IntegrationTests; public static class TemplateEditorTestFields { public static Dictionary Read(string html) { var fields = new Dictionary(); foreach (Match input in Regex.Matches(html, "]+>")) { var name = Regex.Match(input.Value, "name=\"([^\"]+)\""); var value = Regex.Match(input.Value, "value=\"([^\"]*)\""); if (name.Success && value.Success) fields[WebUtility.HtmlDecode(name.Groups[1].Value)] = WebUtility.HtmlDecode(value.Groups[1].Value); } foreach (Match textarea in Regex.Matches(html, "]+name=\"([^\"]+)\"[^>]*>(.*?)", RegexOptions.Singleline)) fields[WebUtility.HtmlDecode(textarea.Groups[1].Value)] = WebUtility.HtmlDecode(textarea.Groups[2].Value); return fields; } public static void SetLanguage(Dictionary fields, string code, string subject, string html, string text) { var codeField = fields.Single(p => p.Key.EndsWith(".LanguageCode") && p.Value == code).Key; var prefix = codeField[..^"LanguageCode".Length]; fields[prefix + "Subject"] = subject; fields[prefix + "HtmlBody"] = html; fields[prefix + "TextBody"] = text; } }