public void RuleSetInspector_FindConflictingRules_ComplexStructureWithConflicts() { // Setup RuleSet solutionRuleSet = this.CreateCommonRuleSet(); // Modifies all the solution rules to Info (should not impact the result) RuleSet otherRuleSet = this.CreateUserSharedRuleSet("User.ruleset", RuleAction.Info); // Modifies all the solution rules to None (should not impact the result) const string BuiltInRuleSetName = "NoneAllRules.ruleset"; this.CreateVsRuleSet(DefaultNumberOfRules, BuiltInRuleSetName, RuleAction.None); // The project has 3 modification -> error, info and warning RuleSet projectRuleSet = this.CreateProjectRuleSetWithIncludes(DefaultNumberOfRules, solutionRuleSet.FilePath, IncludeType.AsIs, RuleAction.Error, otherRuleSet.FilePath, BuiltInRuleSetName); projectRuleSet.Rules[1].Action = RuleAction.Info; projectRuleSet.Rules[2].Action = RuleAction.None; projectRuleSet.WriteToFile(projectRuleSet.FilePath); // Act RuleConflictInfo conflicts = this.testSubject.FindConflictingRules(solutionRuleSet.FilePath, projectRuleSet.FilePath); // Verify [verify that having all that with all that extra noise, since the project level overrides two of the values there will be conflicts] AssertWeakRulesByFullIds(conflicts, new[] { projectRuleSet.Rules[1] }, solutionRuleSet); AssertMissingRulesByFullIds(conflicts, new[] { projectRuleSet.Rules[2] }); }
public void RuleSetInspector_FindConflictingRules_ProjectLevelOverridesOfTheSolutionRuleset() { // Arrange RuleSet solutionRuleSet = this.CreateCommonRuleSet(); // Check all supported RuleAction values foreach (RuleAction ruleAction in GetSupportedRuleActions()) { foreach (IncludeType includeType in Enum.GetValues(typeof(IncludeType)).OfType <IncludeType>()) { this.TestContext.WriteLine("Running test case, Project Rules are {0}, SolutionInclude is {1}", ruleAction, includeType); RuleSet projectRuleSet = this.CreateProjectRuleSetWithInclude(DefaultNumberOfRules, solutionRuleSet.FilePath, includeType, ruleAction); // Act RuleConflictInfo conflicts = this.testSubject.FindConflictingRules(solutionRuleSet.FilePath, projectRuleSet.FilePath); // Assert if (ruleAction == RuleAction.None) { AssertMissingRulesByFullIds(conflicts, solutionRuleSet.Rules); AssertNoWeakRules(conflicts); } else if (ruleAction == RuleAction.Info || ruleAction == RuleAction.Hidden) { AssertWeakRulesByFullIds(conflicts, projectRuleSet.Rules, solutionRuleSet); AssertNoMissingRules(conflicts); } else { AssertNoConflicts(conflicts); } } } }
public void RuleSetInspector_FindConflictingRules_ComplexStructureButNoConflicts() { // Make sure that the solution level has only one ruleset, and all the other rulesets have DefaultNumberOfRules (>1). // This is mainly to check the internal implementation of the RuleSetInjector and its RuleInfoProvider. // Setup string solutionRuleSet = this.CreateCommonRuleSet(rules: 1, defaultAction: RuleAction.Hidden).FilePath; // Modifies all the solution rules to Info (should not impact the result) RuleSet otherRuleSet = this.CreateUserSharedRuleSet("User.ruleset", RuleAction.Info); // Modifies all the solution rules to None (should not impact the result) const string BuiltInRuleSetName = "NoneAllRules.ruleset"; this.CreateVsRuleSet(DefaultNumberOfRules, BuiltInRuleSetName, RuleAction.None); // The project has 3 modification -> error, info and warning RuleSet projectRuleSet = this.CreateProjectRuleSetWithIncludes(DefaultNumberOfRules, solutionRuleSet, IncludeType.AsIs, RuleAction.Hidden, otherRuleSet.FilePath, BuiltInRuleSetName); projectRuleSet.Rules[0].Action = RuleAction.Info; projectRuleSet.Rules[1].Action = RuleAction.Error; projectRuleSet.Rules[2].Action = RuleAction.Warning; projectRuleSet.WriteToFile(projectRuleSet.FilePath); // Act RuleConflictInfo conflicts = this.testSubject.FindConflictingRules(solutionRuleSet, projectRuleSet.FilePath); // Verify AssertNoConflicts(conflicts); }
private static void AssertMissingRulesByFullIds(RuleConflictInfo info, IEnumerable <RuleReference> expectedRules) { string[] expectedFullRuleIds = expectedRules.Select(r => r.FullId).ToArray(); var actualFullIds = info.MissingRules.Select(r => r.FullId).ToArray(); CollectionAssert.AreEquivalent(expectedFullRuleIds, actualFullIds, "Actually missing: {0}", string.Join(", ", actualFullIds)); info.HasConflicts.Should().BeTrue("Expected missing rules"); }
public void ProjectRuleSetConflict_ArgChecks() { var info = new RuleSetInformation("projectFullName", "baselineRuleSet", "projectRuleSet", new string[0]); var conflict = new RuleConflictInfo(); Exceptions.Expect <ArgumentNullException>(() => new ProjectRuleSetConflict(null, info)); Exceptions.Expect <ArgumentNullException>(() => new ProjectRuleSetConflict(conflict, null)); new ProjectRuleSetConflict(conflict, info).Should().NotBeNull("Not expecting this to fail, just to make the static analyzer happy"); }
public void RuleSetInspector_FindConflictingRules_RuleSetFileCustomization_BaselineRuleSetWasRemoved() { // Arrange RuleSet solutionRuleSet = this.CreateCommonRuleSet(rules: 3); RuleSet otherRuleSet = this.CreateUserSharedRuleSet($"User.ruleset", rules: 2); RuleSet projectRuleSet = this.CreateProjectRuleSetWithIncludes(0, otherRuleSet.FilePath, IncludeType.AsIs); // Act RuleConflictInfo conflicts = this.testSubject.FindConflictingRules(solutionRuleSet.FilePath, projectRuleSet.FilePath); // Assert [deleting the baseline and not providing any replacements means that the delta rules are missing] AssertMissingRulesByFullIds(conflicts, new[] { solutionRuleSet.Rules.Last() }); AssertNoWeakRules(conflicts); }
public void RuleSetInspector_FindConflictingRules_RuleSetFileCustomization_OtherRuleSetWasIncludedAtLowerStrictnessThanWarning() { // Arrange RuleSet solutionRuleSet = this.CreateCommonRuleSet(); RuleSet otherRuleSet = this.CreateUserSharedRuleSet($"User.ruleset", RuleAction.Info); RuleSet projectRuleSet = this.CreateProjectRuleSetWithIncludes(0, solutionRuleSet.FilePath, IncludeType.AsIs, RuleAction.Default, otherRuleSet.FilePath); projectRuleSet.WriteToFile(projectRuleSet.FilePath); // Act RuleConflictInfo conflicts = this.testSubject.FindConflictingRules(solutionRuleSet.FilePath, projectRuleSet.FilePath); // Assert [since included with info the user rule set will remain info and once merged will become warning) AssertNoConflicts(conflicts); }
public void RuleSetInspector_FindConflictingRules_RuleSetFileCustomization_OtherRuleSetWasIncludedAtHigherStrictnessThanWarning() { // Setup RuleSet solutionRuleSet = this.CreateCommonRuleSet(); RuleSet otherRuleSet = this.CreateUserSharedRuleSet($"User.ruleset", RuleAction.Info); RuleSet projectRuleSet = this.CreateProjectRuleSetWithIncludes(0, solutionRuleSet.FilePath, IncludeType.AsIs, RuleAction.Default, otherRuleSet.FilePath); FindInclude(projectRuleSet, otherRuleSet.FilePath).Action = RuleAction.Error; projectRuleSet.WriteToFile(projectRuleSet.FilePath); // Act RuleConflictInfo conflicts = this.testSubject.FindConflictingRules(solutionRuleSet.FilePath, projectRuleSet.FilePath); // Verify [since included with Error the user rule set will become error and once merged will become error, not a conflict) AssertNoConflicts(conflicts); }
public void RuleSetInspector_FindConflictingRules_BaselineNoneRulesAreNotTreatedAsMissing() { // Arrange RuleSet solutionRuleSet = this.CreateCommonRuleSet(rules: 2); ChangeRuleActions(solutionRuleSet, RuleAction.None, RuleAction.None); solutionRuleSet.WriteToFile(solutionRuleSet.FilePath); RuleSet projectRuleSet = this.CreateProjectRuleSetWithIncludes(0, solutionRuleSet.FilePath, IncludeType.AsRelativeToProject, RuleAction.Default); projectRuleSet.WriteToFile(projectRuleSet.FilePath); // Act RuleConflictInfo conflicts = this.testSubject.FindConflictingRules(solutionRuleSet.FilePath, projectRuleSet.FilePath); // Assert AssertNoConflicts(conflicts); }
private static void AssertWeakRulesByFullIds(RuleConflictInfo info, IEnumerable <RuleReference> expectedRules, RuleSet baseline) { var expectedFullRuleIds = new HashSet <string>(expectedRules.Select(r => r.FullId)); List <string> found = new List <string>(); foreach (var keyValue in info.WeakerActionRules) { string ruleFullId = keyValue.Key.FullId; found.Add(ruleFullId); expectedFullRuleIds.Contains(ruleFullId).Should().BeTrue("Unexpected weakened rule"); RuleReference baselineRule; baseline.Rules.TryGetRule(ruleFullId, out baselineRule).Should().BeTrue("Test setup error: baseline doesn't contain the rule {0}", ruleFullId); keyValue.Value.Should().Be(baselineRule.Action, "Unexpected Action. Expecting the baseline rule action to be returned part of RuleConflictInfo"); } info.WeakerActionRules.Should().HaveSameCount(expectedFullRuleIds, "Not all the expected weakened rule were found. Missing: {0}", string.Join(", ", expectedFullRuleIds.Except(found))); info.HasConflicts.Should().BeTrue("Expected weakened rules"); }
public void RuleSetInspector_FindConflictingRules_RuleSetFileCustomization_BaselineRuleSetWasIncludedAsNone() { // Arrange RuleSet solutionRuleSet = this.CreateCommonRuleSet(); RuleSet otherRuleSet = this.CreateUserSharedRuleSet($"User.ruleset", RuleAction.Info); RuleSet projectRuleSet = this.CreateProjectRuleSetWithIncludes(0, solutionRuleSet.FilePath, IncludeType.AsIs, RuleAction.Default, otherRuleSet.FilePath); FindInclude(projectRuleSet, solutionRuleSet.FilePath).Action = RuleAction.None; projectRuleSet.WriteToFile(projectRuleSet.FilePath); // Act RuleConflictInfo conflicts = this.testSubject.FindConflictingRules(solutionRuleSet.FilePath, projectRuleSet.FilePath); // Assert [since baseline is None, the other rulesets actions are then ones being used i.e. Info instead of Warning] AssertWeakRulesByFullIds(conflicts, solutionRuleSet.Rules, solutionRuleSet); AssertNoMissingRules(conflicts); }
public void RuleSetInspector_FindConflictingRules_UserIncludesCannotCreateConflictsByDefault() { // Arrange string solutionRuleSet = this.CreateCommonRuleSet().FilePath; // Check all supported RuleAction values foreach (RuleAction includeAllAction in GetSupportedRuleActions()) { RuleSet otherRuleSet = this.CreateUserSharedRuleSet($"User{includeAllAction}.ruleset", includeAllAction); RuleSet projectRuleSet = this.CreateProjectRuleSetWithIncludes(0, solutionRuleSet, IncludeType.AsIs, RuleAction.Default, otherRuleSet.FilePath); // Act RuleConflictInfo conflicts = this.testSubject.FindConflictingRules(solutionRuleSet, projectRuleSet.FilePath); // Assert AssertNoConflicts(conflicts); } }
public void RuleSetInspector_FindConflictingRules_VsIncludesCannotCreateConflictsByDefault() { // Arrange string solutionRuleSet = this.CreateCommonRuleSet().FilePath; // Check all supported RuleAction values foreach (RuleAction includeAllAction in GetSupportedRuleActions()) { string vsRuleSetName = $"VsRuleSet{includeAllAction}.ruleset"; this.CreateVsRuleSet(DefaultNumberOfRules, vsRuleSetName, includeAllAction); RuleSet projectRuleSet = this.CreateProjectRuleSetWithIncludes(0, solutionRuleSet, IncludeType.AsRelativeToProject, RuleAction.Default, vsRuleSetName); // Act RuleConflictInfo conflicts = this.testSubject.FindConflictingRules(solutionRuleSet, projectRuleSet.FilePath); // Assert AssertNoConflicts(conflicts); } }
public void RuleSetInspector_FindConflictingRules_IncludeAllCannotCreateConflictsByDefault() { // Arrange RuleSet solutionRuleSet = this.CreateCommonRuleSet(); // Check all supported RuleAction values foreach (RuleAction includeAllAction in GetSupportedImportRuleActions()) { // Include with <IncludeAll ... /> RuleSet otherRuleSet = this.CreateUserSharedRuleSet($"User{includeAllAction}.ruleset", RuleAction.Info); otherRuleSet.IncludeAll = new IncludeAll(includeAllAction); // Target with <IncludeAll ... /> RuleSet projectRuleSet = this.CreateProjectRuleSetWithIncludes(0, solutionRuleSet.FilePath, IncludeType.AsRelativeToProject, RuleAction.Info); projectRuleSet.IncludeAll = new IncludeAll(includeAllAction); projectRuleSet.WriteToFile(projectRuleSet.FilePath); // Act RuleConflictInfo conflicts = this.testSubject.FindConflictingRules(solutionRuleSet.FilePath, projectRuleSet.FilePath); // Assert AssertNoConflicts(conflicts); } }
private static void AssertNoWeakRules(RuleConflictInfo info) { info.WeakerActionRules.Should().BeEmpty("Actually weak: {0}", string.Join(", ", info.WeakerActionRules.Keys.Select(r => r.FullId))); }
private static void AssertNoMissingRules(RuleConflictInfo info) { info.MissingRules.Should().BeEmpty("Actually missing: {0}", string.Join(", ", info.MissingRules.Select(r => r.FullId))); }
private static void AssertNoConflicts(RuleConflictInfo info) { AssertNoMissingRules(info); AssertNoWeakRules(info); info.HasConflicts.Should().BeFalse("Not expecting conflicts"); }
private static void AssertNoConflicts(RuleConflictInfo info) { AssertNoMissingRules(info); AssertNoWeakRules(info); Assert.IsFalse(info.HasConflicts, "Not expecting conflicts"); }
private static void AssertNoMissingRules(RuleConflictInfo info) { Assert.AreEqual(0, info.MissingRules.Count, "Actually missing: {0}", string.Join(", ", info.MissingRules.Select(r => r.FullId))); }
private static void AssertNoWeakRules(RuleConflictInfo info) { Assert.AreEqual(0, info.WeakerActionRules.Count, "Actually weak: {0}", string.Join(", ", info.WeakerActionRules.Keys.Select(r => r.FullId))); }