Example #1
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);
        }
Example #2
0
        public void ErrorListInfoBarController_Refresh_ActiveSolutionBound_NotFullyLoaded_HasUnboundProjects()
        {
            // Arrange
            this.SetBindingMode(SonarLintMode.LegacyConnected);
            var testSubject = new ErrorListInfoBarController(this.host, this.unboundProjectFinder);

            this.ConfigureLoadedSolution();
            SetSolutionExistsAndFullyLoadedContextState(isActive: false);

            // Act
            testSubject.Refresh();
            RunAsyncAction();

            // Assert
            this.outputWindowPane.AssertOutputStrings(0);
            this.infoBarManager.AssertHasNoAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid);

            // Act (simulate solution fully loaded event)
            SetSolutionExistsAndFullyLoadedContextState(isActive: true);

            // Assert
            this.outputWindowPane.AssertOutputStrings(2);
            this.outputWindowPane.AssertMessageContainsAllWordsCaseSensitive(1, new[] { "unbound.csproj" }, splitter: "\r\n\t ()".ToArray());
            ConfigurableInfoBar infoBar = this.infoBarManager.AssertHasAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid);

            VerifyInfoBar(infoBar);
        }
Example #3
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);
        }
Example #4
0
        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);
        }
Example #5
0
        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);
        }
Example #6
0
        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);
        }
Example #7
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);
        }
Example #8
0
        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();
        }
Example #9
0
        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();
        }
Example #10
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);
        }
Example #11
0
        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);
        }
Example #12
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);
        }
Example #13
0
        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);
        }
Example #14
0
        public void ErrorListInfoBarController_Refresh_ActiveSolutionNotBound()
        {
            // Arrange
            this.SetBindingMode(SonarLintMode.Standalone);
            var testSubject = new ErrorListInfoBarController(this.host, this.unboundProjectFinder);

            this.ConfigureLoadedSolution(hasUnboundProject: true);

            // Act
            testSubject.Refresh();
            RunAsyncAction();

            // Assert
            this.outputWindowPane.AssertOutputStrings(0);
            this.infoBarManager.AssertHasNoAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid);
        }
Example #15
0
        public void ErrorListInfoBarController_Refresh_ActiveSolutionNotBound()
        {
            // Arrange
            this.IsActiveSolutionBound = false;
            var testSubject = new ErrorListInfoBarController(this.host);

            this.ConfigureLoadedSolution(hasUnboundProject: false);

            // Act
            testSubject.Refresh();
            RunAsyncAction();

            // Assert
            this.outputWindowPane.AssertOutputStrings(0);
            this.infoBarManager.AssertHasNoAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid);
        }
Example #16
0
        public void ErrorListInfoBarController_Refresh_ActiveSolutionBecameUnboundAfterRefresh()
        {
            // Arrange
            this.SetBindingMode(SonarLintMode.LegacyConnected);
            var testSubject = new ErrorListInfoBarController(this.host, this.solutionBindingInformationProvider);

            this.ConfigureLoadedSolution(hasUnboundProject: false);

            // Act
            testSubject.Refresh();
            this.SetBindingMode(SonarLintMode.Standalone);
            RunAsyncAction();

            // Assert
            this.outputWindowPane.AssertOutputStrings(0);
            this.infoBarManager.AssertHasNoAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid);
        }
        public void ErrorListInfoBarController_Refresh_ActiveSolutionBoundAndFullyLoaded_HasNoUnboundProjects()
        {
            // Setup
            this.IsActiveSolutionBound = true;
            var testSubject = new ErrorListInfoBarController(this.host);
            this.ConfigureLoadedSolution(hasUnboundProject: false);
            // Set project system with no filtered project, to quickly stop SonarQubeQualityProfileBackgroundProcessor
            var projectSystem = new ConfigurableVsProjectSystemHelper(this.serviceProvider);
            this.serviceProvider.RegisterService(typeof(IProjectSystemHelper), projectSystem);

            // Act
            testSubject.Refresh();
            RunAsyncAction();

            // Verify
            this.outputWindowPane.AssertOutputStrings(2);
            this.infoBarManager.AssertHasNoAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid);
        }
Example #18
0
        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");
        }
Example #19
0
        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");
        }
Example #20
0
        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
        }
Example #21
0
        public void ErrorListInfoBarController_Refresh_ActiveSolutionBoundAndFullyLoaded_HasNoUnboundProjects()
        {
            // Arrange
            this.SetBindingMode(SonarLintMode.LegacyConnected);
            var testSubject = new ErrorListInfoBarController(this.host, this.unboundProjectFinder);

            this.ConfigureLoadedSolution(hasUnboundProject: false);
            // Set project system with no filtered project, to quickly stop SonarQubeQualityProfileBackgroundProcessor
            var projectSystem = new ConfigurableVsProjectSystemHelper(this.serviceProvider);

            this.serviceProvider.RegisterService(typeof(IProjectSystemHelper), projectSystem);

            // Act
            testSubject.Refresh();
            RunAsyncAction();

            // Assert
            this.outputWindowPane.AssertOutputStrings(2);
            this.infoBarManager.AssertHasNoAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid);
        }
Example #22
0
        public void ErrorListInfoBarController_Refresh_ActiveSolutionBoundAndFullyLoaded_HasUnboundProjects()
        {
            // Arrange
            this.IsActiveSolutionBound = true;
            SetSolutionExistsAndFullyLoadedContextState(isActive: true);
            this.solutionBindingInformationProvider.BoundProjects   = new[] { new ProjectMock("bound.csproj") };
            this.solutionBindingInformationProvider.UnboundProjects = new[] { new ProjectMock("unbound.csproj") };
            var testSubject = new ErrorListInfoBarController(this.host);

            // Act
            testSubject.Refresh();
            RunAsyncAction();

            // Assert
            this.outputWindowPane.AssertOutputStrings(2);
            this.outputWindowPane.AssertMessageContainsAllWordsCaseSensitive(1, new[] { "unbound.csproj" }, splitter: "\r\n\t ()".ToArray());
            ConfigurableInfoBar infoBar = this.infoBarManager.AssertHasAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid);

            VerifyInfoBar(infoBar);
        }
Example #23
0
        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();
        }
Example #24
0
        public void ErrorListInfoBarController_InfoBar_ClickButton_HasDisconnectedActiveSection_ConnectCommandIsBusy()
        {
            // Arrange
            this.SetBindingMode(SonarLintMode.LegacyConnected);
            var testSubject = new ErrorListInfoBarController(this.host, this.unboundProjectFinder);

            this.ConfigureLoadedSolution();
            int bindingCalled        = 0;
            ProjectViewModel project = null;

            this.ConfigureActiveSectionWithBindCommand(args =>
            {
                bindingCalled++;
                args.ProjectKey.Should().Be(project.Key);
                args.ProjectName.Should().Be(project.ProjectName);
            });
            int refreshCalled = 0;

            this.ConfigureActiveSectionWithRefreshCommand(connection =>
            {
                refreshCalled++;
            }, connection => false);
            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(0, "Expected to connect once");
            bindingCalled.Should().Be(0, "Not expected to bind yet");
            this.outputWindowPane.AssertOutputStrings(1);
            infoBar.VerifyAllEventsRegistered();
            this.infoBarManager.AssertHasAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid);
        }
Example #25
0
        public void ErrorListInfoBarController_CurrentBackgroundProcessorCancellation()
        {
            // Setup
            this.IsActiveSolutionBound = true;
            var testSubject = new ErrorListInfoBarController(this.host);

            this.ConfigureLoadedSolution(hasUnboundProject: false);
            var projectSystem = new ConfigurableVsProjectSystemHelper(this.serviceProvider);

            this.serviceProvider.RegisterService(typeof(IProjectSystemHelper), projectSystem);
            var project = new ProjectMock("project.proj");

            project.SetCSProjectKind();
            projectSystem.FilteredProjects = new[] { project };
            this.solutionBindingSerializer.CurrentBinding.Profiles = new Dictionary <Language, Persistence.ApplicableQualityProfile>();
            this.solutionBindingSerializer.CurrentBinding.Profiles[Language.CSharp] = new Persistence.ApplicableQualityProfile
            {
                ProfileKey       = "Profile",
                ProfileTimestamp = DateTime.Now
            };
            var sqService = new ConfigurableSonarQubeServiceWrapper();

            this.host.SonarQubeService = sqService;
            sqService.ReturnProfile[Language.CSharp] = new QualityProfile();

            // Act
            testSubject.ProcessSolutionBinding();

            // Verify
            Assert.IsNotNull(testSubject.CurrentBackgroundProcessor?.BackgroundTask, "Background task is expected");
            Assert.IsTrue(testSubject.CurrentBackgroundProcessor.BackgroundTask.Wait(TimeSpan.FromSeconds(2)), "Timeout waiting for the background task");
            this.infoBarManager.AssertHasNoAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid);

            // Act (refresh again and  let the blocked UI thread run to completion)
            testSubject.ProcessSolutionBinding();
            DispatcherHelper.DispatchFrame(DispatcherPriority.Normal);
            this.IsActiveSolutionBound = false;

            // Verify that no info bar was added (due to the last action in which the state will not cause the info bar to appear)
            this.infoBarManager.AssertHasNoAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid);
        }
Example #26
0
        public void ErrorListInfoBarController_InfoBar_ClickButton_NoActiveSection_NavigatesToSection()
        {
            // Setup
            this.IsActiveSolutionBound = true;
            var testSubject = new ErrorListInfoBarController(this.host);

            this.ConfigureLoadedSolution();
            testSubject.Refresh();
            RunAsyncAction();

            // Sanity
            ConfigurableInfoBar infoBar = this.infoBarManager.AssertHasAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid);

            VerifyInfoBar(infoBar);

            // Act
            infoBar.SimulateButtonClickEvent();

            // Verify
            this.teamExplorerController.AssertExpectedNumCallsShowConnectionsPage(1);
        }
Example #27
0
        public void ErrorListInfoBarController_InfoBar_ClickButton_NoActiveSection_NavigatesToSection()
        {
            // Arrange
            this.SetBindingMode(SonarLintMode.LegacyConnected);
            var testSubject = new ErrorListInfoBarController(this.host, this.unboundProjectFinder);

            this.ConfigureLoadedSolution();
            testSubject.Refresh();
            RunAsyncAction();

            // Sanity
            ConfigurableInfoBar infoBar = this.infoBarManager.AssertHasAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid);

            VerifyInfoBar(infoBar);

            // Act
            infoBar.SimulateButtonClickEvent();

            // Assert
            this.teamExplorerController.ShowConnectionsPageCallsCount.Should().Be(1);
        }
Example #28
0
        public void ErrorListInfoBarController_InfoBar_ClickButton_HasDisconnectedActiveSection_ConnectCommandIsBusy()
        {
            // Setup
            this.IsActiveSolutionBound = true;
            var testSubject = new ErrorListInfoBarController(this.host);

            this.ConfigureLoadedSolution();
            int bindingCalled        = 0;
            ProjectViewModel project = null;

            this.ConfigureActiveSectionWithBindCommand(vm =>
            {
                bindingCalled++;
                Assert.AreSame(project, vm);
            });
            int refreshCalled = 0;

            this.ConfigureActiveSectionWithRefreshCommand(connection =>
            {
                refreshCalled++;
            }, connection => false);
            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(0, refreshCalled, "Expected to connect once");
            Assert.AreEqual(0, bindingCalled, "Not expected to bind yet");
            this.outputWindowPane.AssertOutputStrings(1);
            infoBar.VerifyAllEventsRegistered();
            this.infoBarManager.AssertHasAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid);
        }
Example #29
0
        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();
        }
Example #30
0
        public void ErrorListInfoBarController_RefreshShowInfoBar_ClickClose_UnregisterEvents()
        {
            // Arrange
            this.SetBindingMode(SonarLintMode.LegacyConnected);
            var testSubject = new ErrorListInfoBarController(this.host, this.unboundProjectFinder);

            this.ConfigureLoadedSolution();
            testSubject.Refresh();
            RunAsyncAction();

            // Sanity
            ConfigurableInfoBar infoBar = this.infoBarManager.AssertHasAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid);

            VerifyInfoBar(infoBar);

            // Act
            infoBar.SimulateClosedEvent();

            // Assert
            infoBar.VerifyAllEventsUnregistered();
            this.teamExplorerController.ShowConnectionsPageCallsCount.Should().Be(0);
        }
Example #31
0
        public void ErrorListInfoBarController_InfoBar_ClickButton_HasConnectedActiveSection_IsBusy()
        {
            // 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);
            });

            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
            this.stateManager.SetAndInvokeBusyChanged(false);

            // Assert
            executed.Should().Be(1, "Update was expected to be executed");
            this.infoBarManager.AssertHasNoAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid);
            infoBar.VerifyAllEventsUnregistered();
        }
        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);
        }
        public void ErrorListInfoBarController_InfoBar_ClickButton_HasDisconnectedActiveSection_ConnectCommandIsBusy()
        {
            // Setup
            this.IsActiveSolutionBound = true;
            var testSubject = new ErrorListInfoBarController(this.host);
            this.ConfigureLoadedSolution();
            int bindingCalled = 0;
            ProjectViewModel project = null;
            this.ConfigureActiveSectionWithBindCommand(vm =>
            {
                bindingCalled++;
                Assert.AreSame(project, vm);
            });
            int refreshCalled = 0;
            this.ConfigureActiveSectionWithRefreshCommand(connection =>
            {
                refreshCalled++;
            }, connection => false);
            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(0, refreshCalled, "Expected to connect once");
            Assert.AreEqual(0, bindingCalled, "Not expected to bind yet");
            this.outputWindowPane.AssertOutputStrings(1);
            infoBar.VerifyAllEventsRegistered();
            this.infoBarManager.AssertHasAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid);
        }
        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_SolutionBindingAreDifferentThatTheOnesUsedForTheInfoBar()
        {
            // Setup
            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();

            // Verify
            this.teamExplorerController.AssertExpectedNumCallsShowConnectionsPage(0);
            this.infoBarManager.AssertHasNoAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid);
            this.outputWindowPane.AssertOutputStrings(1);
        }
        private void VerifyBackgroundExecution(bool updateRequired, ErrorListInfoBarController.QualityProfileBackgroundProcessor testSubject, params string[] expectedOutput)
        {
            // Act
            int called = 0;
            testSubject.QueueCheckIfUpdateIsRequired((customMessage) =>
            {
                Assert.IsNull(customMessage, "Not expecting any message customizations");
                called++;
            });

            // Verify
            Assert.AreEqual(0, called, "Not expected to be immediate");
            Assert.IsNotNull(testSubject.BackgroundTask, "Expected to start processing in the background");

            // Run the background task
            Assert.IsTrue(testSubject.BackgroundTask.Wait(TimeSpan.FromSeconds(2)), "Timeout waiting for the background task");
            Assert.AreEqual(0, called, "The UI thread (this one) should be blocked");

            // Run the UI async action
            DispatcherHelper.DispatchFrame(DispatcherPriority.Normal); // Allow the BeginInvoke to run

            if (updateRequired)
            {
                Assert.AreEqual(1, called, "Expected to call the update action");
            }
            else
            {
                Assert.AreEqual(0, called, "Not expected to call the update action");
            }

            this.outputWindowPane.AssertOutputStrings(expectedOutput);
        }
        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_HasActiveSection_WasBusyAndSectionClosed()
        {
            // 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);
            this.teamExplorerController.AssertExpectedNumCallsShowConnectionsPage(0);

            // Act (command enabled)
            infoBar.SimulateButtonClickEvent();

            // Verify
            Assert.AreEqual(0, executed, "Busy, should not be executed");

            // Act (close the current section)
            this.host.ClearActiveSection();
            this.stateManager.SetAndInvokeBusyChanged(false);
            RunAsyncAction();

            // Verify
            Assert.AreEqual(0, executed, "Update was not expected to be executed since there is not ActiveSection");
            this.infoBarManager.AssertHasAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid);
            infoBar.VerifyAllEventsRegistered(); // Should be usable
        }
        public void ErrorListInfoBarController_InfoBar_ClickButton_HasConnectedActiveSection_IsBusy()
        {
            // 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
            this.stateManager.SetAndInvokeBusyChanged(false);

            // Verify
            Assert.AreEqual(1, executed, "Update was expected to be executed");
            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 cancelled from team explorer, closing the info bar should not impact the running update execution");
            this.infoBarManager.AssertHasNoAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid);
            infoBar.VerifyAllEventsUnregistered();
        }
        public void ErrorListInfoBarController_Refresh_ActiveSolutionBecameUnboundAfterRefresh()
        {
            // Setup
            this.IsActiveSolutionBound = true;
            var testSubject = new ErrorListInfoBarController(this.host);
            this.ConfigureLoadedSolution(hasUnboundProject: false);

            // Act
            testSubject.Refresh();
            this.IsActiveSolutionBound = false;
            RunAsyncAction();

            // Verify
            this.outputWindowPane.AssertOutputStrings(0);
            this.infoBarManager.AssertHasNoAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid);
        }
        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_CurrentBackgroundProcessorCancellation()
        {
            // Setup
            this.IsActiveSolutionBound = true;
            var testSubject = new ErrorListInfoBarController(this.host);
            this.ConfigureLoadedSolution(hasUnboundProject: false);
            var projectSystem = new ConfigurableVsProjectSystemHelper(this.serviceProvider);
            this.serviceProvider.RegisterService(typeof(IProjectSystemHelper), projectSystem);
            var project = new ProjectMock("project.proj");
            project.SetCSProjectKind();
            projectSystem.FilteredProjects = new[] { project };
            this.solutionBindingSerializer.CurrentBinding.Profiles = new Dictionary<Language, Persistence.ApplicableQualityProfile>();
            this.solutionBindingSerializer.CurrentBinding.Profiles[Language.CSharp] = new Persistence.ApplicableQualityProfile
            {
                ProfileKey = "Profile",
                ProfileTimestamp = DateTime.Now
            };
            var sqService = new ConfigurableSonarQubeServiceWrapper();
            this.host.SonarQubeService = sqService;
            sqService.ReturnProfile[Language.CSharp] = new QualityProfile();

            // Act
            testSubject.ProcessSolutionBinding();

            // Verify
            Assert.IsNotNull(testSubject.CurrentBackgroundProcessor?.BackgroundTask, "Background task is expected");
            Assert.IsTrue(testSubject.CurrentBackgroundProcessor.BackgroundTask.Wait(TimeSpan.FromSeconds(2)), "Timeout waiting for the background task");
            this.infoBarManager.AssertHasNoAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid);

            // Act (refresh again and  let the blocked UI thread run to completion)
            testSubject.ProcessSolutionBinding();
            DispatcherHelper.DispatchFrame(DispatcherPriority.Normal);
            this.IsActiveSolutionBound = false;

            // Verify that no info bar was added (due to the last action in which the state will not cause the info bar to appear)
            this.infoBarManager.AssertHasNoAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid);
        }
        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_RefreshShowInfoBar_ClickClose_UnregisterEvents()
        {
            // Setup
            this.IsActiveSolutionBound = true;
            var testSubject = new ErrorListInfoBarController(this.host);
            this.ConfigureLoadedSolution();
            testSubject.Refresh();
            RunAsyncAction();

            // Sanity
            ConfigurableInfoBar infoBar = this.infoBarManager.AssertHasAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid);
            VerifyInfoBar(infoBar);

            // Act
            infoBar.SimulateClosedEvent();

            // Verify
            infoBar.VerifyAllEventsUnregistered();
            this.teamExplorerController.AssertExpectedNumCallsShowConnectionsPage(0);
        }
        public void ErrorListInfoBarController_Refresh_ActiveSolutionBoundAndFullyLoaded_HasUnboundProjects()
        {
            // Setup
            this.IsActiveSolutionBound = true;
            SetSolutionExistsAndFullyLoadedContextState(isActive: true);
            this.solutionBindingInformationProvider.BoundProjects = new[] { new ProjectMock("bound.csproj") };
            this.solutionBindingInformationProvider.UnboundProjects = new[] { new ProjectMock("unbound.csproj") };
            var testSubject = new ErrorListInfoBarController(this.host);

            // Act
            testSubject.Refresh();
            RunAsyncAction();

            // Verify
            this.outputWindowPane.AssertOutputStrings(2);
            this.outputWindowPane.AssertMessageContainsAllWordsCaseSensitive(1, new[] { "unbound.csproj" }, splitter: "\r\n\t ()".ToArray());
            ConfigurableInfoBar infoBar = this.infoBarManager.AssertHasAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid);
            VerifyInfoBar(infoBar);
        }
        public void ErrorListInfoBarController_InfoBar_ClickButton_HasActiveSection_NavigatesToSection()
        {
            // Setup
            this.IsActiveSolutionBound = true;
            var testSubject = new ErrorListInfoBarController(this.host);
            this.ConfigureLoadedSolution();
            this.host.SetActiveSection(ConfigurableSectionController.CreateDefault());
            testSubject.Refresh();
            RunAsyncAction();

            // Sanity
            ConfigurableInfoBar infoBar = this.infoBarManager.AssertHasAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid);
            VerifyInfoBar(infoBar);

            // Act
            infoBar.SimulateButtonClickEvent();

            // Verify
            this.teamExplorerController.AssertExpectedNumCallsShowConnectionsPage(1);
        }