public void RoslynConfig_ValidRealSonarLintProfile() { // Arrange string rootDir = CreateTestFolders(); TestLogger logger = new TestLogger(); TeamBuildSettings settings = CreateSettings(rootDir); WellKnownProfile testProfile = CreateRealSonarLintProfile(); MockSonarQubeServer mockServer = CreateServer("valid.project", null, "valid.profile", testProfile); RoslynAnalyzerProvider testSubject = CreateTestSubject(logger); // Act AnalyzerSettings actualSettings = testSubject.SetupAnalyzers(mockServer, settings, "valid.project", null); // Assert CheckSettingsInvariants(actualSettings); logger.AssertWarningsLogged(0); logger.AssertErrorsLogged(0); CheckRuleset(actualSettings, rootDir); CheckExpectedAdditionalFiles(testProfile, actualSettings); // Check the additional file is valid XML Assert.AreEqual(1, actualSettings.AdditionalFilePaths.Count(), "Test setup error: expecting only one additional file. Check the sample export XML has not changed"); string filePath = actualSettings.AdditionalFilePaths.First(); CheckFileIsXml(filePath); }
public void RoslynConfig_ValidProfile() { // Arrange string rootDir = CreateTestFolders(); TestLogger logger = new TestLogger(); TeamBuildSettings settings = CreateSettings(rootDir); WellKnownProfile testProfile = CreateValidCSharpProfile(); MockSonarQubeServer mockServer = CreateServer("valid.project", null, "valid.profile", testProfile); MockAnalyzerInstaller mockInstaller = new MockAnalyzerInstaller(); mockInstaller.AssemblyPathsToReturn = new HashSet <string>(new string[] { "c:\\assembly1.dll", "d:\\foo\\assembly2.dll" }); RoslynAnalyzerProvider testSubject = new RoslynAnalyzerProvider(mockInstaller, logger); // Act AnalyzerSettings actualSettings = testSubject.SetupAnalyzers(mockServer, settings, "valid.project", null); // Assert CheckSettingsInvariants(actualSettings); logger.AssertWarningsLogged(0); logger.AssertErrorsLogged(0); CheckRuleset(actualSettings, rootDir); CheckExpectedAdditionalFiles(testProfile, actualSettings); mockInstaller.AssertExpectedPluginsRequested(testProfile.Plugins); CheckExpectedAssemblies(actualSettings, "c:\\assembly1.dll", "d:\\foo\\assembly2.dll"); }
public void RoslynConfig_BranchMissingRuleset() { // This test is a regression scenario for SONARMSBRU-187: // We do not expect the project profile to be returned if we ask for a branch-specific profile // Arrange string rootDir = CreateTestFolders(); TestLogger logger = new TestLogger(); TeamBuildSettings settings = CreateSettings(rootDir); WellKnownProfile testProfile = CreateValidCSharpProfile(); MockSonarQubeServer mockServer = CreateServer("valid.project", null, "valid.profile", testProfile); MockAnalyzerInstaller mockInstaller = new MockAnalyzerInstaller(); mockInstaller.AssemblyPathsToReturn = new HashSet <string>(new string[] { "c:\\assembly1.dll", "d:\\foo\\assembly2.dll" }); RoslynAnalyzerProvider testSubject = new RoslynAnalyzerProvider(mockInstaller, logger); // Act AnalyzerSettings actualSettings = testSubject.SetupAnalyzers(mockServer, settings, "valid.project", "missingBranch"); // Assert AssertAnalyzerSetupNotPerformed(actualSettings, rootDir); logger.AssertErrorsLogged(0); logger.AssertWarningsLogged(0); }
private void CheckExpectedAdditionalFiles(WellKnownProfile expected, AnalyzerSettings actualSettings) { foreach (string expectedFileName in expected.AdditionalFiles.Keys) { string expectedContent = expected.AdditionalFiles[expectedFileName]; CheckExpectedAdditionalFileExists(expectedFileName, expectedContent, actualSettings); } }
private static WellKnownProfile CreateRealSonarLintProfile() { WellKnownProfile profile = new WellKnownProfile(RoslynAnalyzerProvider.RoslynCSharpFormatName, SampleExportXml.RoslynExportedValidSonarLintXml); profile.SetAdditionalFile(SampleExportXml.RoslynExportedAdditionalFileName, null /* don't check */); profile.AddPlugin(SampleExportXml.RoslynExportedPluginKey); return(profile); }
public void RoslynConfig_ValidProfile_BranchSpecific() { // Arrange string rootDir = CreateTestFolders(); TestLogger logger = new TestLogger(); TeamBuildSettings settings = CreateSettings(rootDir); // Differentiate the branch-specific and non-branch-specific profiles WellKnownProfile nonBranchSpecificProfile = CreateValidCSharpProfile(); WellKnownProfile branchSpecificProfile = CreateValidCSharpProfile(); branchSpecificProfile.AssemblyFilePaths.Add("e:\\assembly3.dll"); MockSonarQubeServer mockServer = CreateServer("valid.project", null, "valid.profile", nonBranchSpecificProfile); AddWellKnownProfileToServer("valid.project", "aBranch", "valid.anotherProfile", branchSpecificProfile, mockServer); MockAnalyzerInstaller mockInstaller = new MockAnalyzerInstaller(); mockInstaller.AssemblyPathsToReturn = new HashSet <string>(new string[] { "c:\\assembly1.dll", "d:\\foo\\assembly2.dll", "e:\\assembly3.dll" }); RoslynAnalyzerProvider testSubject = new RoslynAnalyzerProvider(mockInstaller, logger); // Act AnalyzerSettings actualSettings = testSubject.SetupAnalyzers(mockServer, settings, "valid.project", "aBranch"); // Assert CheckSettingsInvariants(actualSettings); logger.AssertWarningsLogged(0); logger.AssertErrorsLogged(0); CheckRuleset(actualSettings, rootDir); CheckExpectedAdditionalFiles(branchSpecificProfile, actualSettings); mockInstaller.AssertExpectedPluginsRequested(branchSpecificProfile.Plugins); CheckExpectedAssemblies(actualSettings, "c:\\assembly1.dll", "d:\\foo\\assembly2.dll", "e:\\assembly3.dll"); }
private void CheckExpectedAdditionalFiles(WellKnownProfile expected, AnalyzerSettings actualSettings) { foreach (string expectedFileName in expected.AdditionalFiles.Keys) { string expectedContent = expected.AdditionalFiles[expectedFileName]; CheckExpectedAdditionalFileExists(expectedFileName, expectedContent, actualSettings); } }
private static WellKnownProfile CreateRealSonarLintProfile() { WellKnownProfile profile = new WellKnownProfile(RoslynAnalyzerProvider.RoslynCSharpFormatName, SampleExportXml.RoslynExportedValidSonarLintXml); profile.SetAdditionalFile(SampleExportXml.RoslynExportedAdditionalFileName, null /* don't check */); profile.SetPackage(SampleExportXml.RoslynExportedPackageId, SampleExportXml.RoslynExportedPackageVersion); return profile; }
private static WellKnownProfile CreateValidCSharpProfile() { string file1Content = @"<AnalysisInput> <Rules> <Rule> <Key>S1067</Key> <Parameters> <Parameter> <Key>max</Key> <Value>3</Value> </Parameter> </Parameters> </Rule> </Rules> <Files> </Files> </AnalysisInput> "; string file2Content = "<Foo />"; string xml = @"<?xml version=""1.0"" encoding=""utf-8""?> <RoslynExportProfile Version=""1.0=""> <Configuration> <RuleSet Name=""Rules for SonarQube"" Description=""This rule set was automatically generated from SonarQube."" ToolsVersion=""14.0""> <Rules AnalyzerId=""SonarLint.CSharp"" RuleNamespace=""SonarLint.CSharp""> <Rule Id=""S1116"" Action=""Warning"" /> <Rule Id=""S1125"" Action=""Warning"" /> <!-- other rules omitted --> </Rules> <Rules AnalyzerId=""Wintellect.Analyzers"" RuleNamespace=""Wintellect.Analyzers""> <Rule Id=""Wintellect003"" Action=""Warning"" /> <!-- other rules omitted --> </Rules> </RuleSet> <AdditionalFiles> <AdditionalFile FileName=""SonarLint.xml"" >" + GetBase64EncodedString(file1Content) + @"</AdditionalFile> <AdditionalFile FileName=""MyAnalyzerData.xml"" >" + GetBase64EncodedString(file2Content) + @"</AdditionalFile> </AdditionalFiles> </Configuration> <Deployment> <NuGetPackages> <NuGetPackage Id=""SonarLint"" Version=""1.3.0"" /> <NuGetPackage Id=""Wintellect.Analyzers"" Version=""1.0.5.0-rc1"" /> </NuGetPackages> </Deployment> </RoslynExportProfile>"; WellKnownProfile profile = new WellKnownProfile(RoslynAnalyzerProvider.RoslynCSharpFormatName, xml); profile.SetAdditionalFile("SonarLint.xml", file1Content); profile.SetAdditionalFile("MyAnalyzerData.xml", file2Content); profile.SetPackage("SonarLint", "1.3.0"); profile.SetPackage("Wintellect.Analyzers", "1.0.5.0-rc1"); return profile; }
private void AddWellKnownProfileToServer(string projectKey, string projectBranch, string profileName, WellKnownProfile profile, MockSonarQubeServer server) { string projectId = projectKey; if (!String.IsNullOrWhiteSpace(projectBranch)) { projectId = projectKey + ":" + projectBranch; } server.Data.AddQualityProfile(profileName, "vb") .AddProject(projectId) .AddProject(profileName) .SetExport(profile.Format, "Invalid content - this export should not be requested"); // Create a C# quality profile for the supplied profile server.Data.AddQualityProfile(profileName, RoslynAnalyzerProvider.CSharpLanguage) .AddProject(projectId) .AddProject("dummy project3") // more dummy data - apply the quality profile to another dummy project .SetExport(profile.Format, profile.Content); }
private MockSonarQubeServer CreateServer(string projectKey, string projectBranch, string profileName, WellKnownProfile profile) { ServerDataModel model = new ServerDataModel(); // Add the required C# plugin and repository model.InstalledPlugins.Add(RoslynAnalyzerProvider.CSharpPluginKey); model.AddRepository(RoslynAnalyzerProvider.CSharpRepositoryKey, RoslynAnalyzerProvider.CSharpLanguage); // Add some dummy data model.InstalledPlugins.Add("unused"); MockSonarQubeServer server = new MockSonarQubeServer(); server.Data = model; AddWellKnownProfileToServer(projectKey, projectBranch, profileName, profile, server); return server; }
private MockSonarQubeServer CreateServer(string projectKey, string profileName, WellKnownProfile profile) { ServerDataModel model = new ServerDataModel(); // Add the required C# plugin and repository model.InstalledPlugins.Add(RoslynAnalyzerProvider.CSharpPluginKey); model.AddRepository(RoslynAnalyzerProvider.CSharpRepositoryKey, RoslynAnalyzerProvider.CSharpLanguage); // Add some dummy data model.InstalledPlugins.Add("unused"); model.AddQualityProfile(profileName, "vb") .AddProject(projectKey) .AddProject(profileName) .SetExport(profile.Format, "Invalid content - this export should not be requested"); // Create a C# quality profile for the supplied profile model.AddQualityProfile(profileName, RoslynAnalyzerProvider.CSharpLanguage) .AddProject(projectKey) .AddProject("dummy project3") // more dummy data - apply the quality profile to another dummy project .SetExport(profile.Format, profile.Content); MockSonarQubeServer server = new MockSonarQubeServer(); server.Data = model; return server; }
private static WellKnownProfile CreateValidCSharpProfile() { string file1Content = @"<AnalysisInput> <Rules> <Rule> <Key>S1067</Key> <Parameters> <Parameter> <Key>max</Key> <Value>3</Value> </Parameter> </Parameters> </Rule> </Rules> <Files> </Files> </AnalysisInput> "; string file2Content = "<Foo />"; string xml = @"<?xml version=""1.0"" encoding=""utf-8""?> <RoslynExportProfile Version=""1.0=""> <Configuration> <RuleSet Name=""Rules for SonarQube"" Description=""This rule set was automatically generated from SonarQube."" ToolsVersion=""14.0""> <Rules AnalyzerId=""SonarLint.CSharp"" RuleNamespace=""SonarLint.CSharp""> <Rule Id=""S1116"" Action=""Warning"" /> <Rule Id=""S1125"" Action=""Warning"" /> <!-- other rules omitted --> </Rules> <Rules AnalyzerId=""Wintellect.Analyzers"" RuleNamespace=""Wintellect.Analyzers""> <Rule Id=""Wintellect003"" Action=""Warning"" /> <!-- other rules omitted --> </Rules> </RuleSet> <AdditionalFiles> <AdditionalFile FileName=""SonarLint.xml"" >" + GetBase64EncodedString(file1Content) + @"</AdditionalFile> <AdditionalFile FileName=""MyAnalyzerData.xml"" >" + GetBase64EncodedString(file2Content) + @"</AdditionalFile> </AdditionalFiles> </Configuration> <Deployment> <Plugins> <Plugin Key=""csharp"" Version=""1.3.0"" /> <Plugin Key=""wintellect.analyzers"" Version=""1.6.0-RC1"" /> </Plugins> <NuGetPackages> <NuGetPackage Id=""Anything"" Version=""1.9.9"" /> </NuGetPackages> </Deployment> </RoslynExportProfile>"; WellKnownProfile profile = new WellKnownProfile(RoslynAnalyzerProvider.RoslynCSharpFormatName, xml); profile.SetAdditionalFile("SonarLint.xml", file1Content); profile.SetAdditionalFile("MyAnalyzerData.xml", file2Content); profile.AddPlugin("csharp"); profile.AddPlugin("wintellect.analyzers"); return(profile); }
private void AddWellKnownProfileToServer(string projectKey, string projectBranch, string profileName, WellKnownProfile profile, MockSonarQubeServer server) { string projectId = projectKey; if (!String.IsNullOrWhiteSpace(projectBranch)) { projectId = projectKey + ":" + projectBranch; } server.Data.AddQualityProfile(profileName, "vb") .AddProject(projectId) .AddProject(profileName) .SetExport(profile.Format, "Invalid content - this export should not be requested"); // Create a C# quality profile for the supplied profile server.Data.AddQualityProfile(profileName, RoslynAnalyzerProvider.CSharpLanguage) .AddProject(projectId) .AddProject("dummy project3") // more dummy data - apply the quality profile to another dummy project .SetExport(profile.Format, profile.Content); }
private MockSonarQubeServer CreateServer(string projectKey, string projectBranch, string profileName, WellKnownProfile profile) { ServerDataModel model = new ServerDataModel(); // Add the required C# plugin and repository model.InstalledPlugins.Add(RoslynAnalyzerProvider.CSharpPluginKey); model.AddRepository(RoslynAnalyzerProvider.CSharpRepositoryKey, RoslynAnalyzerProvider.CSharpLanguage); // Add some dummy data model.InstalledPlugins.Add("unused"); MockSonarQubeServer server = new MockSonarQubeServer(); server.Data = model; AddWellKnownProfileToServer(projectKey, projectBranch, profileName, profile, server); return(server); }