public void UpdateConnection_Disconnect_WpfCommandIsAvailableButNotExecutable_ServiceDisconnectedIsCalled() { // If the WPF command is available then it should be used to disconnect, // rather than calling service.Disconnect() directly. // Here, the command exists but is not executable. // Arrange var testSubject = new ActiveSolutionBoundTracker(this.host, this.activeSolutionTracker, loggerMock.Object); int commandCallCount = 0; int commandCanExecuteCallCount = 0; var teSection = ConfigurableSectionController.CreateDefault(); teSection.DisconnectCommand = new Integration.WPF.RelayCommand( () => commandCallCount++, () => { commandCanExecuteCallCount++; return(false); }); host.SetActiveSection(teSection); ConfigureService(isConnected: true); ConfigureSolutionBinding(null); // Act activeSolutionTracker.SimulateActiveSolutionChanged(isSolutionOpen: false); // Assert VerifyServiceConnect(Times.Never()); VerifyServiceDisconnect(Times.Once()); commandCanExecuteCallCount.Should().Be(1); commandCallCount.Should().Be(0); }
public void ErrorListInfoBarController_InfoBar_ClickButton_NoLongerInLegacyConnected_NoOp() { // Arrange this.SetBindingMode(SonarLintMode.LegacyConnected); var testSubject = new ErrorListInfoBarController(this.host, this.solutionBindingInformationProvider); this.ConfigureLoadedSolution(); this.host.SetActiveSection(ConfigurableSectionController.CreateDefault()); testSubject.Refresh(); RunAsyncAction(); this.outputWindowPane.Reset(); // Sanity ConfigurableInfoBar infoBar = this.infoBarManager.AssertHasAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid); VerifyInfoBar(infoBar); // Change binding // Note: in practice we can't switch from legacy to new connected mode, but the important // thing for this test is that the solution isn't in legacy mode this.SetBindingMode(SonarLintMode.Connected); // Act infoBar.SimulateButtonClickEvent(); // Assert this.teamExplorerController.ShowConnectionsPageCallsCount.Should().Be(0); this.infoBarManager.AssertHasNoAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid); this.outputWindowPane.AssertOutputStrings(1); }
public void ErrorListInfoBarController_InfoBar_ClickButton_SolutionBindingAreDifferentThatTheOnesUsedForTheInfoBar_NoOp() { // Arrange this.SetBindingMode(SonarLintMode.LegacyConnected); var testSubject = new ErrorListInfoBarController(this.host, this.unboundProjectFinder); this.ConfigureLoadedSolution(); this.host.SetActiveSection(ConfigurableSectionController.CreateDefault()); testSubject.Refresh(); RunAsyncAction(); this.outputWindowPane.Reset(); // Sanity ConfigurableInfoBar infoBar = this.infoBarManager.AssertHasAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid); VerifyInfoBar(infoBar); // Change binding this.configProvider.ProjectToReturn = new BoundSonarQubeProject(new Uri("http://server"), "SomeOtherProjectKey", "projectName"); // Act infoBar.SimulateButtonClickEvent(); // Assert this.teamExplorerController.ShowConnectionsPageCallsCount.Should().Be(0); this.infoBarManager.AssertHasNoAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid); this.outputWindowPane.AssertOutputStrings(1); }
public void ErrorListInfoBarController_Dispose() { // Setup this.IsActiveSolutionBound = true; var testSubject = new ErrorListInfoBarController(this.host); this.ConfigureLoadedSolution(); ConfigurableSectionController section = this.ConfigureActiveSectionWithBindCommand(vm => { }); this.ConfigureProjectViewModel(section); testSubject.Refresh(); RunAsyncAction(); this.outputWindowPane.Reset(); // Sanity ConfigurableInfoBar infoBar = this.infoBarManager.AssertHasAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid); VerifyInfoBar(infoBar); // Act testSubject.Dispose(); // Verify this.infoBarManager.AssertHasNoAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid); infoBar.VerifyAllEventsUnregistered(); this.outputWindowPane.AssertOutputStrings(0); this.teamExplorerController.AssertExpectedNumCallsShowConnectionsPage(0); }
public void ErrorListInfoBarController_InfoBar_ClickButton_SolutionBindingAreDifferentThatTheOnesUsedForTheInfoBar() { // Arrange this.IsActiveSolutionBound = true; var testSubject = new ErrorListInfoBarController(this.host); this.ConfigureLoadedSolution(); this.host.SetActiveSection(ConfigurableSectionController.CreateDefault()); testSubject.Refresh(); RunAsyncAction(); this.outputWindowPane.Reset(); // Sanity ConfigurableInfoBar infoBar = this.infoBarManager.AssertHasAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid); VerifyInfoBar(infoBar); // Change binding this.solutionBindingSerializer.CurrentBinding = new Persistence.BoundSonarQubeProject(new Uri("http://server"), "SomeOtherProjectKey"); // Act infoBar.SimulateButtonClickEvent(); // Assert this.teamExplorerController.ShowConnectionsPageCallsCount.Should().Be(0); this.infoBarManager.AssertHasNoAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid); this.outputWindowPane.AssertOutputStrings(1); }
public void UpdateConnection_Disconnect_WpfCommandIsAvailableAndExecutable_ServiceDisconnectedIsNotCalled() { // Wpf command is available and can be executed -> should be called instead of service.Disconnect() // Arrange var testSubject = new ActiveSolutionBoundTracker(this.host, this.activeSolutionTracker, loggerMock.Object); int commandCallCount = 0; int commandCanExecuteCallCount = 0; var teSection = ConfigurableSectionController.CreateDefault(); teSection.DisconnectCommand = new Integration.WPF.RelayCommand( () => { commandCallCount++; isMockServiceConnected = false; }, () => { commandCanExecuteCallCount++; return(true); }); host.SetActiveSection(teSection); ConfigureService(isConnected: true); ConfigureSolutionBinding(null); // Act activeSolutionTracker.SimulateActiveSolutionChanged(isSolutionOpen: false); // Assert VerifyServiceConnect(Times.Never()); VerifyServiceDisconnect(Times.Never()); commandCanExecuteCallCount.Should().Be(1); commandCallCount.Should().Be(1); }
public void ErrorListInfoBarController_Dispose() { // Arrange this.SetBindingMode(SonarLintMode.LegacyConnected); var testSubject = new ErrorListInfoBarController(this.host, this.unboundProjectFinder); this.ConfigureLoadedSolution(); ConfigurableSectionController section = this.ConfigureActiveSectionWithBindCommand(args => { }); this.ConfigureProjectViewModel(section); testSubject.Refresh(); RunAsyncAction(); this.outputWindowPane.Reset(); // Sanity ConfigurableInfoBar infoBar = this.infoBarManager.AssertHasAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid); VerifyInfoBar(infoBar); // Act testSubject.Dispose(); // Assert this.infoBarManager.AssertHasNoAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid); infoBar.VerifyAllEventsUnregistered(); this.outputWindowPane.AssertOutputStrings(0); this.teamExplorerController.ShowConnectionsPageCallsCount.Should().Be(0); }
public void ErrorListInfoBarController_InfoBar_ClickButton_NoLongerInConnected_NoOp() { // Arrange this.SetBindingMode(SonarLintMode.LegacyConnected); var testSubject = new ErrorListInfoBarController(this.host, this.unboundProjectFinder); this.ConfigureLoadedSolution(); this.host.SetActiveSection(ConfigurableSectionController.CreateDefault()); testSubject.Refresh(); RunAsyncAction(); this.outputWindowPane.Reset(); // Sanity ConfigurableInfoBar infoBar = this.infoBarManager.AssertHasAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid); VerifyInfoBar(infoBar); // Change binding this.SetBindingMode(SonarLintMode.Standalone); // Act infoBar.SimulateButtonClickEvent(); // Assert this.teamExplorerController.ShowConnectionsPageCallsCount.Should().Be(0); this.infoBarManager.AssertHasNoAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid); this.outputWindowPane.AssertOutputStrings(1); }
public void ErrorListInfoBarController_InfoBar_ClickButton_ConnectedToADifferentServer() { // Setup this.IsActiveSolutionBound = true; var testSubject = new ErrorListInfoBarController(this.host); this.ConfigureLoadedSolution(); int refreshCalled = 0; ConfigurableSectionController section = this.ConfigureActiveSectionWithRefreshCommand(c => { Assert.AreEqual(this.solutionBindingSerializer.CurrentBinding.ServerUri, c.ServerUri); refreshCalled++; }); int disconnectCalled = 0; this.ConfigureActiveSectionWithDisconnectCommand(() => { disconnectCalled++; }); int bindCalled = 0; this.ConfigureActiveSectionWithBindCommand(vm => { Assert.AreEqual(this.solutionBindingSerializer.CurrentBinding.ProjectKey, vm.Key); bindCalled++; }); this.ConfigureProjectViewModel(section); testSubject.Refresh(); RunAsyncAction(); // Sanity ConfigurableInfoBar infoBar = this.infoBarManager.AssertHasAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid); VerifyInfoBar(infoBar); this.teamExplorerController.AssertExpectedNumCallsShowConnectionsPage(0); // Connect to a different server this.ConfigureProjectViewModel(section, new Uri("http://SomeOtherServer"), "someOtherProjectKey"); // Act infoBar.SimulateButtonClickEvent(); // Verify Assert.AreEqual(1, disconnectCalled, "Should have been disconnected"); Assert.AreEqual(1, refreshCalled, "Also expected to connect to the right server"); Assert.AreEqual(0, bindCalled, "Busy, should not be executed"); // Simulate that connected to the project that is bound to this.ConfigureProjectViewModel(section); // Act this.stateManager.SetAndInvokeBusyChanged(false); // Verify Assert.AreEqual(1, bindCalled, "Should be bound"); this.infoBarManager.AssertHasNoAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid); infoBar.VerifyAllEventsUnregistered(); }
public void ErrorListInfoBarController_InfoBar_ClickButton_ConnectedToADifferentServer() { // Arrange this.SetBindingMode(SonarLintMode.LegacyConnected); var testSubject = new ErrorListInfoBarController(this.host, this.unboundProjectFinder); this.ConfigureLoadedSolution(); int refreshCalled = 0; ConfigurableSectionController section = this.ConfigureActiveSectionWithRefreshCommand(c => { c.ServerUri.Should().Be(this.configProvider.ProjectToReturn.ServerUri); refreshCalled++; }); int disconnectCalled = 0; this.ConfigureActiveSectionWithDisconnectCommand(() => { disconnectCalled++; }); int bindCalled = 0; this.ConfigureActiveSectionWithBindCommand(args => { args.ProjectKey.Should().Be(this.configProvider.ProjectToReturn.ProjectKey); bindCalled++; }); this.ConfigureProjectViewModel(section); testSubject.Refresh(); RunAsyncAction(); // Sanity ConfigurableInfoBar infoBar = this.infoBarManager.AssertHasAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid); VerifyInfoBar(infoBar); this.teamExplorerController.ShowConnectionsPageCallsCount.Should().Be(0); // Connect to a different server this.ConfigureProjectViewModel(section, new Uri("http://SomeOtherServer"), "someOtherProjectKey"); // Act infoBar.SimulateButtonClickEvent(); // Assert disconnectCalled.Should().Be(1, "Should have been disconnected"); refreshCalled.Should().Be(1, "Also expected to connect to the right server"); bindCalled.Should().Be(0, "Busy, should not be executed"); // Simulate that connected to the project that is bound to this.ConfigureProjectViewModel(section); // Act this.stateManager.SetAndInvokeBusyChanged(false); // Assert bindCalled.Should().Be(1, "Should be bound"); this.infoBarManager.AssertHasNoAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid); infoBar.VerifyAllEventsUnregistered(); }
private ProjectViewModel ConfigureProjectViewModel(ConfigurableSectionController section) { var vm = this.ConfigureProjectViewModel(section, this.configProvider.ProjectToReturn?.ServerUri, this.configProvider.ProjectToReturn?.ProjectKey); if (this.configProvider.ProjectToReturn != null) { vm.IsBound = true; } return(vm); }
private ProjectViewModel ConfigureProjectViewModel(ConfigurableSectionController section) { var vm = this.ConfigureProjectViewModel(section, this.solutionBindingSerializer.CurrentBinding?.ServerUri, this.solutionBindingSerializer.CurrentBinding?.ProjectKey); if (this.solutionBindingSerializer.CurrentBinding != null) { vm.IsBound = true; } return(vm); }
public void ErrorListInfoBarController_InfoBar_ClickButton_HasDisconnectedActiveSection() { // Arrange var testSubject = new ErrorListInfoBarController(this.host, this.unboundProjectFinder); this.ConfigureLoadedSolution(); int bindingCalled = 0; ConfigurableSectionController section = this.ConfigureActiveSectionWithBindCommand(args => { bindingCalled++; args.ProjectKey.Should().Be(this.configProvider.ProjectToReturn.ProjectKey); }); int refreshCalled = 0; this.ConfigureActiveSectionWithRefreshCommand(connection => { refreshCalled++; connection.ServerUri.Should().Be(this.configProvider.ProjectToReturn.ServerUri); }); int disconnectCalled = 0; this.ConfigureActiveSectionWithDisconnectCommand(() => { disconnectCalled++; }); this.SetBindingMode(SonarLintMode.LegacyConnected); testSubject.Refresh(); RunAsyncAction(); this.outputWindowPane.Reset(); // Sanity ConfigurableInfoBar infoBar = this.infoBarManager.AssertHasAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid); VerifyInfoBar(infoBar); // Act (kick off connection) infoBar.SimulateButtonClickEvent(); // Assert refreshCalled.Should().Be(1, "Expected to connect once"); disconnectCalled.Should().Be(0, "Not expected to disconnect"); bindingCalled.Should().Be(0, "Not expected to bind yet"); // Act (connected) this.ConfigureProjectViewModel(section); this.stateManager.SetAndInvokeBusyChanged(false); // Assert refreshCalled.Should().Be(1, "Expected to connect once"); bindingCalled.Should().Be(1, "Expected to bind once"); disconnectCalled.Should().Be(0, "Not expected to disconnect"); this.infoBarManager.AssertHasNoAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid); infoBar.VerifyAllEventsUnregistered(); this.outputWindowPane.AssertOutputStrings(0); }
public void ErrorListInfoBarController_InfoBar_ClickButton_HasDisconnectedActiveSection() { // Setup var testSubject = new ErrorListInfoBarController(this.host); this.ConfigureLoadedSolution(); int bindingCalled = 0; ConfigurableSectionController section = this.ConfigureActiveSectionWithBindCommand(vm => { bindingCalled++; Assert.AreEqual(this.solutionBindingSerializer.CurrentBinding.ProjectKey, vm.Key); }); int refreshCalled = 0; this.ConfigureActiveSectionWithRefreshCommand(connection => { refreshCalled++; Assert.AreEqual(this.solutionBindingSerializer.CurrentBinding.ServerUri, connection.ServerUri); }); int disconnectCalled = 0; this.ConfigureActiveSectionWithDisconnectCommand(() => { disconnectCalled++; }); this.IsActiveSolutionBound = true; testSubject.Refresh(); RunAsyncAction(); this.outputWindowPane.Reset(); // Sanity ConfigurableInfoBar infoBar = this.infoBarManager.AssertHasAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid); VerifyInfoBar(infoBar); // Act (kick off connection) infoBar.SimulateButtonClickEvent(); // Verify Assert.AreEqual(1, refreshCalled, "Expected to connect once"); Assert.AreEqual(0, disconnectCalled, "Not expected to disconnect"); Assert.AreEqual(0, bindingCalled, "Not expected to bind yet"); // Act (connected) this.ConfigureProjectViewModel(section); this.stateManager.SetAndInvokeBusyChanged(false); // Verify Assert.AreEqual(1, refreshCalled, "Expected to connect once"); Assert.AreEqual(1, bindingCalled, "Expected to bind once"); Assert.AreEqual(0, disconnectCalled, "Not expected to disconnect"); this.infoBarManager.AssertHasNoAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid); infoBar.VerifyAllEventsUnregistered(); this.outputWindowPane.AssertOutputStrings(0); }
public void ErrorListInfoBarController_InfoBar_ClickButton_HasConnectedActiveSection_NotBusy() { // Arrange this.SetBindingMode(SonarLintMode.LegacyConnected); var testSubject = new ErrorListInfoBarController(this.host, this.unboundProjectFinder); this.ConfigureLoadedSolution(); int bindExecuted = 0; bool canExecute = false; ProjectViewModel project = null; ConfigurableSectionController section = this.ConfigureActiveSectionWithBindCommand(args => { bindExecuted++; args.ProjectKey.Should().Be(project.Key); args.ProjectName.Should().Be(project.ProjectName); }, args => canExecute); this.ConfigureActiveSectionWithRefreshCommand(c => { FluentAssertions.Execution.Execute.Assertion.FailWith("Refresh is not expected to be called"); }); this.ConfigureActiveSectionWithDisconnectCommand(() => { FluentAssertions.Execution.Execute.Assertion.FailWith("Disconnect is not expected to be called"); }); project = this.ConfigureProjectViewModel(section); testSubject.Refresh(); RunAsyncAction(); this.outputWindowPane.Reset(); // Sanity ConfigurableInfoBar infoBar = this.infoBarManager.AssertHasAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid); VerifyInfoBar(infoBar); // Act (command disabled) infoBar.SimulateButtonClickEvent(); // Assert this.teamExplorerController.ShowConnectionsPageCallsCount.Should().Be(1); bindExecuted.Should().Be(0, "Update was not expected to be executed"); this.outputWindowPane.AssertOutputStrings(1); // Act (command enabled) canExecute = true; infoBar.SimulateButtonClickEvent(); // Assert this.teamExplorerController.ShowConnectionsPageCallsCount.Should().Be(2); bindExecuted.Should().Be(1, "Update was expected to be executed"); this.infoBarManager.AssertHasNoAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid); infoBar.VerifyAllEventsUnregistered(); this.outputWindowPane.AssertOutputStrings(1); }
public void ErrorListInfoBarController_InfoBar_ClickButton_HasConnectedActiveSection_NotBusy() { // Setup this.IsActiveSolutionBound = true; var testSubject = new ErrorListInfoBarController(this.host); this.ConfigureLoadedSolution(); int bindExecuted = 0; bool canExecute = false; ProjectViewModel project = null; ConfigurableSectionController section = this.ConfigureActiveSectionWithBindCommand(vm => { bindExecuted++; Assert.AreSame(project, vm); }, vm => canExecute); this.ConfigureActiveSectionWithRefreshCommand(c => { Assert.Fail("Refresh is not expected to be called"); }); this.ConfigureActiveSectionWithDisconnectCommand(() => { Assert.Fail("Disconnect is not expected to be called"); }); project = this.ConfigureProjectViewModel(section); testSubject.Refresh(); RunAsyncAction(); this.outputWindowPane.Reset(); // Sanity ConfigurableInfoBar infoBar = this.infoBarManager.AssertHasAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid); VerifyInfoBar(infoBar); // Act (command disabled) infoBar.SimulateButtonClickEvent(); // Verify this.teamExplorerController.AssertExpectedNumCallsShowConnectionsPage(1); Assert.AreEqual(0, bindExecuted, "Update was not expected to be executed"); this.outputWindowPane.AssertOutputStrings(1); // Act (command enabled) canExecute = true; infoBar.SimulateButtonClickEvent(); // Verify this.teamExplorerController.AssertExpectedNumCallsShowConnectionsPage(2); Assert.AreEqual(1, bindExecuted, "Update was expected to be executed"); this.infoBarManager.AssertHasNoAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid); infoBar.VerifyAllEventsUnregistered(); this.outputWindowPane.AssertOutputStrings(1); }
private ConfigurableSectionController ConfigureActiveSectionWithDisconnectCommand(Action commandAction) { var section = this.host.ActiveSection as ConfigurableSectionController; if (section == null) { section = ConfigurableSectionController.CreateDefault(); } section.ViewModel.State = this.host.VisualStateManager.ManagedState; section.DisconnectCommand = new RelayCommand(commandAction); this.host.SetActiveSection(section); return(section); }
public static ConfigurableSectionController CreateDefault() { var section = new ConfigurableSectionController(); section.ViewModel = new ConnectSectionViewModel(); section.View = new ConnectSectionView(); section.ProgressHost = new ConfigurableProgressControlHost(); section.UserNotifications = new ConfigurableUserNotification(); section.BindCommand = new RelayCommand <BindCommandArgs>(args => { }); section.ConnectCommand = new RelayCommand(() => { }); section.DisconnectCommand = new RelayCommand(() => { }); section.RefreshCommand = new RelayCommand <ConnectionInformation>(c => { }); section.BrowseToUrlCommand = new RelayCommand <string>(url => { }); section.BrowseToProjectDashboardCommand = new RelayCommand <ProjectViewModel>(vm => { }); section.ToggleShowAllProjectsCommand = new RelayCommand <ServerViewModel>(vm => { }); return(section); }
public static ConfigurableSectionController CreateDefault() { var section = new ConfigurableSectionController(); section.ViewModel = new ConnectSectionViewModel(); section.View = new ConnectSectionView(); section.ProgressHost = new ConfigurableProgressControlHost(); section.UserNotifications = new ConfigurableUserNotification(); section.BindCommand = new RelayCommand(() => { }); section.ConnectCommand = new RelayCommand(() => { }); section.DisconnectCommand = new RelayCommand(() => { }); section.RefreshCommand = new RelayCommand(() => { }); section.BrowseToUrlCommand = new RelayCommand(() => { }); section.BrowseToProjectDashboardCommand = new RelayCommand(() => { }); section.ToggleShowAllProjectsCommand = new RelayCommand(() => { }); return(section); }
private ConfigurableSectionController ConfigureActiveSectionWithBindCommand(Action <ProjectViewModel> commandAction, Predicate <ProjectViewModel> canExecuteCommand = null) { var section = this.host.ActiveSection as ConfigurableSectionController; if (section == null) { section = ConfigurableSectionController.CreateDefault(); } section.ViewModel.State = this.host.VisualStateManager.ManagedState; section.BindCommand = new RelayCommand <ProjectViewModel>(pvm => { commandAction(pvm); this.stateManager.SetAndInvokeBusyChanged(true);// Simulate product }, canExecuteCommand); this.host.SetActiveSection(section); return(section); }
private ConfigurableSectionController ConfigureActiveSectionWithRefreshCommand(Action <ConnectionInformation> commandAction, Predicate <ConnectionInformation> canExecuteCommand = null) { var section = this.host.ActiveSection as ConfigurableSectionController; if (section == null) { section = ConfigurableSectionController.CreateDefault(); } section.ViewModel.State = this.host.VisualStateManager.ManagedState; section.RefreshCommand = new RelayCommand <ConnectionInformation>(ci => { commandAction(ci); this.stateManager.SetAndInvokeBusyChanged(true);// Simulate product }, canExecuteCommand); this.host.SetActiveSection(section); return(section); }
public void ErrorListInfoBarController_InfoBar_ClickButton_MoreThanOnce() { // Setup this.IsActiveSolutionBound = true; var testSubject = new ErrorListInfoBarController(this.host); this.ConfigureLoadedSolution(); int bindCommandExecuted = 0; ConfigurableSectionController section = this.ConfigureActiveSectionWithBindCommand(vm => { bindCommandExecuted++; }); this.ConfigureProjectViewModel(section); testSubject.Refresh(); RunAsyncAction(); this.stateManager.SetAndInvokeBusyChanged(true); // Sanity ConfigurableInfoBar infoBar = this.infoBarManager.AssertHasAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid); VerifyInfoBar(infoBar); this.teamExplorerController.AssertExpectedNumCallsShowConnectionsPage(0); // Act (command enabled) infoBar.SimulateButtonClickEvent(); // Verify this.teamExplorerController.AssertExpectedNumCallsShowConnectionsPage(1); // Act (click again) infoBar.SimulateButtonClickEvent(); // Verify this.teamExplorerController.AssertExpectedNumCallsShowConnectionsPage(1); this.infoBarManager.AssertHasAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid); infoBar.VerifyAllEventsRegistered(); // Should be usable // Act (not busy anymore) this.stateManager.SetAndInvokeBusyChanged(false); // Verify this.teamExplorerController.AssertExpectedNumCallsShowConnectionsPage(1); this.infoBarManager.AssertHasNoAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid); infoBar.VerifyAllEventsUnregistered(); Assert.AreEqual(1, bindCommandExecuted, "Expecting the command to be executed only once"); }
public void ErrorListInfoBarController_InfoBar_ClickButton_MoreThanOnce() { // Arrange this.SetBindingMode(SonarLintMode.LegacyConnected); var testSubject = new ErrorListInfoBarController(this.host, this.unboundProjectFinder); this.ConfigureLoadedSolution(); int bindCommandExecuted = 0; ConfigurableSectionController section = this.ConfigureActiveSectionWithBindCommand(args => { bindCommandExecuted++; }); this.ConfigureProjectViewModel(section); testSubject.Refresh(); RunAsyncAction(); this.stateManager.SetAndInvokeBusyChanged(true); // Sanity ConfigurableInfoBar infoBar = this.infoBarManager.AssertHasAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid); VerifyInfoBar(infoBar); this.teamExplorerController.ShowConnectionsPageCallsCount.Should().Be(0); // Act (command enabled) infoBar.SimulateButtonClickEvent(); // Assert this.teamExplorerController.ShowConnectionsPageCallsCount.Should().Be(1); // Act (click again) infoBar.SimulateButtonClickEvent(); // Assert this.teamExplorerController.ShowConnectionsPageCallsCount.Should().Be(1); this.infoBarManager.AssertHasAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid); infoBar.VerifyAllEventsRegistered(); // Should be usable // Act (not busy anymore) this.stateManager.SetAndInvokeBusyChanged(false); // Assert this.teamExplorerController.ShowConnectionsPageCallsCount.Should().Be(1); this.infoBarManager.AssertHasNoAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid); infoBar.VerifyAllEventsUnregistered(); bindCommandExecuted.Should().Be(1, "Expecting the command to be executed only once"); }
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 ErrorListInfoBarController_InfoBar_ClickButton_HasActiveSection_WasBusyAndSectionClosed() { // Arrange this.IsActiveSolutionBound = true; var testSubject = new ErrorListInfoBarController(this.host); this.ConfigureLoadedSolution(); int executed = 0; ProjectViewModel project = null; ConfigurableSectionController section = this.ConfigureActiveSectionWithBindCommand(vm => { executed++; vm.Should().Be(project); }); project = this.ConfigureProjectViewModel(section); testSubject.Refresh(); RunAsyncAction(); this.stateManager.SetAndInvokeBusyChanged(true); // Sanity ConfigurableInfoBar infoBar = this.infoBarManager.AssertHasAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid); VerifyInfoBar(infoBar); this.teamExplorerController.ShowConnectionsPageCallsCount.Should().Be(0); // Act (command enabled) infoBar.SimulateButtonClickEvent(); // Assert executed.Should().Be(0, "Busy, should not be executed"); // Act (close the current section) this.host.ClearActiveSection(); this.stateManager.SetAndInvokeBusyChanged(false); RunAsyncAction(); // Assert executed.Should().Be(0, "Update was not expected to be executed since there is not ActiveSection"); this.infoBarManager.AssertHasAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid); infoBar.VerifyAllEventsRegistered(); // Should be usable }
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 TestInitialize() { serviceProvider = new ConfigurableServiceProvider(); configProvider = new ConfigurableConfigurationProvider(); configProvider.ProjectToReturn = ValidProject; serviceProvider.RegisterService(typeof(IConfigurationProvider), configProvider); var outputWindow = new ConfigurableVsOutputWindow(); outputWindowPane = outputWindow.GetOrCreateSonarLintPane(); serviceProvider.RegisterService(typeof(SVsOutputWindow), outputWindow); host = new ConfigurableHost(serviceProvider, Dispatcher.CurrentDispatcher); section = new ConfigurableSectionController(); host.SetActiveSection(section); testSubject = new UnbindCommand(host); }
public void ErrorListInfoBarController_InfoBar_ClickButton_HasActiveSection_WasBusyAndInfoBarClosed() { // Arrange this.SetBindingMode(SonarLintMode.LegacyConnected); var testSubject = new ErrorListInfoBarController(this.host, this.unboundProjectFinder); this.ConfigureLoadedSolution(); int executed = 0; ProjectViewModel project = null; ConfigurableSectionController section = this.ConfigureActiveSectionWithBindCommand(args => { executed++; args.ProjectKey.Should().Be(project.Key); args.ProjectName.Should().Be(project.ProjectName); }); project = this.ConfigureProjectViewModel(section); testSubject.Refresh(); RunAsyncAction(); this.stateManager.SetAndInvokeBusyChanged(true); // Sanity ConfigurableInfoBar infoBar = this.infoBarManager.AssertHasAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid); VerifyInfoBar(infoBar); // Act (command enabled) infoBar.SimulateButtonClickEvent(); // Assert executed.Should().Be(0, "Busy, should not be executed"); // Act (close the current info bar) testSubject.Reset(); this.stateManager.SetAndInvokeBusyChanged(false); // Assert executed.Should().Be(1, "Once started, the process can only be canceled from team explorer, closing the info bar should not impact the running update execution"); this.infoBarManager.AssertHasNoAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid); infoBar.VerifyAllEventsUnregistered(); }
public void ErrorListInfoBarController_InfoBar_ClickButton_HasActiveSection_WasBusyAndInfoBarClosed() { // Setup this.IsActiveSolutionBound = true; var testSubject = new ErrorListInfoBarController(this.host); this.ConfigureLoadedSolution(); int executed = 0; ProjectViewModel project = null; ConfigurableSectionController section = this.ConfigureActiveSectionWithBindCommand(vm => { executed++; Assert.AreSame(project, vm); }); project = this.ConfigureProjectViewModel(section); testSubject.Refresh(); RunAsyncAction(); this.stateManager.SetAndInvokeBusyChanged(true); // Sanity ConfigurableInfoBar infoBar = this.infoBarManager.AssertHasAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid); VerifyInfoBar(infoBar); // Act (command enabled) infoBar.SimulateButtonClickEvent(); // Verify Assert.AreEqual(0, executed, "Busy, should not be executed"); // Act (close the current info bar) testSubject.Reset(); this.stateManager.SetAndInvokeBusyChanged(false); // Verify Assert.AreEqual(1, executed, "Once started, the process can only be canceled from team explorer, closing the info bar should not impact the running update execution"); this.infoBarManager.AssertHasNoAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid); infoBar.VerifyAllEventsUnregistered(); }
private ProjectViewModel ConfigureProjectViewModel(ConfigurableSectionController section, Uri serverUri, string projectKey) { if (serverUri == null) { FluentAssertions.Execution.Execute.Assertion.FailWith("Test setup: the server uri is not valid"); } if (string.IsNullOrWhiteSpace(projectKey)) { FluentAssertions.Execution.Execute.Assertion.FailWith("Test setup: the project key is not valid"); } section.ViewModel.State.ConnectedServers.Clear(); var serverVM = new ServerViewModel(new ConnectionInformation(serverUri)); section.ViewModel.State.ConnectedServers.Add(serverVM); var projectVM = new ProjectViewModel(serverVM, new SonarQubeProject(projectKey, "")); serverVM.Projects.Add(projectVM); return(projectVM); }
private ProjectViewModel ConfigureProjectViewModel(ConfigurableSectionController section, Uri serverUri, string projectKey) { if (serverUri == null) { Assert.Inconclusive("Test setup: the server uri is not valid"); } if (string.IsNullOrWhiteSpace(projectKey)) { Assert.Inconclusive("Test setup: the project key is not valid"); } section.ViewModel.State.ConnectedServers.Clear(); var serverVM = new ServerViewModel(new ConnectionInformation(serverUri)); section.ViewModel.State.ConnectedServers.Add(serverVM); var projectVM = new ProjectViewModel(serverVM, new ProjectInformation { Key = projectKey }); serverVM.Projects.Add(projectVM); return projectVM; }
private ProjectViewModel ConfigureProjectViewModel(ConfigurableSectionController section) { var vm = this.ConfigureProjectViewModel(section, this.solutionBindingSerializer.CurrentBinding?.ServerUri, this.solutionBindingSerializer.CurrentBinding?.ProjectKey); if (this.solutionBindingSerializer.CurrentBinding != null) { vm.IsBound = true; } return vm; }
public static ConfigurableSectionController CreateDefault() { var section = new ConfigurableSectionController(); section.ViewModel = new ConnectSectionViewModel(); section.View = new ConnectSectionView(); section.ProgressHost = new ConfigurableProgressControlHost(); section.UserNotifications = new ConfigurableUserNotification(); section.BindCommand = new RelayCommand(() => { }); section.ConnectCommand = new RelayCommand(() => { }); section.DisconnectCommand = new RelayCommand(() => { }); section.RefreshCommand = new RelayCommand(() => { }); section.BrowseToUrlCommand = new RelayCommand(() => { }); section.BrowseToProjectDashboardCommand = new RelayCommand(() => { }); section.ToggleShowAllProjectsCommand = new RelayCommand(() => { }); return section; }