sqlinsight-pro/tests/SQLInsight.Rules.Tests/ServerRuleScriptTests.cs
Søren Eggert Lundsteen Olsen 842286d57d SQL Scripts for the Windows server and synthetic check rules (SQLI-WIN-001..013, SQLI-SYN-001..003)
One reviewable file per rule id with a Danish header: what and why, thresholds
with config keys and defaults, severity, required rights (never local
administrator), supported versions, collector file and member, and the
evaluation in plain Danish. The Windows rules use no SQL: their exact CIM/WQL
queries, event log XPath and a read-only PowerShell snippet to verify them are in
a comment block. SQLI-SYN-001/002 carry the exact SQL a SQL check runs (session
settings, transaction that is always rolled back, SELECT 1). A test checks every
server and check rule has its file.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-02 14:58:36 +02:00

37 lines
1.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using SQLInsight.Rules.Servers;
namespace SQLInsight.Rules.Tests;
/// <summary>Every Windows server and synthetic check rule has its reviewable script in SQL Scripts/ (named by its id).</summary>
public class ServerRuleScriptTests
{
private static DirectoryInfo Scripts()
{
for (var directory = new DirectoryInfo(AppContext.BaseDirectory); directory is not null; directory = directory.Parent)
{
var candidate = new DirectoryInfo(Path.Combine(directory.FullName, "SQL Scripts"));
if (candidate.Exists)
{
return candidate;
}
}
throw new DirectoryNotFoundException("SQL Scripts/ blev ikke fundet over testens mappe.");
}
[Fact]
public void Every_server_and_check_rule_has_a_script_with_its_id_and_title()
{
var folder = Scripts();
Assert.All(ServerRuleCatalog.All, rule =>
{
var file = Path.Combine(folder.FullName, rule.Id + ".sql");
Assert.True(File.Exists(file), $"{rule.Id}.sql mangler i SQL Scripts/.");
var text = File.ReadAllText(file);
Assert.Contains($"{rule.Id} – {rule.Title}", text, StringComparison.Ordinal);
Assert.Contains("Evaluering", text, StringComparison.Ordinal);
Assert.DoesNotContain("sysadmin", text, StringComparison.OrdinalIgnoreCase);
});
}
}