public void BuildWrapper_OldCppPluginInstalled_FilesDownloaded()
        {
            // If an older version of the C++ plugin is installed then the embedded resource
            // won't exist. In that case we expect a warning message telling the user to upgrade.

            // Arrange
            string rootDir = TestUtils.CreateTestSpecificFolder(this.TestContext);
            TestLogger logger = new TestLogger();

            MockSonarQubeServer mockServer = new MockSonarQubeServer();
            mockServer.Data.InstalledPlugins.Add("cpp"); // plugin exists but no zip file

            BuildWrapperInstaller testSubject = new BuildWrapperInstaller(logger);

            // Act
            AnalysisProperties properties = testSubject.InstallBuildWrapper(mockServer, rootDir, "c:\\output\\");

            // Assert
            logger.AssertSingleWarningExists(SonarQube.TeamBuild.PreProcessor.Resources.BW_CppPluginUpgradeRequired);
            logger.AssertErrorsLogged(0);

            AssertNoFilesExist(rootDir);

            Assert.IsNotNull(properties, "Returned properties should not be null");
            Assert.AreEqual(0, properties.Count, "Not expecting any properties to be set");
        }
        public void PreProc_InvalidArgs()
        {
            // Arrange
            MockSonarQubeServer mockServer = new MockSonarQubeServer();
            TeamBuildPreProcessor preprocessor = new TeamBuildPreProcessor(
                new TestLogger(), new MockSonarQubeServerFactory(mockServer), new MockTargetsInstaller(), new MockRoslynAnalyzerProvider());

            // Act and assert
            AssertException.Expects<ArgumentNullException>(() => preprocessor.Execute(null));
        }
        public void EmbeddedInstall_CachingScenarios()
        {
            // Arrange
            string localCacheDir = TestUtils.CreateTestSpecificFolder(this.TestContext);
            TestLogger logger = new TestLogger();

            Plugin requestA = new Plugin("p111", "1.0-SNAPSHOT", "p1.zip");
            Plugin requestB = new Plugin("p222", "9.1.3.0", "p2.zip");

            MockSonarQubeServer mockServer = new MockSonarQubeServer();
            AddPlugin(mockServer, requestA, "aaa", "bbb");
            AddPlugin(mockServer, requestB, "ccc");

            IList<string> expectedPlugin111Paths = CalculateExpectedCachedFilePaths(localCacheDir, requestA, "p1.zip", "aaa", "bbb");
            IList<string> expectedPlugin222Paths = CalculateExpectedCachedFilePaths(localCacheDir, requestB, "p2.zip", "ccc");
            List<string> allExpectedPaths = new List<string>(expectedPlugin111Paths);
            allExpectedPaths.AddRange(expectedPlugin222Paths);

            EmbeddedAnalyzerInstaller testSubject = new EmbeddedAnalyzerInstaller(mockServer, localCacheDir, logger);

            AssertExpectedFilesInCache(0, localCacheDir); // cache should be empty to start with

            // 1. Empty cache -> cache miss -> server called
            IEnumerable<string> actualFiles = testSubject.InstallAssemblies(new Plugin[] { requestA });
            mockServer.AssertMethodCalled(DownloadEmbeddedFileMethodName, 1); // should have tried to download

            AssertExpectedFilesReturned(expectedPlugin111Paths, actualFiles);
            AssertExpectedFilesExist(expectedPlugin111Paths);
            AssertExpectedFilesInCache(3, localCacheDir); // only files for the first request should exist

            // 2. New request + request request -> partial cache miss -> server called only for the new request
            actualFiles = testSubject.InstallAssemblies(new Plugin[] { requestA, requestB });
            mockServer.AssertMethodCalled(DownloadEmbeddedFileMethodName, 2); // new request

            AssertExpectedFilesReturned(allExpectedPaths, actualFiles);
            AssertExpectedFilesExist(allExpectedPaths);
            AssertExpectedFilesInCache(5, localCacheDir); // files for both plugins should exist

            // 3. Repeat the request -> cache hit -> server not called
            actualFiles = testSubject.InstallAssemblies(new Plugin[] { requestA, requestB });
            mockServer.AssertMethodCalled(DownloadEmbeddedFileMethodName, 2); // call count should not have changed

            AssertExpectedFilesReturned(allExpectedPaths, actualFiles);

            // 4. Clear the cache and request both -> cache miss -> multiple requests
            Directory.Delete(localCacheDir, true);
            Assert.IsFalse(Directory.Exists(localCacheDir), "Test error: failed to delete the local cache directory");

            actualFiles = testSubject.InstallAssemblies(new Plugin[] { requestA, requestB });
            mockServer.AssertMethodCalled(DownloadEmbeddedFileMethodName, 4); // two new requests

            AssertExpectedFilesReturned(allExpectedPaths, actualFiles);
            AssertExpectedFilesExist(allExpectedPaths);
            AssertExpectedFilesInCache(5, localCacheDir); // files for both plugins should exist
        }
        public void BuildWrapper_PluginInstalled_FilesDownloaded()
        {
            // Arrange
            string rootDir = TestUtils.CreateTestSpecificFolder(this.TestContext);
            TestLogger logger = new TestLogger();

            MockSonarQubeServer mockServer = new MockSonarQubeServer();
            mockServer.Data.InstalledPlugins.Add("cpp");

            // See https://jira.sonarsource.com/browse/CPP-1458 for the embedded resource name
            // The build wrapper installer doesn't care what the content of zip is, just that it exists
            mockServer.Data.AddEmbeddedZipFile("cpp",
                "build-wrapper-win-x86.zip",
                // Content file names
                "file1.txt", "file2.txt", "file3.txt");

            BuildWrapperInstaller testSubject = new BuildWrapperInstaller(logger);

            // Act
            AnalysisProperties properties = testSubject.InstallBuildWrapper(mockServer, rootDir, "c:\\output\\");

            // Assert
            logger.AssertErrorsLogged(0);
            logger.AssertWarningsLogged(0);

            AssertFileExists(rootDir, "file1.txt");
            AssertFileExists(rootDir, "file2.txt");
            AssertFileExists(rootDir, "file3.txt");

            // Check that the expected build wrapper properties are set
            Assert.IsNotNull(properties, "Returned properties should not be null");
            Assert.AreEqual(1, properties.Count, "Expecting one property to be set");

            Property buildWrapperOutputProperty;
            bool found = Property.TryGetProperty(BuildWrapperOutputSettingName, properties, out buildWrapperOutputProperty);
            Assert.IsTrue(found, "Expected property was not found");
            Assert.AreEqual("c:\\output\\bw", buildWrapperOutputProperty.Value, "Build output property does not have the expected value");
        }
        public void EmbeddedInstall_SinglePlugin_SingleResource_Succeeds()
        {
            // Arrange
            var localCacheDir = TestUtils.CreateTestSpecificFolder(TestContext);
            var logger        = new TestLogger();

            var requestedPlugin = new Plugin("plugin1", "1.0", "embeddedFile1.zip");
            var mockServer      = new MockSonarQubeServer();

            AddPlugin(mockServer, requestedPlugin, "file1.dll", "file2.txt");

            var expectedFilePaths = CalculateExpectedCachedFilePaths(localCacheDir, 0, requestedPlugin, "file1.dll", "file2.txt");

            var testSubject = new EmbeddedAnalyzerInstaller(mockServer, localCacheDir, logger);

            // Act
            var actualFiles = testSubject.InstallAssemblies(new Plugin[] { requestedPlugin });

            // Assert
            Assert.IsNotNull(actualFiles, "Returned list should not be null");
            AssertExpectedFilesReturned(expectedFilePaths, actualFiles);
            AssertExpectedFilesExist(expectedFilePaths);
            AssertExpectedFilesInCache(4, localCacheDir); // one zip containing two files
        }
Beispiel #6
0
        public void RoslynConfig_ProfileExportIsUnavailable_FailsGracefully()
        {
            // Arrange
            string            rootDir  = CreateTestFolders();
            TestLogger        logger   = new TestLogger();
            TeamBuildSettings settings = CreateSettings(rootDir);

            // Create a server that doesn't export the expected format (simulates
            // calling an older plugin version)
            MockSonarQubeServer mockServer = CreateValidServer("valid.project", null, "valid.profile");
            QualityProfile      csProfile  = mockServer.Data.FindProfile("valid.profile", RoslynAnalyzerProvider.CSharpLanguage);

            csProfile.SetExport(RoslynAnalyzerProvider.RoslynCSharpFormatName, null);

            RoslynAnalyzerProvider testSubject = CreateTestSubject(logger);

            // Act
            AnalyzerSettings actualSettings = testSubject.SetupAnalyzers(mockServer, settings, "valid.project", null);

            // Assert
            AssertAnalyzerSetupNotPerformed(actualSettings, rootDir);

            logger.AssertErrorsLogged(0);
        }
        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;
        }
        /// <summary>
        /// Creates and returns a mock server that is correctly configured to return
        /// a SonarLint ruleset for the specified project key and profile
        /// </summary>
        private static MockSonarQubeServer CreateValidServer(string validProjectKey, string validProfileName)
        {
            ServerDataModel model = new ServerDataModel();
            model.InstalledPlugins.Add(SonarLintAnalyzerProvider.CSharpPluginKey);
            model.InstalledPlugins.Add("unused");

            model.AddQualityProfile(validProfileName, "vb")
                .AddProject(validProjectKey)
                .AddProject(validProfileName);

            model.AddQualityProfile(validProfileName, SonarLintAnalyzerProvider.CSharpLanguage)
                .AddProject(validProjectKey)
                .AddProject("project3")
                .SetExport(SonarLintAnalyzerProvider.SonarLintProfileFormatName,
            @"<?xml version=""1.0"" encoding=""utf-8""?>
            <RuleSet Name=""Rules for SonarLint"" Description=""This rule set was automatically generated from SonarQube."" ToolsVersion=""14.0"">
              <Rules AnalyzerId=""SonarLint"" RuleNamespace=""SonarLint"">
            <Rule Id=""S1656"" Action=""Warning"" />
              </Rules>
            </RuleSet>");

            model.AddRepository(SonarLintAnalyzerProvider.CSharpRepositoryKey, SonarLintAnalyzerProvider.CSharpLanguage);

            MockSonarQubeServer server = new MockSonarQubeServer();
            server.Data = model;
            return server;
        }
 private void AddPlugin(MockSonarQubeServer mockServer, Plugin plugin, params string[] files)
 {
     mockServer.Data.AddEmbeddedZipFile(plugin.Key, plugin.StaticResourceName, files);
 }
Beispiel #10
0
        public void RulesetGet_Simple()
        {
            string testDir = TestUtils.CreateTestSpecificFolder(this.TestContext);

            ServerDataModel model = new ServerDataModel();

            model.InstalledPlugins.Add("real.plugin1");
            model.InstalledPlugins.Add("unused.plugin1");

            // Set up the rule repositories
            model.AddRepository("empty.repo", "aaa");

            model.AddRepository("repo1", "languageAAA")
            .AddRule("repo1.aaa.r1", "repo1.aaa.r1.internal")
            .AddRule("repo1.aaa.r2", "repo1.aaa.r2.internal");

            model.AddRepository("repo1", "languageBBB")
            .AddRule("repo1.bbb.r1", "repo1.xxx.r1.internal")
            .AddRule("repo1.bbb.r2", "repo1.xxx.r2.internal")
            .AddRule("repo1.bbb.r3", "repo1.xxx.r3.internal");


            // Set up the quality profiles
            model.AddQualityProfile("profile 1", "languageAAA")
            .AddProject("unused.project")
            .AddProject("project1")
            .AddProject("project2:anotherBranch");

            model.AddQualityProfile("profile 2", "languageBBB")
            .AddProject("project1")
            .AddProject("project2");

            model.AddQualityProfile("profile 3", "languageBBB")
            .AddProject("project2:aBranch")
            .AddProject("project3:aThirdBranch");

            // Add rules to the quality profiles
            model.AddRuleToProfile("repo1.aaa.r1", "profile 1"); // Only one rule in the repo

            model.AddRuleToProfile("repo1.bbb.r1", "profile 2");
            model.AddRuleToProfile("repo1.bbb.r2", "profile 2");
            model.AddRuleToProfile("repo1.bbb.r3", "profile 2");

            model.AddRuleToProfile("repo1.bbb.r1", "profile 3");

            MockSonarQubeServer server = new MockSonarQubeServer();

            server.Data = model;

            // 1. Plugin not installed
            string rulesetFilePath = Path.Combine(testDir, "r1.txt");

            RulesetGenerator.Generate(server, "missing.plugin", "languageAAA", "repo1", "project1", null, rulesetFilePath);
            AssertFileDoesNotExist(rulesetFilePath);

            // 2. Language not handled
            RulesetGenerator.Generate(server, "real.plugin1", "unhandled.language", "repo1", "project1", null, rulesetFilePath);
            AssertFileDoesNotExist(rulesetFilePath);

            // 3. Missing project
            RulesetGenerator.Generate(server, "real.plugin1", "languageBBB", "repo1", "missing.project", null, rulesetFilePath);
            AssertFileDoesNotExist(rulesetFilePath);

            // 4. Missing project (project:branch exists)
            RulesetGenerator.Generate(server, "real.plugin1", "languageBBB", "repo1", "project3", null, rulesetFilePath);
            AssertFileDoesNotExist(rulesetFilePath);

            // 5. Missing project:branch
            RulesetGenerator.Generate(server, "real.plugin1", "languageBBB", "repo1", "missing.project", "missingBranch", rulesetFilePath);
            AssertFileDoesNotExist(rulesetFilePath);

            // 6. b) Missing project:branch (project exists)
            RulesetGenerator.Generate(server, "real.plugin1", "languageBBB", "repo1", "project1", "missingBranch", rulesetFilePath);
            AssertFileDoesNotExist(rulesetFilePath);

            // 5. Valid, aaa (default branch)
            string aaa_RulesetFilePath = Path.Combine(testDir, "aaa_ruleset.txt");

            RulesetGenerator.Generate(server, "real.plugin1", "languageAAA", "repo1", "project1", null, aaa_RulesetFilePath);
            PreProcessAsserts.AssertRuleSetContainsRules(aaa_RulesetFilePath, "repo1.aaa.r1");

            // 6. Valid, bbb (default branch)
            string bbb_RulesetFilePath = Path.Combine(testDir, "bbb_ruleset.txt");

            RulesetGenerator.Generate(server, "real.plugin1", "languageBBB", "repo1", "project1", null, bbb_RulesetFilePath);
            PreProcessAsserts.AssertRuleSetContainsRules(bbb_RulesetFilePath,
                                                         "repo1.bbb.r1", "repo1.bbb.r2", "repo1.bbb.r3");

            // 7. Valid, bbb (aBranch branch) - profile 3
            string bbb_aBranch_RulesetFilePath = Path.Combine(testDir, "bbb_aBranch_ruleset.txt");

            RulesetGenerator.Generate(server, "real.plugin1", "languageBBB", "repo1", "project2", "aBranch", bbb_aBranch_RulesetFilePath);
            PreProcessAsserts.AssertRuleSetContainsRules(bbb_aBranch_RulesetFilePath,
                                                         "repo1.bbb.r1");

            // 8. Valid, aaa (anotherBranch branch) - profile 1
            string bbb_anotherBranch_RulesetFilePath = Path.Combine(testDir, "bbb_anotherBranch_ruleset.txt");

            RulesetGenerator.Generate(server, "real.plugin1", "languageAAA", "repo1", "project2", "anotherBranch", bbb_anotherBranch_RulesetFilePath);
            PreProcessAsserts.AssertRuleSetContainsRules(bbb_anotherBranch_RulesetFilePath,
                                                         "repo1.aaa.r1");
        }
        public void PreProc_EndToEnd_SuccessCase()
        {
            // Checks end-to-end happy path for the pre-processor i.e.
            // * arguments are parsed
            // * targets are installed
            // * build wrapper installer is called
            // * server properties are fetched
            // * rulesets are generated
            // * config file is created

            // Arrange
            string workingDir = TestUtils.CreateTestSpecificFolder(this.TestContext);
            TestLogger logger = new TestLogger();

            // Configure the server
            MockSonarQubeServer mockServer = new MockSonarQubeServer();

            ServerDataModel data = mockServer.Data;
            data.ServerProperties.Add("server.key", "server value 1");

            data.InstalledPlugins.Add("csharp");
            data.InstalledPlugins.Add("vbnet");

            data.AddRepository("fxcop", "cs")
                .AddRule("cs.rule1", "cs.rule1.internal")
                .AddRule("cs.rule2", "cs.rule2.internal");

            data.AddRepository("fxcop-vbnet", "vbnet")
                .AddRule("vb.rule1", "vb.rule1.internal")
                .AddRule("vb.rule2", "vb.rule2.internal");

            data.AddQualityProfile("test.profile", "cs")
                .AddProject("key");
            data.AddRuleToProfile("cs.rule1", "test.profile");

            data.AddQualityProfile("test.profile", "vbnet")
                .AddProject("key");
            data.AddRuleToProfile("vb.rule2", "test.profile");

            MockRoslynAnalyzerProvider mockAnalyzerProvider = new MockRoslynAnalyzerProvider();
            mockAnalyzerProvider.SettingsToReturn = new AnalyzerSettings();
            mockAnalyzerProvider.SettingsToReturn.RuleSetFilePath = "c:\\xxx.ruleset";

            MockTargetsInstaller mockTargetsInstaller = new MockTargetsInstaller();
            MockBuildWrapperInstaller mockBuildWrapperInstaller = new MockBuildWrapperInstaller();

            MockObjectFactory mockFactory = new MockObjectFactory(mockServer, mockTargetsInstaller, mockAnalyzerProvider, mockBuildWrapperInstaller);

            string[] validArgs = new string[] {
                "/k:key", "/n:name", "/v:1.0",
                "/d:cmd.line1=cmdline.value.1",
                "/d:sonar.host.url=http://host",
                "/d:sonar.log.level=INFO|DEBUG"};

            TeamBuildSettings settings;
            using (PreprocessTestUtils.CreateValidNonTeamBuildScope())
            using (new WorkingDirectoryScope(workingDir))
            {
                settings = TeamBuildSettings.GetSettingsFromEnvironment(new TestLogger());
                Assert.IsNotNull(settings, "Test setup error: TFS environment variables have not been set correctly");
                Assert.AreEqual(BuildEnvironment.NotTeamBuild, settings.BuildEnvironment, "Test setup error: build environment was not set correctly");

                TeamBuildPreProcessor preProcessor = new TeamBuildPreProcessor(mockFactory, logger);

                // Act
                bool success = preProcessor.Execute(validArgs);
                Assert.IsTrue(success, "Expecting the pre-processing to complete successfully");
            }

            // Assert
            AssertDirectoryExists(settings.AnalysisBaseDirectory);
            AssertDirectoryExists(settings.SonarConfigDirectory);
            AssertDirectoryExists(settings.SonarOutputDirectory);
            // The bootstrapper is responsible for creating the bin directory

            mockTargetsInstaller.AssertsTargetsCopied();
            mockServer.AssertMethodCalled("GetProperties", 1);
            mockServer.AssertMethodCalled("GetInternalKeys", 2); // C# and VB

            mockBuildWrapperInstaller.AssertExpectedCallCount(1);

            logger.AssertErrorsLogged(0);
            logger.AssertWarningsLogged(0);
            logger.AssertVerbosity(LoggerVerbosity.Debug);

            AssertConfigFileExists(settings.AnalysisConfigFilePath);
            AnalysisConfig actualConfig = AnalysisConfig.Load(settings.AnalysisConfigFilePath);

            Assert.AreEqual("key", actualConfig.SonarProjectKey, "Unexpected project key");
            Assert.AreEqual("name", actualConfig.SonarProjectName, "Unexpected project name");
            Assert.AreEqual("1.0", actualConfig.SonarProjectVersion, "Unexpected project version");

            Assert.IsNotNull(actualConfig.AnalyzerSettings, "Analyzer settings should not be null");
            Assert.AreEqual("c:\\xxx.ruleset", actualConfig.AnalyzerSettings.RuleSetFilePath, "Unexpected ruleset path");

            AssertExpectedLocalSetting(SonarProperties.HostUrl, "http://host", actualConfig);
            AssertExpectedLocalSetting("cmd.line1", "cmdline.value.1", actualConfig);
            AssertExpectedServerSetting("server.key", "server value 1", actualConfig);

            string fxCopFilePath = AssertFileExists(settings.SonarConfigDirectory, TeamBuildPreProcessor.FxCopCSharpRuleset);
            PreProcessAsserts.AssertRuleSetContainsRules(fxCopFilePath, "cs.rule1");

            fxCopFilePath = AssertFileExists(settings.SonarConfigDirectory, TeamBuildPreProcessor.FxCopVBNetRuleset);
            PreProcessAsserts.AssertRuleSetContainsRules(fxCopFilePath, "vb.rule2");
        }
Beispiel #12
0
        public void PreProc_EndToEnd_SuccessCase()
        {
            // Checks end-to-end happy path for the pre-processor i.e.
            // * arguments are parsed
            // * targets are installed
            // * server properties are fetched
            // * rulesets are generated
            // * config file is created

            // Arrange
            string     workingDir = TestUtils.CreateTestSpecificFolder(this.TestContext);
            TestLogger logger     = new TestLogger();

            // Configure the server
            MockSonarQubeServer mockServer = new MockSonarQubeServer();

            ServerDataModel data = mockServer.Data;

            data.ServerProperties.Add("server.key", "server value 1");

            data.Languages.Add("cs");
            data.Languages.Add("vbnet");
            data.Languages.Add("another_plugin");

            data.AddQualityProfile("qp1", "cs", null)
            .AddProject("key")
            .AddRule(new ActiveRule("csharpsquid", "cs.rule3"));

            data.AddQualityProfile("qp2", "vbnet", null)
            .AddProject("key")
            .AddRule(new ActiveRule("vbnet", "vb.rule3"));

            MockRoslynAnalyzerProvider mockAnalyzerProvider = new MockRoslynAnalyzerProvider
            {
                SettingsToReturn = new AnalyzerSettings
                {
                    RuleSetFilePath = "c:\\xxx.ruleset"
                }
            };

            Mock <ITargetsInstaller> mockTargetsInstaller = new Mock <ITargetsInstaller>();
            MockObjectFactory        mockFactory          = new MockObjectFactory(mockServer, mockTargetsInstaller.Object, mockAnalyzerProvider);

            TeamBuildSettings settings;

            using (PreprocessTestUtils.CreateValidNonTeamBuildScope())
                using (new WorkingDirectoryScope(workingDir))
                {
                    settings = TeamBuildSettings.GetSettingsFromEnvironment(new TestLogger());
                    Assert.IsNotNull(settings, "Test setup error: TFS environment variables have not been set correctly");
                    Assert.AreEqual(BuildEnvironment.NotTeamBuild, settings.BuildEnvironment, "Test setup error: build environment was not set correctly");

                    TeamBuildPreProcessor preProcessor = new TeamBuildPreProcessor(mockFactory, logger);

                    // Act
                    bool success = preProcessor.Execute(CreateValidArgs("key", "name", "1.0"));
                    Assert.IsTrue(success, "Expecting the pre-processing to complete successfully");
                }

            // Assert
            AssertDirectoriesCreated(settings);

            mockTargetsInstaller.Verify(x => x.InstallLoaderTargets(logger, workingDir), Times.Once());
            mockServer.AssertMethodCalled("GetProperties", 1);
            mockServer.AssertMethodCalled("GetAllLanguages", 1);
            mockServer.AssertMethodCalled("TryGetQualityProfile", 2); // C# and VBNet
            mockServer.AssertMethodCalled("GetActiveRules", 2);       // C# and VBNet
            mockServer.AssertMethodCalled("GetInactiveRules", 2);     // C# and VBNet

            AssertAnalysisConfig(settings.AnalysisConfigFilePath, 2, logger);
        }
        public void EmbeddedInstall_SinglePlugin_SingleResource_Succeeds()
        {
            // Arrange
            string localCacheDir = TestUtils.CreateTestSpecificFolder(this.TestContext);
            TestLogger logger = new TestLogger();

            Plugin requestedPlugin = new Plugin("plugin1", "1.0", "embeddedFile1.zip");
            MockSonarQubeServer mockServer = new MockSonarQubeServer();
            AddPlugin(mockServer, requestedPlugin, "file1.dll", "file2.txt");

            IList<string> expectedFilePaths = CalculateExpectedCachedFilePaths(localCacheDir, requestedPlugin, "embeddedFile1.zip", "file1.dll", "file2.txt");

            EmbeddedAnalyzerInstaller testSubject = new EmbeddedAnalyzerInstaller(mockServer, localCacheDir, logger);

            // Act
            IEnumerable<string> actualFiles = testSubject.InstallAssemblies(new Plugin[] { requestedPlugin });

            // Assert
            Assert.IsNotNull(actualFiles, "Returned list should not be null");
            AssertExpectedFilesReturned(expectedFilePaths, actualFiles);
            AssertExpectedFilesExist(expectedFilePaths);
            AssertExpectedFilesInCache(3, localCacheDir); // one zip containing two files
        }
 private void AddPlugin(MockSonarQubeServer mockServer, Plugin plugin, params string[] files)
 {
     mockServer.Data.InstalledPlugins.Add(plugin.Key);
     mockServer.Data.AddEmbeddedZipFile(plugin.Key, plugin.StaticResourceName, files);
 }
        public void EmbeddedInstall_MultiplePlugins_Succeeds()
        {
            // Arrange
            string localCacheDir = TestUtils.CreateTestSpecificFolder(this.TestContext);
            TestLogger logger = new TestLogger();

            Plugin request1 = new Plugin("no.matching.resource.plugin", "2.0", "non.existent.resource.zip");
            Plugin request2 = new Plugin("plugin1", "1.0", "p1.resource1.zip");
            Plugin request3 = new Plugin("plugin1", "1.0", "p1.resource2.zip"); // second resource for plugin 1
            Plugin request4 = new Plugin("plugin2", "2.0", "p2.resource1.zip");

            MockSonarQubeServer mockServer = new MockSonarQubeServer();
            AddPlugin(mockServer, request2, "p1.resource1.file1.dll", "p1.resource1.file2.dll");
            AddPlugin(mockServer, request3, "p1.resource2.file1.dll");
            AddPlugin(mockServer, request4, "p2.resource1.dll");

            List<string> expectedPaths = new List<string>();
            expectedPaths.AddRange(CalculateExpectedCachedFilePaths(localCacheDir, request2, "p1.resource1.zip", "p1.resource1.file1.dll", "p1.resource1.file2.dll"));
            expectedPaths.AddRange(CalculateExpectedCachedFilePaths(localCacheDir, request3, "p1.resource2.zip", "p1.resource2.file1.dll"));
            expectedPaths.AddRange(CalculateExpectedCachedFilePaths(localCacheDir, request4, "p2.resource1.zip", "p2.resource1.dll"));

            EmbeddedAnalyzerInstaller testSubject = new EmbeddedAnalyzerInstaller(mockServer, localCacheDir, logger);

            // Act
            IEnumerable<string> actualFiles = testSubject.InstallAssemblies(new Plugin[] { request1, request2, request3, request4});

            // Assert
            Assert.IsNotNull(actualFiles, "Returned list should not be null");
            AssertExpectedFilesReturned(expectedPaths, actualFiles);
            AssertExpectedFilesExist(expectedPaths);
            AssertExpectedFilesInCache(expectedPaths.Count, localCacheDir);
        }
        public void EmbeddedInstall_EmptyCacheDirectoryExists_CacheMissAndServerCalled()
        {
            // Arrange
            string localCacheDir = TestUtils.CreateTestSpecificFolder(this.TestContext);
            TestLogger logger = new TestLogger();

            Plugin requestA = new Plugin("p111", "1.0-SNAPSHOT", "p1.zip");

            MockSonarQubeServer mockServer = new MockSonarQubeServer();
            AddPlugin(mockServer, requestA, "aaa.txt");

            IList<string> expectedPlugin111Paths = CalculateExpectedCachedFilePaths(localCacheDir, requestA, "p1.zip", "aaa.txt");
            Assert.AreNotEqual(0, expectedPlugin111Paths.Count, "Test setup error: expecting at least one file path");

            // Create the expected directories, but not the files
            foreach(string file in expectedPlugin111Paths)
            {
                string dir = Path.GetDirectoryName(file);
                Directory.CreateDirectory(dir);
            }

            AssertExpectedFilesInCache(0, localCacheDir); // cache should be empty to start with
            Assert.AreNotEqual(0, Directory.GetDirectories(localCacheDir, "*.*", SearchOption.AllDirectories)); // ... but should have directories

            EmbeddedAnalyzerInstaller testSubject = new EmbeddedAnalyzerInstaller(mockServer, localCacheDir, logger);

            // 1. Empty directory = cache miss -> server called
            IEnumerable<string> actualFiles = testSubject.InstallAssemblies(new Plugin[] { requestA });
            mockServer.AssertMethodCalled(DownloadEmbeddedFileMethodName, 1); // should have tried to download

            AssertExpectedFilesReturned(expectedPlugin111Paths, actualFiles);
            AssertExpectedFilesExist(expectedPlugin111Paths);
            AssertExpectedFilesInCache(2, localCacheDir);
        }
        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 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 void AddPlugin(MockSonarQubeServer mockServer, Plugin plugin, params string[] files)
 {
     mockServer.Data.InstalledPlugins.Add(plugin.Key);
     mockServer.Data.AddEmbeddedFile(plugin.Key, plugin.StaticResourceName, CreateDummyZipFile(files));
 }
 /// <summary>
 /// Used by tests that don't care about the content of the plugin, just it's existence
 /// </summary>
 private MockSonarQubeServer CreateServerWithDummyPlugin(string pluginKey)
 {
     MockSonarQubeServer mockServer = new MockSonarQubeServer();
     mockServer.Data.InstalledPlugins.Add(pluginKey);
     mockServer.Data.AddEmbeddedZipFile(pluginKey, "embeddedFile1.zip", "file1.dll", "file2.txt");
     return mockServer;
 }
Beispiel #21
0
        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);
        }
Beispiel #22
0
        public void PreProc_NoProject()
        {
            // Arrange
            string     workingDir = TestUtils.CreateTestSpecificFolder(this.TestContext);
            TestLogger logger     = new TestLogger();

            // Configure the server
            MockSonarQubeServer mockServer = new MockSonarQubeServer();

            ServerDataModel data = mockServer.Data;

            data.ServerProperties.Add("server.key", "server value 1");

            data.Languages.Add("cs");
            data.Languages.Add("vbnet");
            data.Languages.Add("another_plugin");

            data.AddQualityProfile("qp1", "cs", null)
            .AddProject("invalid")
            .AddRule(new ActiveRule("fxcop", "cs.rule1"))
            .AddRule(new ActiveRule("fxcop", "cs.rule2"));

            data.AddQualityProfile("qp2", "vbnet", null)
            .AddProject("invalid")
            .AddRule(new ActiveRule("fxcop-vbnet", "vb.rule1"))
            .AddRule(new ActiveRule("fxcop-vbnet", "vb.rule2"));

            MockRoslynAnalyzerProvider mockAnalyzerProvider = new MockRoslynAnalyzerProvider
            {
                SettingsToReturn = new AnalyzerSettings
                {
                    RuleSetFilePath = "c:\\xxx.ruleset"
                }
            };

            Mock <ITargetsInstaller> mockTargetsInstaller = new Mock <ITargetsInstaller>();
            MockObjectFactory        mockFactory          = new MockObjectFactory(mockServer, mockTargetsInstaller.Object, mockAnalyzerProvider);

            TeamBuildSettings settings;

            using (PreprocessTestUtils.CreateValidNonTeamBuildScope())
                using (new WorkingDirectoryScope(workingDir))
                {
                    settings = TeamBuildSettings.GetSettingsFromEnvironment(new TestLogger());
                    Assert.IsNotNull(settings, "Test setup error: TFS environment variables have not been set correctly");
                    Assert.AreEqual(BuildEnvironment.NotTeamBuild, settings.BuildEnvironment, "Test setup error: build environment was not set correctly");

                    TeamBuildPreProcessor preProcessor = new TeamBuildPreProcessor(mockFactory, logger);

                    // Act
                    bool success = preProcessor.Execute(CreateValidArgs("key", "name", "1.0", null));
                    Assert.IsTrue(success, "Expecting the pre-processing to complete successfully");
                }

            // Assert
            AssertDirectoriesCreated(settings);

            mockTargetsInstaller.Verify(x => x.InstallLoaderTargets(logger, workingDir), Times.Once());
            mockServer.AssertMethodCalled("GetProperties", 1);
            mockServer.AssertMethodCalled("GetAllLanguages", 1);
            mockServer.AssertMethodCalled("TryGetQualityProfile", 2); // C# and VBNet
            mockServer.AssertMethodCalled("GetActiveRules", 0);       // no quality profile assigned to project
            mockServer.AssertMethodCalled("GetInactiveRules", 0);

            AssertAnalysisConfig(settings.AnalysisConfigFilePath, 0, logger);

            // only contains SonarQubeAnalysisConfig (no rulesets or aditional files)
            AssertDirectoryContains(settings.SonarConfigDirectory, Path.GetFileName(settings.AnalysisConfigFilePath));
        }
        public void PreProc_InvalidArgs()
        {
            // Arrange
            TestLogger validLogger = new TestLogger();

            string[] validArgs = new string[] { "/k:key", "/n:name", "/v:1.0" };

            MockSonarQubeServer mockServer = new MockSonarQubeServer();
            MockTargetsInstaller mockTargetsInstaller = new MockTargetsInstaller();
            TeamBuildPreProcessor preprocessor = new TeamBuildPreProcessor(new MockSonarQubeServerFactory(mockServer), mockTargetsInstaller);

            // Act and assert
            AssertException.Expects<ArgumentNullException>(() => preprocessor.Execute(null, validLogger));
            AssertException.Expects<ArgumentNullException>(() => preprocessor.Execute(validArgs, null));
        }
        public void EmbeddedInstall_CachingScenarios()
        {
            // Arrange
            string     localCacheDir = TestUtils.CreateTestSpecificFolder(this.TestContext);
            TestLogger logger        = new TestLogger();

            Plugin requestA = new Plugin("p111", "1.0-SNAPSHOT", "p1.zip");
            Plugin requestB = new Plugin("p222", "9.1.3.0", "p2.zip");

            MockSonarQubeServer mockServer = new MockSonarQubeServer();

            AddPlugin(mockServer, requestA, "aaa", "bbb");
            AddPlugin(mockServer, requestB, "ccc");

            IList <string> expectedPlugin111Paths = CalculateExpectedCachedFilePaths(localCacheDir, requestA, "p1.zip", "aaa", "bbb");
            IList <string> expectedPlugin222Paths = CalculateExpectedCachedFilePaths(localCacheDir, requestB, "p2.zip", "ccc");
            List <string>  allExpectedPaths       = new List <string>(expectedPlugin111Paths);

            allExpectedPaths.AddRange(expectedPlugin222Paths);

            EmbeddedAnalyzerInstaller testSubject = new EmbeddedAnalyzerInstaller(mockServer, localCacheDir, logger);

            AssertExpectedFilesInCache(0, localCacheDir); // cache should be empty to start with


            // 1. Empty cache -> cache miss -> server called
            IEnumerable <string> actualFiles = testSubject.InstallAssemblies(new Plugin[] { requestA });

            mockServer.AssertMethodCalled(DownloadEmbeddedFileMethodName, 1); // should have tried to download

            AssertExpectedFilesReturned(expectedPlugin111Paths, actualFiles);
            AssertExpectedFilesExist(expectedPlugin111Paths);
            AssertExpectedFilesInCache(3, localCacheDir); // only files for the first request should exist


            // 2. New request + request request -> partial cache miss -> server called only for the new request
            actualFiles = testSubject.InstallAssemblies(new Plugin[] { requestA, requestB });
            mockServer.AssertMethodCalled(DownloadEmbeddedFileMethodName, 2); // new request

            AssertExpectedFilesReturned(allExpectedPaths, actualFiles);
            AssertExpectedFilesExist(allExpectedPaths);
            AssertExpectedFilesInCache(5, localCacheDir); // files for both plugins should exist


            // 3. Repeat the request -> cache hit -> server not called
            actualFiles = testSubject.InstallAssemblies(new Plugin[] { requestA, requestB });
            mockServer.AssertMethodCalled(DownloadEmbeddedFileMethodName, 2); // call count should not have changed

            AssertExpectedFilesReturned(allExpectedPaths, actualFiles);

            // 4. Clear the cache and request both -> cache miss -> multiple requests
            Directory.Delete(localCacheDir, true);
            Assert.IsFalse(Directory.Exists(localCacheDir), "Test error: failed to delete the local cache directory");

            actualFiles = testSubject.InstallAssemblies(new Plugin[] { requestA, requestB });
            mockServer.AssertMethodCalled(DownloadEmbeddedFileMethodName, 4); // two new requests

            AssertExpectedFilesReturned(allExpectedPaths, actualFiles);
            AssertExpectedFilesExist(allExpectedPaths);
            AssertExpectedFilesInCache(5, localCacheDir); // files for both plugins should exist
        }
        public void PreProc_EndToEnd_SuccessCase()
        {
            // Checks end-to-end happy path for the pre-processor i.e.
            // * arguments are parsed
            // * targets are installed
            // * server properties are fetched
            // * rulesets are generated
            // * config file is created

            // Arrange
            string     workingDir = TestUtils.CreateTestSpecificFolder(this.TestContext);
            TestLogger logger     = new TestLogger();

            // Configure the server
            MockSonarQubeServer mockServer = new MockSonarQubeServer();

            ServerDataModel data = mockServer.Data;

            data.ServerProperties.Add("server.key", "server value 1");

            data.InstalledPlugins.Add("csharp");
            data.InstalledPlugins.Add("vbnet");

            data.AddRepository("fxcop", "cs")
            .AddRule("cs.rule1", "cs.rule1.internal")
            .AddRule("cs.rule2", "cs.rule2.internal");

            data.AddRepository("fxcop-vbnet", "vbnet")
            .AddRule("vb.rule1", "vb.rule1.internal")
            .AddRule("vb.rule2", "vb.rule2.internal");

            data.AddQualityProfile("test.profile", "cs")
            .AddProject("key");
            data.AddRuleToProfile("cs.rule1", "test.profile");

            data.AddQualityProfile("test.profile", "vbnet")
            .AddProject("key");
            data.AddRuleToProfile("vb.rule2", "test.profile");

            MockRoslynAnalyzerProvider mockAnalyzerProvider = new MockRoslynAnalyzerProvider();

            mockAnalyzerProvider.SettingsToReturn = new AnalyzerSettings();
            mockAnalyzerProvider.SettingsToReturn.RuleSetFilePath = "c:\\xxx.ruleset";

            MockTargetsInstaller mockTargetsInstaller = new MockTargetsInstaller();

            MockObjectFactory mockFactory = new MockObjectFactory(mockServer, mockTargetsInstaller, mockAnalyzerProvider);


            string[] validArgs = new string[] {
                "/k:key", "/n:name", "/v:1.0",
                "/d:cmd.line1=cmdline.value.1",
                "/d:sonar.host.url=http://host",
                "/d:sonar.log.level=INFO|DEBUG"
            };

            TeamBuildSettings settings;

            using (PreprocessTestUtils.CreateValidNonTeamBuildScope())
                using (new WorkingDirectoryScope(workingDir))
                {
                    settings = TeamBuildSettings.GetSettingsFromEnvironment(new TestLogger());
                    Assert.IsNotNull(settings, "Test setup error: TFS environment variables have not been set correctly");
                    Assert.AreEqual(BuildEnvironment.NotTeamBuild, settings.BuildEnvironment, "Test setup error: build environment was not set correctly");

                    TeamBuildPreProcessor preProcessor = new TeamBuildPreProcessor(mockFactory, logger);

                    // Act
                    bool success = preProcessor.Execute(validArgs);
                    Assert.IsTrue(success, "Expecting the pre-processing to complete successfully");
                }

            // Assert
            AssertDirectoryExists(settings.AnalysisBaseDirectory);
            AssertDirectoryExists(settings.SonarConfigDirectory);
            AssertDirectoryExists(settings.SonarOutputDirectory);
            // The bootstrapper is responsible for creating the bin directory

            mockTargetsInstaller.AssertsTargetsCopied();
            mockServer.AssertMethodCalled("GetProperties", 1);
            mockServer.AssertMethodCalled("GetInternalKeys", 2); // C# and VB

            logger.AssertErrorsLogged(0);
            logger.AssertWarningsLogged(0);
            logger.AssertVerbosity(LoggerVerbosity.Debug);

            AssertConfigFileExists(settings.AnalysisConfigFilePath);
            AnalysisConfig actualConfig = AnalysisConfig.Load(settings.AnalysisConfigFilePath);

            Assert.AreEqual("key", actualConfig.SonarProjectKey, "Unexpected project key");
            Assert.AreEqual("name", actualConfig.SonarProjectName, "Unexpected project name");
            Assert.AreEqual("1.0", actualConfig.SonarProjectVersion, "Unexpected project version");

            Assert.IsNotNull(actualConfig.AnalyzerSettings, "Analyzer settings should not be null");
            Assert.AreEqual("c:\\xxx.ruleset", actualConfig.AnalyzerSettings.RuleSetFilePath, "Unexpected ruleset path");

            AssertExpectedLocalSetting(SonarProperties.HostUrl, "http://host", actualConfig);
            AssertExpectedLocalSetting("cmd.line1", "cmdline.value.1", actualConfig);
            AssertExpectedServerSetting("server.key", "server value 1", actualConfig);

            string fxCopFilePath = AssertFileExists(settings.SonarConfigDirectory, TeamBuildPreProcessor.FxCopCSharpRuleset);

            PreProcessAsserts.AssertRuleSetContainsRules(fxCopFilePath, "cs.rule1");

            fxCopFilePath = AssertFileExists(settings.SonarConfigDirectory, TeamBuildPreProcessor.FxCopVBNetRuleset);
            PreProcessAsserts.AssertRuleSetContainsRules(fxCopFilePath, "vb.rule2");
        }
        public void RulesetGet_Simple()
        {
            string testDir = TestUtils.CreateTestSpecificFolder(this.TestContext);

            ServerDataModel model = new ServerDataModel();

            model.InstalledPlugins.Add("real.plugin1");
            model.InstalledPlugins.Add("unused.plugin1");

            // Set up the rule repositories
            model.AddRepository("empty.repo", "aaa");

            model.AddRepository("repo1", "languageAAA")
                .AddRule("repo1.aaa.r1", "repo1.aaa.r1.internal")
                .AddRule("repo1.aaa.r2", "repo1.aaa.r2.internal");

            model.AddRepository("repo1", "languageBBB")
                .AddRule("repo1.bbb.r1", "repo1.xxx.r1.internal")
                .AddRule("repo1.bbb.r2", "repo1.xxx.r2.internal")
                .AddRule("repo1.bbb.r3", "repo1.xxx.r3.internal");


            // Set up the quality profiles
            model.AddQualityProfile("profile 1", "languageAAA")
                .AddProject("unused.project")
                .AddProject("project1")
                .AddProject("project2:anotherBranch");

            model.AddQualityProfile("profile 2", "languageBBB")
                .AddProject("project1")
                .AddProject("project2");

            model.AddQualityProfile("profile 3", "languageBBB")
                .AddProject("project2:aBranch")
                .AddProject("project3:aThirdBranch");

            // Add rules to the quality profiles
            model.AddRuleToProfile("repo1.aaa.r1", "profile 1"); // Only one rule in the repo

            model.AddRuleToProfile("repo1.bbb.r1", "profile 2");
            model.AddRuleToProfile("repo1.bbb.r2", "profile 2");
            model.AddRuleToProfile("repo1.bbb.r3", "profile 2");

            model.AddRuleToProfile("repo1.bbb.r1", "profile 3");

            MockSonarQubeServer server = new MockSonarQubeServer();
            server.Data = model;

            // 1. Plugin not installed
            string rulesetFilePath = Path.Combine(testDir, "r1.txt");
            RulesetGenerator.Generate(server, "missing.plugin", "languageAAA", "repo1", "project1", null, rulesetFilePath);
            AssertFileDoesNotExist(rulesetFilePath);

            // 2. Language not handled
            RulesetGenerator.Generate(server, "real.plugin1", "unhandled.language", "repo1", "project1", null, rulesetFilePath);
            AssertFileDoesNotExist(rulesetFilePath);

            // 3. Missing project
            RulesetGenerator.Generate(server, "real.plugin1", "languageBBB", "repo1", "missing.project", null, rulesetFilePath);
            AssertFileDoesNotExist(rulesetFilePath);

            // 4. Missing project (project:branch exists)
            RulesetGenerator.Generate(server, "real.plugin1", "languageBBB", "repo1", "project3", null, rulesetFilePath);
            AssertFileDoesNotExist(rulesetFilePath);

            // 5. Missing project:branch
            RulesetGenerator.Generate(server, "real.plugin1", "languageBBB", "repo1", "missing.project", "missingBranch", rulesetFilePath);
            AssertFileDoesNotExist(rulesetFilePath);

            // 6. b) Missing project:branch (project exists)
            RulesetGenerator.Generate(server, "real.plugin1", "languageBBB", "repo1", "project1", "missingBranch", rulesetFilePath);
            AssertFileDoesNotExist(rulesetFilePath);

            // 5. Valid, aaa (default branch)
            string aaa_RulesetFilePath = Path.Combine(testDir, "aaa_ruleset.txt");
            RulesetGenerator.Generate(server, "real.plugin1", "languageAAA", "repo1", "project1", null, aaa_RulesetFilePath);
            PreProcessAsserts.AssertRuleSetContainsRules(aaa_RulesetFilePath, "repo1.aaa.r1");

            // 6. Valid, bbb (default branch)
            string bbb_RulesetFilePath = Path.Combine(testDir, "bbb_ruleset.txt");
            RulesetGenerator.Generate(server, "real.plugin1", "languageBBB", "repo1", "project1", null, bbb_RulesetFilePath);
            PreProcessAsserts.AssertRuleSetContainsRules(bbb_RulesetFilePath,
                "repo1.bbb.r1", "repo1.bbb.r2", "repo1.bbb.r3");

            // 7. Valid, bbb (aBranch branch) - profile 3
            string bbb_aBranch_RulesetFilePath = Path.Combine(testDir, "bbb_aBranch_ruleset.txt");
            RulesetGenerator.Generate(server, "real.plugin1", "languageBBB", "repo1", "project2", "aBranch", bbb_aBranch_RulesetFilePath);
            PreProcessAsserts.AssertRuleSetContainsRules(bbb_aBranch_RulesetFilePath,
                "repo1.bbb.r1");

            // 8. Valid, aaa (anotherBranch branch) - profile 1
            string bbb_anotherBranch_RulesetFilePath = Path.Combine(testDir, "bbb_anotherBranch_ruleset.txt");
            RulesetGenerator.Generate(server, "real.plugin1", "languageAAA", "repo1", "project2", "anotherBranch", bbb_anotherBranch_RulesetFilePath);
            PreProcessAsserts.AssertRuleSetContainsRules(bbb_anotherBranch_RulesetFilePath,
                "repo1.aaa.r1");
        }
        public void BuildWrapper_PluginNotInstalled_NoDownload()
        {
            // Arrange
            string rootDir = TestUtils.CreateTestSpecificFolder(this.TestContext);
            TestLogger logger = new TestLogger();

            MockSonarQubeServer mockServer = new MockSonarQubeServer();

            BuildWrapperInstaller testSubject = new BuildWrapperInstaller(logger);

            // Act
            AnalysisProperties properties = testSubject.InstallBuildWrapper(mockServer, rootDir, "c:\\output\\");

            // Assert
            logger.AssertSingleInfoMessageExists(SonarQube.TeamBuild.PreProcessor.Resources.BW_CppPluginNotInstalled);
            logger.AssertErrorsLogged(0);
            logger.AssertWarningsLogged(0);

            AssertNoFilesExist(rootDir);

            Assert.IsNotNull(properties, "Returned properties should not be null");
            Assert.AreEqual(0, properties.Count, "Not expecting any properties to be set");
        }