using Microsoft.Extensions.Logging.Abstractions; using StellaOps.Notifier.Tests.Support; using StellaOps.Notifier.WebService.Setup; using Xunit; namespace StellaOps.Notifier.Tests; public sealed class PackApprovalTemplateSeederTests { [Fact] public async Task SeedAsync_loads_templates_from_docs() { var templateRepo = new InMemoryTemplateRepository(); var channelRepo = new InMemoryChannelRepository(); var ruleRepo = new InMemoryRuleRepository(); var logger = NullLogger.Instance; var contentRoot = LocateRepoRoot(); var count = await PackApprovalTemplateSeeder.SeedTemplatesAsync( templateRepo, contentRoot, logger, cancellationToken: TestContext.Current.CancellationToken); var routed = await PackApprovalTemplateSeeder.SeedRoutingAsync( channelRepo, ruleRepo, logger, cancellationToken: TestContext.Current.CancellationToken); Assert.True(count >= 2, "Expected at least two templates to be seeded."); Assert.Equal(3, routed); var templates = await templateRepo.ListAsync("tenant-sample", TestContext.Current.CancellationToken); Assert.Contains(templates, t => t.TemplateId == "tmpl-pack-approval-slack-en"); Assert.Contains(templates, t => t.TemplateId == "tmpl-pack-approval-email-en"); var channels = await channelRepo.ListAsync("tenant-sample", cancellationToken: TestContext.Current.CancellationToken); Assert.Contains(channels, c => c.ChannelId == "chn-pack-approvals-slack"); Assert.Contains(channels, c => c.ChannelId == "chn-pack-approvals-email"); var rules = await ruleRepo.ListAsync("tenant-sample", TestContext.Current.CancellationToken); Assert.Contains(rules, r => r.RuleId == "rule-pack-approvals-default"); } private static string LocateRepoRoot() { var directory = AppContext.BaseDirectory; while (directory != null) { if (File.Exists(Path.Combine(directory, "StellaOps.sln")) || File.Exists(Path.Combine(directory, "StellaOps.Notifier.sln"))) { return directory; } directory = Directory.GetParent(directory)?.FullName; } throw new InvalidOperationException("Unable to locate repository root."); } }