using SQLInsight.Core.Data; using SQLInsight.Core.Findings; using SQLInsight.Rules.Engine; using SQLInsight.Rules.Instance; using static SQLInsight.Rules.Tests.TestInstances; namespace SQLInsight.Rules.Tests; public class ServiceRuleTests { private static RuleResult Run(IRule rule, RuleContext context) => Assert.Single(new RuleEngine([rule]).Evaluate(context)); private static InstanceConfigurationSnapshot Setup(params ServiceInfo[] services) => new() { CapturedAt = Now, ServicesAvailable = true, Services = services }; [Fact] public void A_stopped_automatic_service_is_high_and_manual_ones_are_ignored() { var result = Run(new StoppedServiceRule(), With(Setup( new ServiceInfo("SQL Server (MSSQLSERVER)", @"NT Service\MSSQLSERVER", "Automatic", "Running", true), new ServiceInfo("SQL Server Agent (MSSQLSERVER)", @"KUNDE\svc-agent", "Automatic", "Stopped", null), new ServiceInfo("SQL Server Launchpad (MSSQLSERVER)", null, "Manual", "Stopped", null)))); var finding = Assert.Single(result.Findings); Assert.Equal(Severity.High, finding.Severity); Assert.Contains("backup", finding.Explanation, StringComparison.Ordinal); Assert.True(finding.Evidence.Single(e => e.Name == "Konto").Sensitive); } [Fact] public void Before_2008_r2_sp1_it_is_not_relevant() => Assert.Equal(RuleOutcome.NotApplicable, Run(new StoppedServiceRule(), WithVersion("10.50.1600.1", Setup())).Outcome); }