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); }
internal /*for testing purposes*/ bool TryUpdateExistingProjectRuleSet(string solutionRuleSetPath, string projectRuleSetRootFolder, string currentRuleSet, out string existingRuleSetPath, out RuleSet existingRuleSet) { existingRuleSet = null; existingRuleSetPath = PathHelper.ResolveRelativePath(currentRuleSet, projectRuleSetRootFolder); if (!PathHelper.IsPathRootedUnderRoot(existingRuleSetPath, projectRuleSetRootFolder)) { // Not our file (i.e. absolute path to some other ruleset) existingRuleSetPath = null; return(false); } if (this.AlreadyUpdatedExistingRuleSetPaths.TryGetValue(existingRuleSetPath, out existingRuleSet)) { return(true); } existingRuleSet = this.ruleSetSerializer.LoadRuleSet(existingRuleSetPath); if (existingRuleSet == null) { existingRuleSetPath = null; return(false); } RuleSetUpdater.UpdateExistingProjectRuleSet(existingRuleSet, solutionRuleSetPath); this.AlreadyUpdatedExistingRuleSetPaths.Add(existingRuleSetPath, existingRuleSet); return(true); }
/// <summary> /// Attempts to fix the conflicts by ensuring that the server ruleset is included with the expected Include Action /// </summary> /// <returns>Whether all conflicts were resolved</returns> private bool TryResolveIncludeConflicts(RuleSet baselineRuleSet, RuleSet targetRuleSet) { Debug.Assert(baselineRuleSet != null); Debug.Assert(targetRuleSet != null); Debug.Assert(!string.IsNullOrWhiteSpace(baselineRuleSet.FilePath)); Debug.Assert(!string.IsNullOrWhiteSpace(targetRuleSet.FilePath)); RuleSetUpdater.UpdateExistingProjectRuleSet(targetRuleSet, baselineRuleSet.FilePath); RuleConflictInfo conflicts1stAttempt = this.FindConflictsCore(baselineRuleSet, targetRuleSet); return(!conflicts1stAttempt.HasConflicts); }
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 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"); }