Files
hrynco-notification-service/HrynCo.NotificationService.Web.IntegrationTests/TemplateEditorTestFields.cs
T
agrynco 81654c0d33 feat(templates): add service language template management
Add normalized service and template catalogs, scoped administration, migration, validation, and regression coverage.

Ref: IT-1601
2026-10-17 22:02:43 +03:00

32 lines
1.4 KiB
C#

using System.Net;
using System.Text.RegularExpressions;
namespace HrynCo.NotificationService.Web.IntegrationTests;
public static class TemplateEditorTestFields
{
public static Dictionary<string, string> Read(string html)
{
var fields = new Dictionary<string, string>();
foreach (Match input in Regex.Matches(html, "<input[^>]+>"))
{
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, "<textarea[^>]+name=\"([^\"]+)\"[^>]*>(.*?)</textarea>", RegexOptions.Singleline))
fields[WebUtility.HtmlDecode(textarea.Groups[1].Value)] = WebUtility.HtmlDecode(textarea.Groups[2].Value);
return fields;
}
public static void SetLanguage(Dictionary<string, string> 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;
}
}