CreateTestRuleSet() public static method

public static CreateTestRuleSet ( int numRules, IEnumerable includes = null ) : RuleSet
numRules int
includes IEnumerable
return RuleSet
        public void RuleSetUpdater_FindAllIncludesUnderRoot()
        {
            // Arrange
            const string slnRoot     = @"X:\SolutionDir\";
            string       projectRoot = Path.Combine(slnRoot, @"Project\");
            string       sonarRoot   = Path.Combine(slnRoot, @"Sonar\");
            string       commonRoot  = Path.Combine(slnRoot, @"Common\");

            const string sonarRs1FileName      = "Sonar1.ruleset";
            const string sonarRs2FileName      = "Sonar2.ruleset";
            const string projectRsBaseFileName = "ProjectBase.ruleset";
            const string commonRs1FileName     = "SolutionCommon1.ruleset";
            const string commonRs2FileName     = "SolutionCommon2.ruleset";

            var sonarRs1      = TestRuleSetHelper.CreateTestRuleSet(sonarRoot, sonarRs1FileName);
            var sonarRs2      = TestRuleSetHelper.CreateTestRuleSet(sonarRoot, sonarRs2FileName);
            var projectBaseRs = TestRuleSetHelper.CreateTestRuleSet(projectRoot, projectRsBaseFileName);
            var commonRs1     = TestRuleSetHelper.CreateTestRuleSet(commonRoot, commonRs1FileName);
            var commonRs2     = TestRuleSetHelper.CreateTestRuleSet(commonRoot, commonRs2FileName);

            var inputRuleSet = TestRuleSetHelper.CreateTestRuleSet(projectRoot, "test.ruleset");

            AddRuleSetInclusion(inputRuleSet, projectBaseRs, useRelativePath: true);
            AddRuleSetInclusion(inputRuleSet, commonRs1, useRelativePath: true);
            AddRuleSetInclusion(inputRuleSet, commonRs2, useRelativePath: false);
            var expected1 = AddRuleSetInclusion(inputRuleSet, sonarRs1, useRelativePath: true);
            var expected2 = AddRuleSetInclusion(inputRuleSet, sonarRs2, useRelativePath: false);

            // Act
            RuleSetInclude[] actual = RuleSetUpdater.FindAllIncludesUnderRoot(inputRuleSet, sonarRoot).ToArray();

            // Assert
            CollectionAssert.AreEquivalent(new[] { expected1, expected2 }, actual);
        }
        private static RuleConflictInfo CreateConflictsBasedOnNumberOfCalls(int findConflictCalls)
        {
            RuleSet temp = TestRuleSetHelper.CreateTestRuleSet(2);
            Dictionary <RuleReference, RuleAction> map = new Dictionary <RuleReference, RuleAction>();

            switch (findConflictCalls)
            {
            case 1:
                return(new RuleConflictInfo());    // No conflicts

            case 2:
                return(new RuleConflictInfo(temp.Rules));    // Missing rules

            case 3:
                map[temp.Rules[0]] = RuleAction.Error;
                return(new RuleConflictInfo(map));    // Weakened rules

            case 4:
                map[temp.Rules[0]] = RuleAction.Error;
                return(new RuleConflictInfo(temp.Rules.Skip(1), map));    // One of each

            default:
                FluentAssertions.Execution.Execute.Assertion.FailWith("Called unexpected number of times");
                return(null);
            }
        }
        public void HasInclude_RelativePaths()
        {
            // Arrange
            var target = TestRuleSetHelper.CreateTestRuleSet(@"c:\aaa\Solution\SomeFolder\fullFilePath.ruleset");

            var relativeInclude           = @"Solution\SomeFolder\fullFilePath.ruleset".ToLowerInvariant(); // Catch casing errors
            var sourceWithRelativeInclude = TestRuleSetHelper.CreateTestRuleSetWithIncludes(@"c:\aaa\fullFilePath.ruleset",
                                                                                            relativeInclude, "otherInclude.ruleset");

            // Alternative directory separator, different relative path format
            var relativeInclude2           = @"./Solution/SomeFolder/fullFilePath.ruleset";
            var sourceWithRelativeInclude2 = TestRuleSetHelper.CreateTestRuleSetWithIncludes(@"c:\aaa\fullFilePath.ruleset",
                                                                                             "c://XXX/Solution/SomeFolder/another.ruleset", relativeInclude2);

            // Case 1: Relative include
            // Act
            var hasInclude = RuleSetIncludeChecker.HasInclude(sourceWithRelativeInclude, target);

            // Assert
            hasInclude.Should().BeTrue();

            // Case 2: Relative include, alternative path separators
            // Act
            hasInclude = RuleSetIncludeChecker.HasInclude(sourceWithRelativeInclude2, target);

            // Assert
            hasInclude.Should().BeTrue();
        }
Ejemplo n.º 4
0
        public void RuleSetSerializer_WriteRuleSetFile_ArgChecks()
        {
            RuleSet ruleSet = TestRuleSetHelper.CreateTestRuleSet(this.TestContext.TestRunDirectory, this.TestContext.TestName + ".ruleset");

            Exceptions.Expect <ArgumentNullException>(() => this.testSubject.WriteRuleSetFile(null, @"c:\file.ruleSet"));
            Exceptions.Expect <ArgumentNullException>(() => this.testSubject.WriteRuleSetFile(ruleSet, null));
            Exceptions.Expect <ArgumentNullException>(() => this.testSubject.WriteRuleSetFile(ruleSet, ""));
            Exceptions.Expect <ArgumentNullException>(() => this.testSubject.WriteRuleSetFile(ruleSet, "\t\n"));
        }
        private RuleSet CreateCommonRuleSet(string ruleSetFileName = "SonarQube.ruleset", RuleAction defaultAction = RuleAction.Warning, int rules = DefaultNumberOfRules)
        {
            RuleSet ruleSet = TestRuleSetHelper.CreateTestRuleSet(rules);

            ruleSet.Rules.ToList().ForEach(r => r.Action = defaultAction);
            ruleSet.FilePath = Path.Combine(this.SonarQubeRuleSetFolder, ruleSetFileName);
            ruleSet.WriteToFile(ruleSet.FilePath);

            this.temporaryFiles.AddFile(ruleSet.FilePath, false);
            return(ruleSet);
        }
        private RuleSet CreateVsRuleSet(int rules, string ruleSetFileName, RuleAction defaultAction = RuleAction.Warning)
        {
            RuleSet ruleSet = TestRuleSetHelper.CreateTestRuleSet(rules);

            ruleSet.Rules.ToList().ForEach(r => r.Action = defaultAction);
            ruleSet.FilePath = Path.Combine(this.VsRuleSetsDirectory, ruleSetFileName);
            ruleSet.WriteToFile(ruleSet.FilePath);

            this.temporaryFiles.AddFile(ruleSet.FilePath, false);

            return(ruleSet);
        }
        public void HasInclude_NoIncludes()
        {
            // Arrange
            var ruleSet             = TestRuleSetHelper.CreateTestRuleSet(@"c:\Solution\SomeFolder\fullFilePath.ruleset");
            var unreferencedRuleset = TestRuleSetHelper.CreateTestRuleSet(@"c:\unreferenced.ruleset");

            // Act No includes at all
            var include = RuleSetIncludeChecker.HasInclude(ruleSet, unreferencedRuleset);

            // Assert
            include.Should().BeFalse();
        }
        public void ToRuleSet_DumpsContentToRuleSetFileAndLoadsIt()
        {
            // Arrange
            var ruleset = TestRuleSetHelper.CreateTestRuleSet(numRules: 10);
            var roslynProfileExporter = RoslynExportProfileHelper.CreateExport(ruleset);

            // Act
            var result = RulesHelper.ToRuleSet(roslynProfileExporter);

            // Assert
            TestRuleSetHelper.RuleSetToXml(result).Should().Be(TestRuleSetHelper.RuleSetToXml(ruleset));
        }
        public void ToQualityProfile_SelectRulesNotMarkedAsNone()
        {
            // Arrange
            var ruleset           = TestRuleSetHelper.CreateTestRuleSet(numRules: 5);
            var nonNoneRulesCount = ruleset.Rules.Count(x => x.Action != RuleAction.None);

            // Act
            var result = RulesHelper.ToQualityProfile(ruleset, Language.CSharp);

            // Assert
            result.Language.Should().Be(Language.CSharp);
            result.Rules.Should().HaveCount(nonNoneRulesCount);
        }
        public void HasInclude_NoIncludesFromSourceToTarget()
        {
            // Arrange
            var target = TestRuleSetHelper.CreateTestRuleSet(@"c:\Solution\SomeFolder\fullFilePath.ruleset");

            var sourceWithInclude = TestRuleSetHelper.CreateTestRuleSetWithIncludes(@"c:\fullFilePath.ruleset",
                                                                                    "include1", "c:\\foo\\include2", "fullFilePath.ruleset");

            // Act - No includes from source to target
            var include = RuleSetIncludeChecker.HasInclude(sourceWithInclude, target);

            // Assert
            include.Should().BeFalse();
        }
        public void HasInclude_RelativePaths_Complex2()
        {
            // Arrange
            var target = TestRuleSetHelper.CreateTestRuleSet(@"c:\Solution\SomeFolder\fullFilePath.ruleset");

            var relativeInclude           = @"./.\..\..\Dummy1\Dummy2\..\.././Solution\SomeFolder\fullFilePath.ruleset";
            var sourceWithRelativeInclude = TestRuleSetHelper.CreateTestRuleSetWithIncludes(@"c:\aaa\bbb\fullFilePath.ruleset",
                                                                                            relativeInclude);

            // Act
            var hasInclude = RuleSetIncludeChecker.HasInclude(sourceWithRelativeInclude, target);

            // Assert
            hasInclude.Should().BeTrue();
        }
        public void HasInclude_SourceIsTarget_ReturnsTrue()
        {
            // Covers the case where the ruleset is included directly in the project, rather
            // than indirectly as a RuleSetInclude in another ruleset.

            // Arrange
            var source = TestRuleSetHelper.CreateTestRuleSet(@"c:\Solution\SomeFolder\fullFilePath.ruleset");
            var target = TestRuleSetHelper.CreateTestRuleSet(@"C:/SOLUTION\./SomeFolder\fullFilePath.ruleset");

            // Act
            var include = RuleSetIncludeChecker.HasInclude(source, target);

            // Assert
            include.Should().BeTrue();
        }
        public void HasInclude_AbsolutePaths()
        {
            // Arrange
            var target = TestRuleSetHelper.CreateTestRuleSet(@"c:\Solution\SomeFolder\fullFilePath.ruleset");

            var absoluteInclude           = target.FilePath.ToUpperInvariant(); // Catch casing errors
            var sourceWithAbsoluteInclude = TestRuleSetHelper.CreateTestRuleSetWithIncludes(@"c:\fullFilePath.ruleset",
                                                                                            ".\\include1.ruleset", absoluteInclude, "c:\\dummy\\include2.ruleset");

            // Act
            var hasInclude = RuleSetIncludeChecker.HasInclude(sourceWithAbsoluteInclude, target);

            // Assert
            hasInclude.Should().BeTrue();
        }
Ejemplo n.º 14
0
        public void RuleSetSerializer_LoadRuleSet()
        {
            // Setup
            RuleSet ruleSet = TestRuleSetHelper.CreateTestRuleSet(this.TestContext.TestRunDirectory, this.TestContext.TestName + ".ruleset");

            this.temporaryFiles.AddFile(ruleSet.FilePath, false);
            ruleSet.WriteToFile(ruleSet.FilePath);
            this.fileSystem.RegisterFile(ruleSet.FilePath);

            // Act
            RuleSet loaded = this.testSubject.LoadRuleSet(ruleSet.FilePath);

            // Verify
            Assert.IsNotNull(loaded, "Expected to load a rule set file");
            RuleSetAssert.AreEqual(ruleSet, loaded, "Loaded unexpected rule set");
        }
Ejemplo n.º 15
0
        public void RuleSetSerializer_LoadRuleSet()
        {
            // Arrange
            RuleSet ruleSet = TestRuleSetHelper.CreateTestRuleSet(this.TestContext.TestRunDirectory, this.TestContext.TestName + ".ruleset");

            temporaryFiles.AddFile(ruleSet.FilePath, false);
            ruleSet.WriteToFile(ruleSet.FilePath);
            fileSystem.AddFile(ruleSet.FilePath, new MockFileData(""));

            // Act
            RuleSet loaded = this.testSubject.LoadRuleSet(ruleSet.FilePath);

            // Assert
            loaded.Should().NotBeNull("Expected to load a rule set file");
            RuleSetAssert.AreEqual(ruleSet, loaded, "Loaded unexpected rule set");
        }
Ejemplo n.º 16
0
        public void RuleSetSerializer_WriteRuleSetFile()
        {
            // Setup
            RuleSet ruleSet = TestRuleSetHelper.CreateTestRuleSet(this.TestContext.TestRunDirectory, this.TestContext.TestName + ".ruleset");

            this.temporaryFiles.AddFile(ruleSet.FilePath, false);
            string expectedPath = Path.Combine(this.TestContext.TestRunDirectory, this.TestContext.TestName + "Other.ruleset");

            // Act
            this.testSubject.WriteRuleSetFile(ruleSet, expectedPath);

            // Verify
            Assert.IsTrue(File.Exists(expectedPath), "File not exists where expected");
            Assert.IsFalse(File.Exists(ruleSet.FilePath), "Expected to save only to the specified file path");
            RuleSet loaded = RuleSet.LoadFromFile(expectedPath);

            RuleSetAssert.AreEqual(ruleSet, loaded, "Written unexpected rule set");
        }
        public void HasInclude_RelativePaths_Complex()
        {
            // Regression test for https://github.com/SonarSource/sonarlint-visualstudio/issues/658
            // "SonarLint for Visual Studio 2017 plugin does not respect shared imports "

            // Arrange
            var target = TestRuleSetHelper.CreateTestRuleSet(@"c:\Solution\SomeFolder\fullFilePath.ruleset");

            var relativeInclude           = @".\..\..\Solution\SomeFolder\fullFilePath.ruleset";
            var sourceWithRelativeInclude = TestRuleSetHelper.CreateTestRuleSetWithIncludes(@"c:\aaa\bbb\fullFilePath.ruleset",
                                                                                            relativeInclude);

            // Act
            var hasInclude = RuleSetIncludeChecker.HasInclude(sourceWithRelativeInclude, target);

            // Assert
            hasInclude.Should().BeTrue();
        }
        public void RuleSetConflictsController_FixConflictsCommandExecution()
        {
            // Arrange
            var testSubject = new RuleSetConflictsController(this.host, this.conflictsManager);

            this.ConfigureServiceProviderForFixConflictsCommandExecution();
            this.host.VisualStateManager.IsBusy = false;
            this.host.VisualStateManager.SetBoundProject(new Uri("http://foo"), null, "project123");
            var section = ConfigurableSectionController.CreateDefault();

            this.host.SetActiveSection(section);
            ConfigurableUserNotification notifications = (ConfigurableUserNotification)section.UserNotifications;

            ProjectRuleSetConflict[] conflicts = new[] { ConfigurableConflictsManager.CreateConflict() };

            RuleSet fixedRuleSet = TestRuleSetHelper.CreateTestRuleSet(3);

            fixedRuleSet.FilePath = "MyFixedRules.ruleset";

            RuleSetInspectorTestDataProvider inspectorData = new RuleSetInspectorTestDataProvider();
            var weakenedRulesMap = new Dictionary <RuleReference, RuleAction>();

            inspectorData.FindConflictsResult = new RuleConflictInfo(new RuleReference[0], weakenedRulesMap);
            inspectorData.FixConflictsResult  = new FixedRuleSetInfo(fixedRuleSet, new[] { "reset.ruleset" }, new[] { "deletedRuleId1" });
            this.ruleSetInspector.FindConflictingRulesAction = inspectorData.FindConflictingRulesAction;
            this.ruleSetInspector.FixConflictingRulesAction  = inspectorData.FixConflictingRulesAction;

            ICommand fixMeCommand = testSubject.CreateFixConflictsCommand(conflicts);

            section.UserNotifications.ShowNotificationWarning("fix me", NotificationIds.RuleSetConflictsId, fixMeCommand);

            // Act
            fixMeCommand.Execute(null);

            // Assert
            this.sccFS.files.Should().ContainKey(fixedRuleSet.FilePath);
            this.rsSerializer.AssertRuleSetsAreSame(fixedRuleSet.FilePath, fixedRuleSet);
            this.outputWindowPane.AssertOutputStrings(1);
            this.outputWindowPane.AssertMessageContainsAllWordsCaseSensitive(0,
                                                                             words: new[] { fixedRuleSet.FilePath, "deletedRuleId1", "reset.ruleset" },
                                                                             splitter: new[] { '\n', '\r', '\t', '\'', ':' });
            notifications.AssertNoNotification(NotificationIds.RuleSetConflictsId);
        }
        public void ConflictsManager_GetCurrentConflicts_HasConflicts_WithAggregationApplied()
        {
            // Arrange
            this.SetSolutionBinding(SonarLintMode.LegacyConnected);
            this.SetValidProjects(3);
            this.SetValidSolutionRuleSetPerProjectKind();
            IEnumerable <RuleSetDeclaration> knownDeclarations = this.SetValidRuleSetDeclarationPerProjectAndConfiguration(
                useUniqueProjectRuleSets: false,
                configurationNames: new[] { "Debug", "Release" });

            this.ConfigureInspectorWithConflicts(knownDeclarations, () =>
            {
                RuleSet temp = TestRuleSetHelper.CreateTestRuleSet(1);
                return(new RuleConflictInfo(temp.Rules)); // Missing rules
            });

            // Act + Assert
            testSubject.GetCurrentConflicts().Should().HaveCount(3, "Expecting 3 conflicts (1 per project) since the ruleset declaration for project configuration are the same");
            this.outputWindowPane.AssertOutputStrings(0);
        }
        private RuleSet CreateProjectRuleSetWithIncludes(int rules, string solutionRuleSetToInclude, IncludeType solutionIncludeType, RuleAction defaultAction = RuleAction.Warning, params string[] otherIncludes)
        {
            string projectRuleSetFilePath = Path.Combine(this.ProjectRuleSetFolder, Guid.NewGuid() + ".ruleset");
            string solutionInclude        = solutionIncludeType == IncludeType.AsIs ? solutionRuleSetToInclude : PathHelper.CalculateRelativePath(projectRuleSetFilePath, solutionRuleSetToInclude);

            string[] includes = new[] { solutionInclude };
            if ((otherIncludes?.Length ?? 0) > 0)
            {
                includes = includes.Concat(otherIncludes).ToArray();
            }

            RuleSet ruleSet = TestRuleSetHelper.CreateTestRuleSet(rules, includes);

            ruleSet.Rules.ToList().ForEach(r => r.Action = defaultAction);
            ruleSet.FilePath = projectRuleSetFilePath;
            ruleSet.WriteToFile(ruleSet.FilePath);

            this.temporaryFiles.AddFile(ruleSet.FilePath, false);

            return(ruleSet);
        }
        public void RuleSetHelper_FindInclude()
        {
            // Arrange
            RuleSet target = TestRuleSetHelper.CreateTestRuleSet(@"c:\Solution\SomeFolder\fullFilePath.ruleset");
            RuleSet sourceWithRelativeInclude = TestRuleSetHelper.CreateTestRuleSet(@"c:\fullFilePath.ruleset");
            string  relativeInclude           = @"Solution\SomeFolder\fullFilePath.ruleset".ToLowerInvariant(); // Catch casing errors

            sourceWithRelativeInclude.RuleSetIncludes.Add(new RuleSetInclude(relativeInclude, RuleAction.Error));
            RuleSet sourceWithAbsoluteInclude = TestRuleSetHelper.CreateTestRuleSet(@"c:\fullFilePath.ruleset");
            string  absoluteInclude           = target.FilePath.ToUpperInvariant(); // Catch casing errors

            sourceWithAbsoluteInclude.RuleSetIncludes.Add(new RuleSetInclude(absoluteInclude, RuleAction.Warning));
            RuleSetInclude include;

            // Case 1: Relative include
            // Act
            include = RuleSetHelper.FindInclude(sourceWithRelativeInclude, target);

            // Assert
            StringComparer.OrdinalIgnoreCase.Equals(include.FilePath, relativeInclude).Should().BeTrue($"Unexpected include {include.FilePath} instead of {relativeInclude}");

            // Case 2: Absolute include
            // Act
            include = RuleSetHelper.FindInclude(sourceWithAbsoluteInclude, target);

            // Assert
            StringComparer.OrdinalIgnoreCase.Equals(include.FilePath, absoluteInclude).Should().BeTrue($"Unexpected include {include.FilePath} instead of {absoluteInclude}");

            // Case 3: No includes at all
            // Act
            include = RuleSetHelper.FindInclude(target, target);
            // Assert
            include.Should().BeNull("No includes at all");

            // Case 4: No includes from source to target
            // Act
            include = RuleSetHelper.FindInclude(sourceWithRelativeInclude, sourceWithAbsoluteInclude);
            // Assert
            include.Should().BeNull("No includes from source to target");
        }
        public void RuleSetUpdater_RemoveAllIncludesUnderRoot()
        {
            // Arrange
            const string slnRoot     = @"X:\SolutionDir\";
            string       projectRoot = Path.Combine(slnRoot, @"Project\");
            string       sonarRoot   = Path.Combine(slnRoot, @"Sonar\");
            string       commonRoot  = Path.Combine(slnRoot, @"Common\");

            const string sonarRs1FileName      = "Sonar1.ruleset";
            const string sonarRs2FileName      = "Sonar2.ruleset";
            const string projectRsBaseFileName = "ProjectBase.ruleset";
            const string commonRs1FileName     = "SolutionCommon1.ruleset";
            const string commonRs2FileName     = "SolutionCommon2.ruleset";

            var sonarRs1      = TestRuleSetHelper.CreateTestRuleSet(sonarRoot, sonarRs1FileName);
            var sonarRs2      = TestRuleSetHelper.CreateTestRuleSet(sonarRoot, sonarRs2FileName);
            var projectBaseRs = TestRuleSetHelper.CreateTestRuleSet(projectRoot, projectRsBaseFileName);
            var commonRs1     = TestRuleSetHelper.CreateTestRuleSet(commonRoot, commonRs1FileName);
            var commonRs2     = TestRuleSetHelper.CreateTestRuleSet(commonRoot, commonRs2FileName);

            var inputRuleSet = TestRuleSetHelper.CreateTestRuleSet(projectRoot, "test.ruleset");

            AddRuleSetInclusion(inputRuleSet, projectBaseRs, useRelativePath: true);
            AddRuleSetInclusion(inputRuleSet, commonRs1, useRelativePath: true);
            AddRuleSetInclusion(inputRuleSet, commonRs2, useRelativePath: false);
            AddRuleSetInclusion(inputRuleSet, sonarRs1, useRelativePath: true);
            AddRuleSetInclusion(inputRuleSet, sonarRs2, useRelativePath: false);

            var expectedRuleSet = TestRuleSetHelper.CreateTestRuleSet(projectRoot, "test.ruleset");

            AddRuleSetInclusion(expectedRuleSet, projectBaseRs, useRelativePath: true);
            AddRuleSetInclusion(expectedRuleSet, commonRs1, useRelativePath: true);
            AddRuleSetInclusion(expectedRuleSet, commonRs2, useRelativePath: false);

            // Act
            RuleSetUpdater.RemoveAllIncludesUnderRoot(inputRuleSet, sonarRoot);

            // Assert
            RuleSetAssert.AreEqual(expectedRuleSet, inputRuleSet);
        }
        public void ConflictsManager_GetCurrentConflicts_HasConflicts_WithAggregationApplied()
        {
            // Setup
            var testSubject = new ConflictsManager(this.serviceProvider);

            this.SetValidSolutionBinding();
            this.SetValidProjects(3);
            this.SetValidSolutionRuleSetPerProjectKind();
            IEnumerable <RuleSetDeclaration> knownDeclarations = this.SetValidRuleSetDeclarationPerProjectAndConfiguration(
                useUniqueProjectRuleSets: false,
                configurationNames: new[] { "Debug", "Release" });

            this.ConfigureInspectorWithConflicts(knownDeclarations, () =>
            {
                RuleSet temp = TestRuleSetHelper.CreateTestRuleSet(1);
                return(new RuleConflictInfo(temp.Rules)); // Missing rules
            });

            // Act + Verify
            Assert.AreEqual(3, testSubject.GetCurrentConflicts().Count, "Expecting 3 conflicts (1 per project) since the ruleset declaration for project configuration are the same");
            this.outputWindowPane.AssertOutputStrings(0);
        }
Ejemplo n.º 24
0
        public void ConflictsManager_GetCurrentConflicts_HasConflicts_WithoutAggregationApplied()
        {
            // Arrange
            var testSubject = new ConflictsManager(this.serviceProvider);

            this.SetValidSolutionBinding();
            this.SetValidProjects(3);
            this.SetValidSolutionRuleSetPerProjectKind();
            IEnumerable <RuleSetDeclaration> knownDeclarations = this.SetValidRuleSetDeclarationPerProjectAndConfiguration(
                useUniqueProjectRuleSets: true,
                configurationNames: new[] { "Debug", "Release" });

            this.ConfigureInspectorWithConflicts(knownDeclarations, () =>
            {
                RuleSet temp = TestRuleSetHelper.CreateTestRuleSet(1);
                return(new RuleConflictInfo(temp.Rules)); // Missing rules
            });

            // Act + Assert
            testSubject.GetCurrentConflicts().Should().HaveCount(6, "Expecting 6 conflicts (3 projects x 2 configuration)");
            this.outputWindowPane.AssertOutputStrings(0);
        }
        public void RuleSetUpdater_UpdateExistingProjectRuleSet()
        {
            // Arrange
            const string existingProjectRuleSetPath = @"X:\MySolution\ProjectOne\proj1.ruleset";
            const string existingInclude            = @"..\SolutionRuleSets\sonarqube1.ruleset";

            const string newSolutionRuleSetPath = @"X:\MySolution\SolutionRuleSets\sonarqube2.ruleset";
            const string expectedInclude        = @"..\SolutionRuleSets\sonarqube2.ruleset";

            var existingProjectRuleSet = TestRuleSetHelper.CreateTestRuleSet(existingProjectRuleSetPath);

            existingProjectRuleSet.RuleSetIncludes.Add(new RuleSetInclude(existingInclude, RuleAction.Default));

            var expectedRuleSet = TestRuleSetHelper.CreateTestRuleSet(existingProjectRuleSetPath);

            expectedRuleSet.RuleSetIncludes.Add(new RuleSetInclude(expectedInclude, RuleAction.Default));

            // Act
            RuleSetUpdater.UpdateExistingProjectRuleSet(existingProjectRuleSet, newSolutionRuleSetPath);

            // Assert
            RuleSetAssert.AreEqual(expectedRuleSet, existingProjectRuleSet, "Update should delete previous solution rulesets, and replace them with a new one provide");
        }
        private void SonarQubeServiceWrapper_TryGetExportProfile(Language language)
        {
            using (var testSubject = new TestableSonarQubeServiceWrapper(this.serviceProvider))
            {
                // Setup
                QualityProfile profile = CreateRandomQualityProfile(language);
                var            project = new ProjectInformation {
                    Key = "awesome1", Name = "My Awesome Project"
                };
                var expectedExport         = RoslynExportProfileHelper.CreateExport(ruleSet: TestRuleSetHelper.CreateTestRuleSet(3));
                var roslynExporter         = SonarQubeServiceWrapper.CreateRoslynExporterName(language);
                ConnectionInformation conn = ConfigureValidConnection(testSubject, new[] { project });

                // Setup test server
                RegisterProfileExportQueryValidator(testSubject);

                RequestHandler getExportHandler = testSubject.RegisterRequestHandler(
                    SonarQubeServiceWrapper.CreateQualityProfileExportUrl(profile, language, roslynExporter),
                    ctx => ServiceProfileExport(ctx, expectedExport)
                    );

                // Act
                RoslynExportProfile actualExport;
                Assert.IsTrue(testSubject.TryGetExportProfile(conn, profile, language, CancellationToken.None, out actualExport), "TryGetExportProfile failed unexpectedly");

                // Verify
                Assert.IsNotNull(actualExport, "Expected a profile export to be returned");
                RoslynExportProfileHelper.AssertAreEqual(expectedExport, actualExport);
                getExportHandler.AssertHandlerCalled(1);
            }
        }