public void RoslynConfig_ValidProfile()
        {
            // Arrange
            var rootFolder = CreateTestFolders();
            var logger     = new TestLogger();
            IList <ActiveRule> activeRules   = createActiveRules();
            IList <string>     inactiveRules = createInactiveRules();
            var language      = RoslynAnalyzerProvider.CSharpLanguage;
            var mockInstaller = new MockAnalyzerInstaller
            {
                AssemblyPathsToReturn = new HashSet <string>(new string[] { "c:\\assembly1.dll", "d:\\foo\\assembly2.dll" })
            };
            var settings = CreateSettings(rootFolder);

            var testSubject = new RoslynAnalyzerProvider(mockInstaller, logger);

            // Act
            var actualSettings = testSubject.SetupAnalyzer(settings, ServerSettings, activeRules, inactiveRules, language);

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

            CheckRuleset(actualSettings, rootFolder, language);
            CheckExpectedAdditionalFiles(rootFolder, language, settings.SonarOutputDirectory, actualSettings);
            CheckExpectedAssemblies(actualSettings, "c:\\assembly1.dll", "d:\\foo\\assembly2.dll");
            var plugins = new List <string>
            {
                "wintellect",
                "csharp"
            };

            mockInstaller.AssertExpectedPluginsRequested(plugins);
        }
Beispiel #2
0
        public void RoslynConfig_ValidProfile()
        {
            // Arrange
            string                       rootFolder     = CreateTestFolders();
            TestLogger                   logger         = new TestLogger();
            IList <ActiveRule>           activeRules    = createActiveRules();
            IList <string>               inactiveRules  = createInactiveRules();
            string                       language       = RoslynAnalyzerProvider.CSharpLanguage;
            IDictionary <string, string> serverSettings = createServerSettings();
            MockAnalyzerInstaller        mockInstaller  = new MockAnalyzerInstaller();

            mockInstaller.AssemblyPathsToReturn = new HashSet <string>(new string[] { "c:\\assembly1.dll", "d:\\foo\\assembly2.dll" });
            TeamBuildSettings settings = CreateSettings(rootFolder);

            RoslynAnalyzerProvider testSubject = new RoslynAnalyzerProvider(mockInstaller, logger);

            // Act
            AnalyzerSettings actualSettings = testSubject.SetupAnalyzer(settings, serverSettings, activeRules, inactiveRules, language);

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

            CheckRuleset(actualSettings, rootFolder, language);
            CheckExpectedAdditionalFiles(rootFolder, language, actualSettings);
            CheckExpectedAssemblies(actualSettings, "c:\\assembly1.dll", "d:\\foo\\assembly2.dll");
            List <string> plugins = new List <string>();

            plugins.Add("wintellect");
            plugins.Add("csharp");
            mockInstaller.AssertExpectedPluginsRequested(plugins);
        }
        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);
        }
Beispiel #4
0
        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");
        }
Beispiel #5
0
        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);
        }
        public void RoslynConfig_NoAssemblies()
        {
            // Arrange
            var rootFolder = CreateTestFolders();
            var logger     = new TestLogger();
            IList <ActiveRule> activeRules   = createActiveRules();
            IList <string>     inactiveRules = createInactiveRules();
            var language = RoslynAnalyzerProvider.CSharpLanguage;

            // missing properties to get plugin related properties
            IDictionary <string, string> serverSettings = new Dictionary <string, string>
            {
                { "wintellect.analyzerId", "Wintellect.Analyzers" },
                { "wintellect.ruleNamespace", "Wintellect.Analyzers" },
                { "sonaranalyzer-cs.analyzerId", "SonarAnalyzer.CSharp" },
                { "sonaranalyzer-cs.ruleNamespace", "SonarAnalyzer.CSharp" }
            };

            var mockInstaller = new MockAnalyzerInstaller
            {
                AssemblyPathsToReturn = new HashSet <string>(new string[] { "c:\\assembly1.dll", "d:\\foo\\assembly2.dll" })
            };
            var settings = CreateSettings(rootFolder);

            var testSubject = new RoslynAnalyzerProvider(mockInstaller, logger);

            // Act
            var actualSettings = testSubject.SetupAnalyzer(settings, serverSettings, activeRules, inactiveRules, language);

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

            CheckRuleset(actualSettings, rootFolder, language);
            Assert.IsTrue(!actualSettings.AnalyzerAssemblyPaths.Any());
            var plugins = new List <string>();

            mockInstaller.AssertExpectedPluginsRequested(plugins);
        }
Beispiel #7
0
        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");
        }
        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.AssertExpectedPackagesRequested(branchSpecificProfile.Packages);
            CheckExpectedAssemblies(actualSettings, "c:\\assembly1.dll", "d:\\foo\\assembly2.dll", "e:\\assembly3.dll");
        }
        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.AssertExpectedPackagesRequested(testProfile.Packages);
            CheckExpectedAssemblies(actualSettings, "c:\\assembly1.dll", "d:\\foo\\assembly2.dll");
        }