Conflicts manager for a SonarQube bound solution
Inheritance: IConflictsManager
        public void ConflictsManager_Ctor()
        {
            Exceptions.Expect<ArgumentNullException>(() => new ConflictsManager(null));

            var testSubject = new ConflictsManager(this.serviceProvider);
            Assert.IsNotNull(testSubject, "Avoid code analysis warning when testSubject is unused");
        }
        public void ConflictsManager_GetCurrentConflicts_NotBound()
        {
            // Setup
            var testSubject = new ConflictsManager(this.serviceProvider);
            this.SetValidProjects();
            this.solutionBinding.CurrentBinding = null;

            // Act + Verify
            Assert.AreEqual(0, testSubject.GetCurrentConflicts().Count, "Not expecting any conflicts since solution is not bound");
            this.outputWindowPane.AssertOutputStrings(0);
        }
        public void ConflictsManager_GetCurrentConflicts_MissingBaselineFile()
        {
            // Setup
            var testSubject = new ConflictsManager(this.serviceProvider);
            this.SetValidSolutionBinding();
            this.SetValidProjects();

            // Act + Verify
            Assert.AreEqual(0, testSubject.GetCurrentConflicts().Count, "Not expecting any conflicts since the solution baseline is missing");
            this.outputWindowPane.AssertOutputStrings(1);
            this.outputWindowPane.AssertMessageContainsAllWordsCaseSensitive(0,
                words: new[] { Constants.SonarQubeManagedFolderName },
                splitter: new[] { Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar });
        }
        public void ConflictsManager_GetCurrentConflicts_NoValidProjects()
        {
            // Setup
            var testSubject = new ConflictsManager(this.serviceProvider);
            this.SetValidSolutionBinding();

            // Act + Verify
            Assert.AreEqual(0, testSubject.GetCurrentConflicts().Count, "Not expecting any conflicts since there are no projects");
            this.outputWindowPane.AssertOutputStrings(0);
        }
        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);
        }
        public void ConflictsManager_GetCurrentConflicts_HasConflicts()
        {
            // Setup
            var testSubject = new ConflictsManager(this.serviceProvider);
            this.SetValidSolutionBinding();
            this.SetValidProjects(4);
            this.SetValidSolutionRuleSetPerProjectKind();
            IEnumerable<RuleSetDeclaration> knownDeclarations = this.SetSingleValidRuleSetDeclarationPerProject();
            int findConflictCalls = 0;
            this.ConfigureInspectorWithConflicts(knownDeclarations, () =>
            {
                findConflictCalls++;
                return CreateConflictsBasedOnNumberOfCalls(findConflictCalls);
            });

            // Act + Verify
            Assert.AreEqual(3, testSubject.GetCurrentConflicts().Count, "Expect 3 conflicts (1st call is not a conflict)");
            this.outputWindowPane.AssertOutputStrings(0);
            Assert.AreEqual(4, findConflictCalls);
        }
        public void ConflictsManager_GetCurrentConflicts_ExceptionDuringFindConflicts()
        {
            // Setup
            var testSubject = new ConflictsManager(this.serviceProvider);
            this.SetValidSolutionBinding();
            this.SetValidProjects(2);
            this.SetValidSolutionRuleSetPerProjectKind();
            IEnumerable<RuleSetDeclaration> knownDeclarations = this.SetSingleValidRuleSetDeclarationPerProject();
            int findConflictCalls = 0;
            this.ConfigureInspectorWithConflicts(knownDeclarations, () =>
            {
                findConflictCalls++;
                throw new Exception($"Hello world{findConflictCalls} ");
            });

            // Act + Verify
            int conflicts = 0;
            using (new AssertIgnoreScope()) // Ignore asserts on exception
            {
                conflicts = testSubject.GetCurrentConflicts().Count;
            }

            Assert.AreEqual(0, conflicts, "Expect 0 conflicts since failed each time");
            this.outputWindowPane.AssertOutputStrings(2);
            this.outputWindowPane.AssertMessageContainsAllWordsCaseSensitive(0, new[] { "Hello", "world1" });
            this.outputWindowPane.AssertMessageContainsAllWordsCaseSensitive(1, new[] { "Hello", "world2" });
            Assert.AreEqual(2, findConflictCalls);
        }
        public void ConflictsManager_GetCurrentConflicts_NoConflicts()
        {
            // Setup
            var testSubject = new ConflictsManager(this.serviceProvider);
            this.SetValidSolutionBinding();
            this.SetValidProjects();
            this.SetValidSolutionRuleSetPerProjectKind();
            IEnumerable<RuleSetDeclaration> knownDeclarations = this.SetSingleValidRuleSetDeclarationPerProject();

            bool findConflictsWasCalled = false;
            this.ConfigureInspectorWithConflicts(knownDeclarations, () =>
            {
                findConflictsWasCalled = true;
                return new RuleConflictInfo();
            });

            // Act + Verify
            Assert.AreEqual(0, testSubject.GetCurrentConflicts().Count, "Not expecting any conflicts since there are no conflicts");
            this.outputWindowPane.AssertOutputStrings(0);
            Assert.IsTrue(findConflictsWasCalled);
        }