public void RuleSetConflictsController_FixConflictsCommandStatus() { // Arrange var testSubject = new RuleSetConflictsController(this.host, this.conflictsManager); // Case 1: Nulls testSubject.FixConflictsCommand.CanExecute(null).Should().BeFalse(); // Case 2: Empty collections testSubject.FixConflictsCommand.CanExecute(new ProjectRuleSetConflict[0]).Should().BeFalse(); // 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 Uri("http://foo"), null, "project123"); testSubject.FixConflictsCommand.CanExecute(conflicts).Should().BeFalse(); // Case 4: Valid input, not busy, not bound project this.host.VisualStateManager.IsBusy = false; this.host.VisualStateManager.ClearBoundProject(); testSubject.FixConflictsCommand.CanExecute(conflicts).Should().BeFalse(); // Case 5: Valid input, not busy, has bound project this.host.VisualStateManager.IsBusy = false; this.host.VisualStateManager.SetBoundProject(new Uri("http://foo"), null, "project123"); testSubject.FixConflictsCommand.CanExecute(conflicts).Should().BeTrue(); }
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)); }
public void TestInit() { this.serviceProvider = new ConfigurableServiceProvider(); var outputWindow = new ConfigurableVsOutputWindow(); this.outputWindowPane = outputWindow.GetOrCreateSonarLintPane(); this.serviceProvider.RegisterService(typeof(SVsOutputWindow), outputWindow); this.host = new ConfigurableHost(this.serviceProvider, Dispatcher.CurrentDispatcher); this.ruleSetInspector = null; this.sccFS = null; this.rsSerializer = null; this.conflictsManager = new ConfigurableConflictsManager(); IComponentModel componentModel = ConfigurableComponentModel.CreateWithExports( new Export[] { MefTestHelpers.CreateExport <ITelemetryLogger>(new ConfigurableTelemetryLogger()) }); this.serviceProvider.RegisterService(typeof(SComponentModel), componentModel); fileSystem = new MockFileSystem(); }
private static void VerifyInputForDefaultConflictInstance(string baseline, string project, string[] directories) { var expectedConflict = ConfigurableConflictsManager.CreateConflict(); baseline.Should().Be(expectedConflict.RuleSetInfo.BaselineFilePath, "baseline argument is not as expected"); project.Should().Be(expectedConflict.RuleSetInfo.RuleSetFilePath, "project argument is not as expected"); CollectionAssert.AreEqual(expectedConflict.RuleSetInfo.RuleSetDirectories, directories, "directories argument is not as expected"); }
public void TestInit() { this.serviceProvider = new ConfigurableServiceProvider(); var outputWindow = new ConfigurableVsOutputWindow(); this.outputWindowPane = outputWindow.GetOrCreateSonarLintPane(); this.serviceProvider.RegisterService(typeof(SVsOutputWindow), outputWindow); this.host = new ConfigurableHost(this.serviceProvider, Dispatcher.CurrentDispatcher); this.ruleSetInspector = null; this.sccFS = null; this.rsSerializer = null; this.conflictsManager = new ConfigurableConflictsManager(); fileSystem = new MockFileSystem(); }
public void TestInit() { this.serviceProvider = new ConfigurableServiceProvider(); var outputWindow = new ConfigurableVsOutputWindow(); this.outputWindowPane = outputWindow.GetOrCreateSonarLintPane(); this.serviceProvider.RegisterService(typeof(SVsOutputWindow), outputWindow); this.host = new ConfigurableHost(this.serviceProvider, Dispatcher.CurrentDispatcher); this.ruleSetInspector = null; this.sccFS = null; this.rsSerializer = null; this.conflictsManager = new ConfigurableConflictsManager(); // Instead of ignored unexpected service, register one (for telemetry) this.serviceProvider.RegisterService(typeof(SComponentModel), new ConfigurableComponentModel()); }
public void RuleSetConflictsController_FixConflictsCommandExecution() { // Arrange var testSubject = new RuleSetConflictsController(this.host, this.conflictsManager); this.ConfigureServiceProviderForFixConflictsCommandExecution(); this.host.VisualStateManager.IsBusy = false; this.host.VisualStateManager.SetBoundProject(new Uri("http://foo"), null, "project123"); 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); // Assert this.sccFS.files.Should().ContainKey(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); }
public void RuleSetConflictsController_CheckForConflicts() { // Setup var conflictsMananger = new ConfigurableConflictsManager(); this.serviceProvider.RegisterService(typeof(IConflictsManager), conflictsMananger); var testSubject = new RuleSetConflictsController(this.host); bool result; // Case 1: No conflicts // Act result = testSubject.CheckForConflicts(); // Verify Assert.IsFalse(result, "Not expecting any conflicts"); this.outputWindowPane.AssertOutputStrings(0); // Case 2: Has conflicts, no active section ProjectRuleSetConflict conflict = conflictsMananger.AddConflict(); // Act result = testSubject.CheckForConflicts(); // Verify Assert.IsTrue(result, "Conflicts expected"); this.outputWindowPane.AssertOutputStrings(1); this.outputWindowPane.AssertMessageContainsAllWordsCaseSensitive(0, new[] { conflict.Conflict.MissingRules.Single().FullId }); // Case 3: Has conflicts, has active section var section = ConfigurableSectionController.CreateDefault(); this.host.SetActiveSection(section); // Act result = testSubject.CheckForConflicts(); // Verify Assert.IsTrue(result, "Conflicts expected"); ((ConfigurableUserNotification)section.UserNotifications).AssertNotification(NotificationIds.RuleSetConflictsId); this.outputWindowPane.AssertOutputStrings(2); this.outputWindowPane.AssertMessageContainsAllWordsCaseSensitive(1, new[] { conflict.Conflict.MissingRules.Single().FullId }); }
public void RuleSetConflictsController_CheckForConflicts() { // Setup var conflictsMananger = new ConfigurableConflictsManager(); this.serviceProvider.RegisterService(typeof(IConflictsManager), conflictsMananger); var testSubject = new RuleSetConflictsController(this.host); bool result; // Case 1: No conflicts // Act result = testSubject.CheckForConflicts(); // Verify Assert.IsFalse(result, "Not expecting any conflicts"); this.outputWindowPane.AssertOutputStrings(0); // Case 2: Has conflicts, no active section ProjectRuleSetConflict conflict = conflictsMananger.AddConflict(); // Act result = testSubject.CheckForConflicts(); // Verify Assert.IsTrue(result, "Conflicts expected"); this.outputWindowPane.AssertOutputStrings(1); this.outputWindowPane.AssertMessageContainsAllWordsCaseSensitive(0, new[] { conflict.Conflict.MissingRules.Single().FullId }); // Case 3: Has conflicts, has active section var section = ConfigurableSectionController.CreateDefault(); this.host.SetActiveSection(section); // Act result = testSubject.CheckForConflicts(); // Verify Assert.IsTrue(result, "Conflicts expected"); ((ConfigurableUserNotification)section.UserNotifications).AssertNotification(NotificationIds.RuleSetConflictsId); this.outputWindowPane.AssertOutputStrings(2); this.outputWindowPane.AssertMessageContainsAllWordsCaseSensitive(1, new[] { conflict.Conflict.MissingRules.Single().FullId }); }