using SQLInsight.Rules.Engine; namespace SQLInsight.Rules.Tests; public class RuleCatalogTests { [Fact] public void Every_rule_has_a_unique_well_formed_id() { var rules = BuiltInRules.Create(); Assert.Equal(rules.Count, rules.Select(r => r.Id).Distinct(StringComparer.OrdinalIgnoreCase).Count()); Assert.All(rules, r => Assert.Matches("^SQLI-[A-Z]+-[0-9]{3}$", r.Id)); Assert.All(rules, r => Assert.False(string.IsNullOrWhiteSpace(r.Title))); } /// Keeps the rule count in the README honest. [Fact] public void Rule_count() { Assert.Equal(92, BuiltInRules.Create().Count); Assert.Equal(13, Servers.WindowsServerRules.Create().Count); Assert.Equal(3, Servers.SyntheticCheckRules.Create().Count); Assert.Equal(108, BuiltInRules.Create().Count + Servers.ServerRuleCatalog.All.Count); } [Fact] public void Server_and_check_rules_have_unique_ids_that_no_instance_rule_has() { var ids = BuiltInRules.Create().Select(r => r.Id).Concat(Servers.ServerRuleCatalog.All.Select(r => r.Id)).ToList(); Assert.Equal(ids.Count, ids.Distinct(StringComparer.OrdinalIgnoreCase).Count()); Assert.All(Servers.ServerRuleCatalog.All, r => Assert.Matches("^SQLI-(WIN|SYN)-[0-9]{3}$", r.Id)); Assert.All(Servers.ServerRuleCatalog.All, r => Assert.False(string.IsNullOrWhiteSpace(r.Title))); } }