public void ProjectBindingOperation_TryUpdateExistingProjectRuleSet_ExistingRuleSetIsNotAtTheProjectLevel() { // Setup 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); // Verify string testCase = currentRuleSet ?? "NULL"; Assert.IsNull(pathOutResult, "Unexpected rule set path was returned: {0}. Case: {1}", pathOutResult, testCase); Assert.IsNull(rsOutput, "Unexpected rule set was returned. Case: {0}", testCase); Assert.IsFalse(result, "Not expecting to update a non project rooted rulesets. Case: {0}", testCase); } }
public void RuleSetConflictsController_FixConflictsCommandExecution() { // Setup var testSubject = new RuleSetConflictsController(this.host); this.ConfigureServiceProviderForFixConflictsCommandExecution(); this.host.VisualStateManager.IsBusy = false; this.host.VisualStateManager.SetBoundProject(new Integration.Service.ProjectInformation()); var section = ConfigurableSectionController.CreateDefault(); this.host.SetActiveSection(section); ConfigurableUserNotification notifications = (ConfigurableUserNotification)section.UserNotifications; ProjectRuleSetConflict[] conflicts = new[] { ConfigurableConflictsManager.CreateConflict() }; RuleSet fixedRuleSet = TestRuleSetHelper.CreateTestRuleSet(3); fixedRuleSet.FilePath = "MyFixedRules.ruleset"; RuleSetInspectorTestDataProvider inspectorData = new RuleSetInspectorTestDataProvider(); var weakenedRulesMap = new Dictionary<RuleReference, RuleAction>(); inspectorData.FindConflictsResult = new RuleConflictInfo(new RuleReference[0], weakenedRulesMap); inspectorData.FixConflictsResult = new FixedRuleSetInfo(fixedRuleSet, new[] { "reset.ruleset" }, new[] { "deletedRuleId1" }); this.ruleSetInspector.FindConflictingRulesAction = inspectorData.FindConflictingRulesAction; this.ruleSetInspector.FixConflictingRulesAction = inspectorData.FixConflictingRulesAction; ICommand fixMeCommand = testSubject.CreateFixConflictsCommand(conflicts); section.UserNotifications.ShowNotificationWarning("fix me", NotificationIds.RuleSetConflictsId, fixMeCommand); // Act fixMeCommand.Execute(null); // Verify this.sccFS.AssertFileExists(fixedRuleSet.FilePath); this.rsSerializer.AssertRuleSetsAreSame(fixedRuleSet.FilePath, fixedRuleSet); this.outputWindowPane.AssertOutputStrings(1); this.outputWindowPane.AssertMessageContainsAllWordsCaseSensitive(0, words: new[] { fixedRuleSet.FilePath, "deletedRuleId1", "reset.ruleset" }, splitter:new[] {'\n', '\r', '\t', '\'', ':' }); notifications.AssertNoNotification(NotificationIds.RuleSetConflictsId); }
private static IEnumerable<RuleAction> GetSupportedImportRuleActions() { RuleAction[] unsupportedActions = new[] { RuleAction.None, RuleAction.Default }; return Enum.GetValues(typeof(RuleAction)).OfType<RuleAction>().Except(unsupportedActions); }
public void RuleSetConflictsController_FixConflictsCommandStatus() { // Setup var testSubject = new RuleSetConflictsController(this.host); // Case 1: Nulls Assert.IsFalse(testSubject.FixConflictsCommand.CanExecute(null)); // Case 2: Empty collections Assert.IsFalse(testSubject.FixConflictsCommand.CanExecute(new ProjectRuleSetConflict[0])); // Valid input ProjectRuleSetConflict[] conflicts = new[] { ConfigurableConflictsManager.CreateConflict() }; // Case 3: Valid input, busy, has bound project this.host.VisualStateManager.IsBusy = true; this.host.VisualStateManager.SetBoundProject(new Integration.Service.ProjectInformation()); Assert.IsFalse(testSubject.FixConflictsCommand.CanExecute(conflicts)); // Case 4: Valid input, not busy, not bound project this.host.VisualStateManager.IsBusy = false; this.host.VisualStateManager.ClearBoundProject(); Assert.IsFalse(testSubject.FixConflictsCommand.CanExecute(conflicts)); // Case 5: Valid input, not busy, has bound project this.host.VisualStateManager.IsBusy = false; this.host.VisualStateManager.SetBoundProject(new Integration.Service.ProjectInformation()); Assert.IsTrue(testSubject.FixConflictsCommand.CanExecute(conflicts)); }
private RuleSet CreateProjectRuleSetWithIncludes(int rules, string solutionRuleSetToInclude, IncludeType solutionIncludeType, RuleAction defaultAction = RuleAction.Warning, params string[] otherIncludes) { string projectRuleSetFilePath = Path.Combine(this.ProjectRuleSetFolder, Guid.NewGuid() + ".ruleset"); string solutionInclude = solutionIncludeType == IncludeType.AsIs ? solutionRuleSetToInclude : PathHelper.CalculateRelativePath(projectRuleSetFilePath, solutionRuleSetToInclude); string[] includes = new[] { solutionInclude }; if ((otherIncludes?.Length ?? 0) > 0) { includes = includes.Concat(otherIncludes).ToArray(); } RuleSet ruleSet = TestRuleSetHelper.CreateTestRuleSet(rules, includes); ruleSet.Rules.ToList().ForEach(r => r.Action = defaultAction); ruleSet.FilePath = projectRuleSetFilePath; ruleSet.WriteToFile(ruleSet.FilePath); this.temporaryFiles.AddFile(ruleSet.FilePath, false); return ruleSet; }