private void CheckRuleset(AnalyzerSettings actualSettings, string rootTestDir, string language) { string.IsNullOrWhiteSpace(actualSettings.RuleSetFilePath).Should().BeFalse("Ruleset file path should be set"); Path.IsPathRooted(actualSettings.RuleSetFilePath).Should().BeTrue("Ruleset file path should be absolute"); File.Exists(actualSettings.RuleSetFilePath).Should().BeTrue("Specified ruleset file does not exist: {0}", actualSettings.RuleSetFilePath); TestContext.AddResultFile(actualSettings.RuleSetFilePath); CheckFileIsXml(actualSettings.RuleSetFilePath); Path.GetFileName(actualSettings.RuleSetFilePath).Should().Be(RoslynAnalyzerProvider.GetRoslynRulesetFileName(language), "Ruleset file does not have the expected name"); var expectedFilePath = GetExpectedRulesetFilePath(rootTestDir, language); actualSettings.RuleSetFilePath.Should().Be(expectedFilePath, "Ruleset was not written to the expected location"); var expectedContent = @"<?xml version=""1.0"" encoding=""utf-8""?> <RuleSet xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" Name=""Rules for SonarQube"" Description=""This rule set was automatically generated from SonarQube"" ToolsVersion=""14.0""> <Rules AnalyzerId=""SonarAnalyzer.CSharp"" RuleNamespace=""SonarAnalyzer.CSharp""> <Rule Id=""S1116"" Action=""Warning"" /> <Rule Id=""S1125"" Action=""Warning"" /> <Rule Id=""S1000"" Action=""None"" /> </Rules> <Rules AnalyzerId=""Wintellect.Analyzers"" RuleNamespace=""Wintellect.Analyzers""> <Rule Id=""Wintellect003"" Action=""Warning"" /> </Rules> </RuleSet>"; File.ReadAllText(actualSettings.RuleSetFilePath).Should().Be(expectedContent, "Ruleset file does not have the expected content: {0}", actualSettings.RuleSetFilePath); }
private static string GetExpectedRulesetFilePath(string rootDir, string language) { return(Path.Combine(GetConfPath(rootDir), RoslynAnalyzerProvider.GetRoslynRulesetFileName(language))); }