public void RuleSetInspector_FixConflictingRules_AllAtOnce()
        {
            // Arrange
            RuleSet solutionRuleSet = this.CreateCommonRuleSet(defaultAction: RuleAction.Error);

            RuleSet otherRuleSet = this.CreateUserSharedRuleSet($"User.ruleset", RuleAction.Info);

            RuleSet projectRuleSet  = this.CreateProjectRuleSetWithIncludes(1, solutionRuleSet.FilePath, IncludeType.AsRelativeToProject, RuleAction.Warning, otherRuleSet.FilePath);
            string  relativeInclude = PathHelper.CalculateRelativePath(projectRuleSet.FilePath, solutionRuleSet.FilePath);

            FindInclude(projectRuleSet, relativeInclude).Action = RuleAction.Hidden;
            projectRuleSet.WriteToFile(projectRuleSet.FilePath);

            // Sanity
            AssertConflictsExpected(solutionRuleSet.FilePath, projectRuleSet.FilePath, "Expected 3 weakened rules since solution include was set to Hidden (and also a rule override with a weaker action)");

            // Act
            FixedRuleSetInfo fixedInfo = this.testSubject.FixConflictingRules(solutionRuleSet.FilePath, projectRuleSet.FilePath);

            // Assert
            VerifyFix(fixedInfo, expectedIncludesReset: 1, expectedRulesDeleted: 1);
            RuleSet fixedTarget     = fixedInfo.FixedRuleSet;
            RuleSet expectedRuleSet = this.CreateProjectRuleSetWithIncludes(0, solutionRuleSet.FilePath, IncludeType.AsRelativeToProject, otherIncludes: otherRuleSet.FilePath);

            RuleSetAssert.AreEqual(expectedRuleSet, fixedTarget, "Expected the include action to change to default and the conflicting rules to be removed");
            VerifyFixedRuleSetIsNotPersisted(solutionRuleSet, projectRuleSet, fixedTarget);
        }
        public void RuleSetInspector_FixConflictingRules_RuleOverrideConflict()
        {
            // Arrange
            RuleSet solutionRuleSet = this.CreateCommonRuleSet(rules: 5);

            // Create less rules than in the solution rule set and create conflicts not in all of them
            RuleSet projectRuleSet = this.CreateProjectRuleSetWithIncludes(4, solutionRuleSet.FilePath, IncludeType.AsRelativeToProject);

            projectRuleSet.Rules[1].Action = RuleAction.Hidden;
            projectRuleSet.Rules[2].Action = RuleAction.Info;
            projectRuleSet.Rules[3].Action = RuleAction.None;
            projectRuleSet.WriteToFile(projectRuleSet.FilePath);

            // Sanity
            AssertConflictsExpected(solutionRuleSet.FilePath, projectRuleSet.FilePath, "Expected 2 weakened rules and 1 missing due to rule overrides at the project level");

            // Act
            FixedRuleSetInfo fixedInfo = this.testSubject.FixConflictingRules(solutionRuleSet.FilePath, projectRuleSet.FilePath);

            // Assert
            VerifyFix(fixedInfo, expectedIncludesReset: 1, expectedRulesDeleted: 3);
            RuleSet fixedTarget     = fixedInfo.FixedRuleSet;
            RuleSet expectedRuleSet = this.CreateProjectRuleSetWithIncludes(1, solutionRuleSet.FilePath, IncludeType.AsRelativeToProject);

            RuleSetAssert.AreEqual(expectedRuleSet, fixedTarget, "Expected the conflicting rules to be deleted");
            VerifyFixedRuleSetIsNotPersisted(solutionRuleSet, projectRuleSet, fixedTarget);
        }
Exemple #3
0
        public void RuleSetInspector_FixConflictingRules_IncludeConflict()
        {
            // Setup
            RuleSet solutionRuleSet = this.CreateCommonRuleSet();

            RuleSet otherRuleSet = this.CreateUserSharedRuleSet($"User.ruleset", RuleAction.Info);

            RuleSet projectRuleSet  = this.CreateProjectRuleSetWithIncludes(0, solutionRuleSet.FilePath, IncludeType.AsRelativeToProject, RuleAction.Default, otherRuleSet.FilePath);
            string  relativeInclude = PathHelper.CalculateRelativePath(projectRuleSet.FilePath, solutionRuleSet.FilePath);

            FindInclude(projectRuleSet, relativeInclude).Action = RuleAction.Hidden;
            projectRuleSet.WriteToFile(projectRuleSet.FilePath);

            // Sanity
            AssertConflictsExpected(solutionRuleSet.FilePath, projectRuleSet.FilePath, "Expected 3 weakened rules since solution include was set to Hidden");

            // Act
            FixedRuleSetInfo fixedInfo = this.testSubject.FixConflictingRules(solutionRuleSet.FilePath, projectRuleSet.FilePath);

            // Verify
            VerifyFix(fixedInfo, expectedIncludesReset: 1, expectedRulesDeleted: 0);
            RuleSet fixedTarget     = fixedInfo.FixedRuleSet;
            RuleSet expectedRuleSet = this.CreateProjectRuleSetWithIncludes(0, solutionRuleSet.FilePath, IncludeType.AsRelativeToProject, RuleAction.Warning, otherRuleSet.FilePath);

            RuleSetAssert.AreEqual(expectedRuleSet, fixedTarget, "Expected the include action to be fixed");
            VerifyFixedRuleSetIsNotPersisted(solutionRuleSet, projectRuleSet, fixedTarget);
        }
        public void RuleSetInspector_FixConflictingRules_NoConflicts()
        {
            // Arrange
            RuleSet solutionRuleSet = this.CreateCommonRuleSet();

            RuleSet projectRuleSet = this.CreateProjectRuleSetWithIncludes(0, solutionRuleSet.FilePath, IncludeType.AsRelativeToProject, RuleAction.Default);

            // Sanity
            AssertNoConflictsExpected(solutionRuleSet.FilePath, projectRuleSet.FilePath);

            // Act
            FixedRuleSetInfo fixedInfo = this.testSubject.FixConflictingRules(solutionRuleSet.FilePath, projectRuleSet.FilePath);

            // Assert
            RuleSet target = fixedInfo.FixedRuleSet;

            RuleSetAssert.AreEqual(projectRuleSet, target);
            VerifyFix(fixedInfo, expectedIncludesReset: 0, expectedRulesDeleted: 0);
        }
 private static void VerifyFix(FixedRuleSetInfo fixedInfo, int expectedIncludesReset, int expectedRulesDeleted)
 {
     fixedInfo.IncludesReset.Count().Should().Be(expectedIncludesReset, "Unexpected number if includes were reset");
     fixedInfo.RulesDeleted.Count().Should().Be(expectedRulesDeleted, "Unexpected number of rules were deleted");
 }
Exemple #6
0
 private static void VerifyFix(FixedRuleSetInfo fixedInfo, int expectedIncludesReset, int expectedRulesDeleted)
 {
     Assert.AreEqual(expectedIncludesReset, fixedInfo.IncludesReset.Count(), "Unexpected number if includes were reset");
     Assert.AreEqual(expectedRulesDeleted, fixedInfo.RulesDeleted.Count(), "Unexpected number of rules were deleted");
 }