public void ProjectBindingOperation_TryUpdateExistingProjectRuleSet_ExistingRuleSetIsNotAtTheProjectLevel() { // Arrange ProjectBindingOperation testSubject = this.CreateTestSubject(); string solutionRuleSetPath = @"X:\SolutionDir\Sonar\Sonar1.ruleset"; string projectRuleSetRoot = @"X:\SolutionDir\Project\"; string[] cases = new[] { "../relativeSolutionLevel.ruleset", @"..\..\relativeSolutionLevel.ruleset", @"X:\SolutionDir\Sonar\absolutionSolutionRooted.ruleset", @"c:\OtherPlaceEntirey\rules.ruleset", ProjectBindingOperation.DefaultProjectRuleSet, null, string.Empty }; foreach (var currentRuleSet in cases) { // Act string pathOutResult; RuleSet rsOutput; bool result = testSubject.TryUpdateExistingProjectRuleSet(solutionRuleSetPath, projectRuleSetRoot, currentRuleSet, out pathOutResult, out rsOutput); // Assert string testCase = currentRuleSet ?? "NULL"; pathOutResult.Should().BeNull("Unexpected rule set path was returned: {0}. Case: {1}", pathOutResult, testCase); rsOutput.Should().BeNull("Unexpected rule set was returned. Case: {0}", testCase); result.Should().BeFalse("Not expecting to update a non project rooted rulesets. Case: {0}", testCase); } }
public void ProjectBindingOperation_TryUpdateExistingProjectRuleSet_RuleSetNotAlreadyWritten_WritesFile() { // Setup ProjectBindingOperation testSubject = this.CreateTestSubject(); string solutionRuleSetPath = @"X:\SolutionDir\Sonar\Sonar1.ruleset"; string projectRuleSetRoot = @"X:\SolutionDir\Project\"; string existingRuleSetFullPath = @"X:\SolutionDir\Project\ExistingSharedRuleSet.ruleset"; string existingRuleSetPropValue = PathHelper.CalculateRelativePath(projectRuleSetRoot, existingRuleSetFullPath); var existingRuleSet = TestRuleSetHelper.CreateTestRuleSet(existingRuleSetFullPath); this.ruleSetFS.RegisterRuleSet(existingRuleSet, existingRuleSetFullPath); long beforeTimestamp = this.sccFileSystem.GetFileTimestamp(existingRuleSetFullPath); // Act string pathOutResult; RuleSet rsOutput; bool result = testSubject.TryUpdateExistingProjectRuleSet(solutionRuleSetPath, projectRuleSetRoot, existingRuleSetPropValue, out pathOutResult, out rsOutput); // Verify Assert.IsTrue(result, "Expected to return true when trying to update existing rule set"); Assert.AreSame(existingRuleSet, rsOutput, "Same RuleSet instance expected"); Assert.AreEqual(existingRuleSetFullPath, pathOutResult, "Unexpected rule set path was returned"); this.sccFileSystem.AssertFileTimestamp(existingRuleSetFullPath, beforeTimestamp); }
public void ProjectBindingOperation_TryUpdateExistingProjectRuleSet_RuleSetAlreadyWritten_DoesNotWriteAgain() { // Arrange ProjectBindingOperation testSubject = this.CreateTestSubject(); string solutionRuleSetPath = @"X:\SolutionDir\Sonar\Sonar1.ruleset"; string projectRuleSetRoot = @"X:\SolutionDir\Project\"; string existingRuleSetFullPath = @"X:\SolutionDir\Project\ExistingSharedRuleSet.ruleset"; string existingRuleSetPropValue = PathHelper.CalculateRelativePath(projectRuleSetRoot, existingRuleSetFullPath); var existingRuleSet = new RuleSet("test") { FilePath = existingRuleSetFullPath }; testSubject.AlreadyUpdatedExistingRuleSetPaths.Add(existingRuleSet.FilePath, existingRuleSet); this.ruleSetFS.RegisterRuleSet(existingRuleSet); long beforeTimestamp = this.sccFileSystem.GetFileTimestamp(existingRuleSetFullPath); // Act string pathOutResult; RuleSet rsOutput; bool result = testSubject.TryUpdateExistingProjectRuleSet(solutionRuleSetPath, projectRuleSetRoot, existingRuleSetPropValue, out pathOutResult, out rsOutput); // Assert result.Should().BeTrue("Expected to return true when trying to update already updated existing rule set"); rsOutput.Should().Be(existingRuleSet, "Same RuleSet instance is expected"); pathOutResult.Should().Be(existingRuleSetFullPath, "Unexpected rule set path was returned"); this.sccFileSystem.AssertFileTimestamp(existingRuleSetFullPath, beforeTimestamp); }
public void ProjectBindingOperation_TryUpdateExistingProjectRuleSet_RuleSetSaved(bool doesAlreadyExist) { // Arrange ProjectBindingOperation testSubject = CreateTestSubject(); string solutionRuleSetPath = @"X:\SolutionDir\Sonar\Sonar1.ruleset"; string projectRuleSetRoot = @"X:\SolutionDir\Project\"; string existingRuleSetFullPath = @"X:\SolutionDir\Project\ExistingSharedRuleSet.ruleset"; string existingRuleSetPropValue = PathHelper.CalculateRelativePath(projectRuleSetRoot, existingRuleSetFullPath); var existingRuleSet = TestRuleSetHelper.CreateTestRuleSet(existingRuleSetFullPath); if (doesAlreadyExist) { testSubject.AlreadyUpdatedExistingRuleSetPaths.Add(existingRuleSet.FilePath, existingRuleSet); } this.ruleSetFS.RegisterRuleSet(existingRuleSet); // Act string pathOutResult; RuleSet rsOutput; bool result = testSubject.TryUpdateExistingProjectRuleSet(solutionRuleSetPath, projectRuleSetRoot, existingRuleSetPropValue, out pathOutResult, out rsOutput); // Assert result.Should().BeTrue("Expected to return true when trying to update existing rule set"); rsOutput.Should().Be(existingRuleSet, "Same RuleSet instance is expected"); pathOutResult.Should().Be(existingRuleSetFullPath, "Unexpected rule set path was returned"); }