Пример #1
0
        public void StateManager_ToggleShowAllProjectsCommand_DynamicText()
        {
            // Setup
            var section                  = ConfigurableSectionController.CreateDefault();
            ConfigurableHost host        = new ConfigurableHost();
            StateManager     testSubject = this.CreateTestSubject(host, section);
            var connection1              = new ConnectionInformation(new Uri("http://127.0.0.1"));
            var projects                 = new ProjectInformation[] { new ProjectInformation(), new ProjectInformation() };

            testSubject.SetProjects(connection1, projects);
            ServerViewModel serverVM = testSubject.ManagedState.ConnectedServers.Single();

            host.SetActiveSection(section);
            testSubject.SyncCommandFromActiveSection();
            ContextualCommandViewModel toggleContextCmd = serverVM.Commands.First(x => x.InternalRealCommand.Equals(section.ToggleShowAllProjectsCommand));

            // Case 1: No bound projects
            serverVM.ShowAllProjects = true;
            // Act + Verify
            Assert.AreEqual(Strings.HideUnboundProjectsCommandText, toggleContextCmd.DisplayText, "Unexpected disabled context command text");

            // Case 2: has bound projects
            serverVM.ShowAllProjects = false;

            // Act + Verify
            Assert.AreEqual(Strings.ShowAllProjectsCommandText, toggleContextCmd.DisplayText, "Unexpected context command text");
        }
        public void StateManager_SetProjectsUIThread_With_BoundProjectKey()
        {
            // Arrange
            var section = ConfigurableSectionController.CreateDefault();
            ConfigurableUserNotification notifications = (ConfigurableUserNotification)section.UserNotifications;
            ConfigurableHost             host          = new ConfigurableHost();
            StateManager testSubject = this.CreateTestSubject(host);

            host.VisualStateManager = testSubject;
            section.ViewModel.State = testSubject.ManagedState;
            host.SetActiveSection(section);

            var connection1 = new ConnectionInformation(new Uri("http://127.0.0.1"));
            var projects    = new[] { new SonarQubeProject("project1", ""), new SonarQubeProject("project2", "") };

            // Case 1 - projects does not contain BoundProjectKey
            testSubject.BoundProjectKey = "missing_project";
            testSubject.SetProjects(connection1, projects);

            // Assert
            var message = notifications.AssertNotification(NotificationIds.FailedToFindBoundProjectKeyId);

            message.Should().MatchRegex("\\[.+\\]\\(\\)"); // Contains the hyperlink syntax [text]()
            notifications.AssertNotification(NotificationIds.FailedToFindBoundProjectKeyId, section.ReconnectCommand);

            // Case 2 - projects contains BoundProjectKey
            testSubject.BoundProjectKey = "project1";
            testSubject.SetProjects(connection1, projects);

            // Assert
            notifications.AssertNoNotification(NotificationIds.FailedToFindBoundProjectKeyId);
        }
        public void VsSessionHost_SetActiveSection()
        {
            // Setup
            VsSessionHost testSubject = this.CreateTestSubject(null);

            // Case 1: Invalid args
            Exceptions.Expect <ArgumentNullException>(() => testSubject.SetActiveSection(null));

            // Case 2: Valid args
            var  section1       = ConfigurableSectionController.CreateDefault();
            var  section2       = ConfigurableSectionController.CreateDefault();
            bool refresh1Called = false;

            section1.RefreshCommand = new RelayCommand(() => refresh1Called = true);
            bool refresh2Called = false;

            section2.RefreshCommand = new RelayCommand(() => refresh2Called = true);

            // Act (set section1)
            testSubject.SetActiveSection(section1);
            Assert.IsFalse(refresh1Called, "Refresh should only be called when bound project was found");
            Assert.IsFalse(refresh2Called, "Refresh should only be called when bound project was found");

            // Verify
            Assert.AreSame(section1, testSubject.ActiveSection);

            // Act (set section2)
            testSubject.ClearActiveSection();
            testSubject.SetActiveSection(section2);

            // Verify
            Assert.AreSame(section2, testSubject.ActiveSection);
            Assert.IsFalse(refresh1Called, "Refresh should only be called when bound project was found");
            Assert.IsFalse(refresh2Called, "Refresh should only be called when bound project was found");
        }
Пример #4
0
        public void VsSessionHost_ResetBinding_BoundSolutionWithActiveSectionScenario()
        {
            // Arrange
            var tracker      = new ConfigurableActiveSolutionTracker();
            var testSubject  = this.CreateTestSubject(tracker);
            var boundProject = new SonarQubeProject("bla", "");

            this.stateManager.SetBoundProject(boundProject);
            this.solutionBinding.CurrentBinding = new Persistence.BoundSonarQubeProject(new Uri("http://bound"), boundProject.Key);
            var  section       = ConfigurableSectionController.CreateDefault();
            bool refreshCalled = false;

            section.RefreshCommand = new RelayCommand(() => refreshCalled = true);
            testSubject.SetActiveSection(section);

            // Sanity
            this.stateManager.BoundProject.Should().Be(boundProject);
            this.stepRunner.AbortAllNumberOfCalls.Should().Be(0);

            // Act (simulate solution opened event)
            tracker.SimulateActiveSolutionChanged();

            // Assert
            this.stepRunner.AbortAllNumberOfCalls.Should().Be(1);
            this.stateManager.BoundProjectKey.Should().Be(boundProject.Key, "Key was not set, will not be able to mark project as bound after refresh");
            this.stateManager.BoundProject.Should().Be(boundProject);
            refreshCalled.Should().BeTrue("Expected the refresh command to be called");
        }
        public void VsSessionHost_ResetBinding_ErrorInReadingSolutionBinding()
        {
            // Setup
            var tracker      = new ConfigurableActiveSolutionTracker();
            var testSubject  = this.CreateTestSubject(tracker);
            var boundProject = new Integration.Service.ProjectInformation {
                Key = "bla"
            };

            this.stateManager.SetBoundProject(boundProject);
            this.solutionBinding.CurrentBinding = new Persistence.BoundSonarQubeProject(new Uri("http://bound"), boundProject.Key);
            var section = ConfigurableSectionController.CreateDefault();

            testSubject.SetActiveSection(section);

            // Sanity
            this.stateManager.AssertBoundProject(boundProject);
            this.stepRunner.AssertAbortAllCalled(0);

            // Introduce an error
            this.solutionBinding.ReadSolutionBindingAction = () => { throw new Exception("boom"); };

            // Act (i.e. simulate loading a different solution)
            using (new AssertIgnoreScope()) // Ignore exception assert
            {
                tracker.SimulateActiveSolutionChanged();
            }

            // Verify
            this.stateManager.AssertNoBoundProject();
        }
        public void VsSessionHost_ResetBinding_BoundSolutionWithActiveSectionScenario()
        {
            // Setup
            var tracker      = new ConfigurableActiveSolutionTracker();
            var testSubject  = this.CreateTestSubject(tracker);
            var boundProject = new Integration.Service.ProjectInformation {
                Key = "bla"
            };

            this.stateManager.SetBoundProject(boundProject);
            this.solutionBinding.CurrentBinding = new Persistence.BoundSonarQubeProject(new Uri("http://bound"), boundProject.Key);
            var  section       = ConfigurableSectionController.CreateDefault();
            bool refreshCalled = false;

            section.RefreshCommand = new RelayCommand(() => refreshCalled = true);
            testSubject.SetActiveSection(section);

            // Sanity
            this.stateManager.AssertBoundProject(boundProject);
            this.stepRunner.AssertAbortAllCalled(0);

            // Act (simulate solution opened event)
            tracker.SimulateActiveSolutionChanged();

            // Verify
            this.stepRunner.AssertAbortAllCalled(1);
            Assert.AreEqual(boundProject.Key, this.stateManager.BoundProjectKey, "Key was not set, will not be able to mark project as bound after refresh");
            this.stateManager.AssertBoundProject(boundProject);
            Assert.IsTrue(refreshCalled, "Expected the refresh command to be called");
        }
Пример #7
0
        public void VsSessionHost_ResetBinding_ErrorInReadingSolutionBinding()
        {
            // Arrange
            var tracker      = new ConfigurableActiveSolutionTracker();
            var testSubject  = this.CreateTestSubject(tracker);
            var boundProject = new SonarQubeProject("bla", "");

            this.stateManager.SetBoundProject(boundProject);
            this.solutionBinding.CurrentBinding = new BoundSonarQubeProject(new Uri("http://bound"), boundProject.Key);
            var section = ConfigurableSectionController.CreateDefault();

            testSubject.SetActiveSection(section);

            // Sanity
            this.stateManager.BoundProject.Should().Be(boundProject);
            this.stepRunner.AbortAllNumberOfCalls.Should().Be(0);

            // Introduce an error
            this.solutionBinding.ReadSolutionBindingAction = () => { throw new Exception("boom"); };

            // Act (i.e. simulate loading a different solution)
            using (new AssertIgnoreScope()) // Ignore exception assert
            {
                tracker.SimulateActiveSolutionChanged();
            }

            // Assert
            this.stateManager.BoundProject.Should().BeNull();
        }
        public void ConnectionWorkflow_ConnectionStep_WhenMissingCSharpPluginAndVBNetPlugin_AbortsWorkflowAndDisconnects()
        {
            // Setup
            var connectionInfo             = new ConnectionInformation(new Uri("http://server"));
            ConnectionWorkflow testSubject = new ConnectionWorkflow(this.host, new RelayCommand(() => { }));
            var controller = new ConfigurableProgressController();

            this.sonarQubeService.AllowConnections         = true;
            this.sonarQubeService.ReturnProjectInformation = new ProjectInformation[0];
            this.sonarQubeService.ClearServerPlugins();
            this.host.SetActiveSection(ConfigurableSectionController.CreateDefault());
            ConfigurableUserNotification notifications = (ConfigurableUserNotification)this.host.ActiveSection.UserNotifications;
            var executionEvents = new ConfigurableProgressStepExecutionEvents();

            // Act
            testSubject.ConnectionStep(controller, CancellationToken.None, connectionInfo, executionEvents);

            // Verify
            controller.AssertNumberOfAbortRequests(1);
            executionEvents.AssertProgressMessages(
                connectionInfo.ServerUri.ToString(),
                Strings.DetectingServerPlugins,
                Strings.ConnectionResultFailure);
            notifications.AssertNotification(NotificationIds.BadServerPluginId, Strings.ServerHasNoSupportedPluginVersion);
        }
        public void TestInit()
        {
            this.serviceProvider  = new ConfigurableServiceProvider();
            this.sonarQubeService = new ConfigurableSonarQubeServiceWrapper();
            this.host             = new ConfigurableHost(this.serviceProvider, Dispatcher.CurrentDispatcher);
            this.host.SetActiveSection(ConfigurableSectionController.CreateDefault());
            this.host.SonarQubeService = this.sonarQubeService;
            this.projectSystemHelper   = new ConfigurableVsProjectSystemHelper(this.serviceProvider);

            this.sonarQubeService.RegisterServerPlugin(new ServerPlugin {
                Key = MinimumSupportedServerPlugin.CSharp.Key, Version = MinimumSupportedServerPlugin.CSharp.MinimumVersion
            });
            this.sonarQubeService.RegisterServerPlugin(new ServerPlugin {
                Key = MinimumSupportedServerPlugin.VbNet.Key, Version = MinimumSupportedServerPlugin.VbNet.MinimumVersion
            });
            this.settings = new ConfigurableIntegrationSettings {
                AllowNuGetPackageInstall = true
            };

            var mefExports = MefTestHelpers.CreateExport <IIntegrationSettings>(settings);
            var mefModel   = ConfigurableComponentModel.CreateWithExports(mefExports);

            this.serviceProvider.RegisterService(typeof(SComponentModel), mefModel);

            this.filter = new ConfigurableProjectSystemFilter();
            this.serviceProvider.RegisterService(typeof(IProjectSystemFilter), this.filter);

            var outputWindow = new ConfigurableVsOutputWindow();

            this.outputWindowPane = outputWindow.GetOrCreateSonarLintPane();
            this.serviceProvider.RegisterService(typeof(SVsOutputWindow), outputWindow);
            this.serviceProvider.RegisterService(typeof(IProjectSystemHelper), this.projectSystemHelper);
        }
Пример #10
0
        public void VsSessionHost_SyncCommandFromActiveSectionDuringActiveSectionChanges()
        {
            // Arrange
            VsSessionHost      testSubject = this.CreateTestSubject(null);
            ISectionController section     = ConfigurableSectionController.CreateDefault();
            int syncCalled = 0;

            this.stateManager.SyncCommandFromActiveSectionAction = () => syncCalled++;

            // Case 1: SetActiveSection
            this.stateManager.ExpectActiveSection = true;

            // Act
            testSubject.SetActiveSection(section);

            // Assert
            syncCalled.Should().Be(1, "SyncCommandFromActiveSection wasn't called during section activation");

            // Case 2: ClearActiveSection section
            this.stateManager.ExpectActiveSection = false;

            // Act
            testSubject.ClearActiveSection();

            // Assert
            syncCalled.Should().Be(2, "SyncCommandFromActiveSection wasn't called during section deactivation");
        }
Пример #11
0
        public void VsSessionHost_SetActiveSection()
        {
            // Arrange
            VsSessionHost testSubject = this.CreateTestSubject(null);

            // Case 1: Invalid args
            Exceptions.Expect <ArgumentNullException>(() => testSubject.SetActiveSection(null));

            // Case 2: Valid args
            var  section1       = ConfigurableSectionController.CreateDefault();
            var  section2       = ConfigurableSectionController.CreateDefault();
            bool refresh1Called = false;

            section1.RefreshCommand = new RelayCommand(() => refresh1Called = true);
            bool refresh2Called = false;

            section2.RefreshCommand = new RelayCommand(() => refresh2Called = true);

            // Act (set section1)
            testSubject.SetActiveSection(section1);
            refresh1Called.Should().BeFalse();
            refresh2Called.Should().BeFalse();

            // Assert
            testSubject.ActiveSection.Should().Be(section1);

            // Act (set section2)
            testSubject.ClearActiveSection();
            testSubject.SetActiveSection(section2);

            // Assert
            testSubject.ActiveSection.Should().Be(section2);
            refresh1Called.Should().BeFalse();
            refresh2Called.Should().BeFalse();
        }
        public async Task ConnectionWorkflow_ConnectionStep_WhenMissingCSharpPluginAndVBNetPlugin_AbortsWorkflowAndDisconnects()
        {
            // Arrange
            var connectionInfo             = new ConnectionInformation(new Uri("http://server"));
            ConnectionWorkflow testSubject = new ConnectionWorkflow(this.host, new RelayCommand(() => { }));
            var controller = new ConfigurableProgressController();

            this.sonarQubeServiceMock.Setup(x => x.GetAllProjectsAsync(It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(new List <SonarQubeProject>());
            this.sonarQubeServiceMock.Setup(x => x.GetAllPluginsAsync(It.IsAny <CancellationToken>()))
            .ReturnsAsync(new List <SonarQubePlugin>());
            this.host.SetActiveSection(ConfigurableSectionController.CreateDefault());
            ConfigurableUserNotification notifications = (ConfigurableUserNotification)this.host.ActiveSection.UserNotifications;
            var executionEvents = new ConfigurableProgressStepExecutionEvents();

            // Act
            await testSubject.ConnectionStepAsync(connectionInfo, controller, executionEvents, CancellationToken.None);

            // Assert
            controller.NumberOfAbortRequests.Should().Be(1);
            AssertServiceDisconnectCalled();
            executionEvents.AssertProgressMessages(
                connectionInfo.ServerUri.ToString(),
                Strings.ConnectionStepValidatinCredentials,
                Strings.DetectingSonarQubePlugins,
                Strings.ConnectionResultFailure);
            notifications.AssertNotification(NotificationIds.BadSonarQubePluginId, Strings.ServerHasNoSupportedPluginVersion);

            AssertCredentialsNotStored(); // Username and password are null
        }
        public void TestInit()
        {
            this.serviceProvider      = new ConfigurableServiceProvider();
            this.sonarQubeServiceMock = new Mock <ISonarQubeService>();
            this.host = new ConfigurableHost(this.serviceProvider, Dispatcher.CurrentDispatcher);
            this.host.SetActiveSection(ConfigurableSectionController.CreateDefault());
            this.host.SonarQubeService = this.sonarQubeServiceMock.Object;
            this.projectSystemHelper   = new ConfigurableVsProjectSystemHelper(this.serviceProvider);

            this.sonarQubeServiceMock.Setup(x => x.GetAllPluginsAsync(It.IsAny <CancellationToken>()))
            .ReturnsAsync(new List <SonarQubePlugin>
            {
                new SonarQubePlugin(MinimumSupportedSonarQubePlugin.CSharp.Key, MinimumSupportedSonarQubePlugin.CSharp.MinimumVersion),
                new SonarQubePlugin(MinimumSupportedSonarQubePlugin.VbNet.Key, MinimumSupportedSonarQubePlugin.VbNet.MinimumVersion)
            });
            this.settings = new ConfigurableSonarLintSettings();

            var mefExports = MefTestHelpers.CreateExport <ISonarLintSettings>(settings);
            var mefModel   = ConfigurableComponentModel.CreateWithExports(mefExports);

            this.serviceProvider.RegisterService(typeof(SComponentModel), mefModel);

            this.filter = new ConfigurableProjectSystemFilter();
            this.serviceProvider.RegisterService(typeof(IProjectSystemFilter), this.filter);

            var outputWindow = new ConfigurableVsOutputWindow();

            this.outputWindowPane = outputWindow.GetOrCreateSonarLintPane();
            this.serviceProvider.RegisterService(typeof(SVsOutputWindow), outputWindow);
            this.serviceProvider.RegisterService(typeof(IProjectSystemHelper), this.projectSystemHelper);

            this.credentialStoreMock = new Mock <ICredentialStoreService>();
            this.serviceProvider.RegisterService(typeof(ICredentialStoreService), this.credentialStoreMock.Object);
        }
Пример #14
0
        public void VsSessionHost_ResetBinding_BoundSolutionWithNoActiveSectionScenario()
        {
            // Arrange
            var tracker      = new ConfigurableActiveSolutionTracker();
            var testSubject  = this.CreateTestSubject(tracker);
            var boundProject = new SonarQubeProject("bla", "");

            this.solutionBinding.CurrentBinding = new Persistence.BoundSonarQubeProject(new Uri("http://bound"), boundProject.Key);
            this.stateManager.SetBoundProject(boundProject);

            // Sanity
            this.stateManager.BoundProject.Should().Be(boundProject);
            this.stepRunner.AbortAllNumberOfCalls.Should().Be(0);

            // Act (simulate solution opened event)
            tracker.SimulateActiveSolutionChanged();

            // Assert that nothing has changed (should defer all the work to when the section is connected)
            this.stepRunner.AbortAllNumberOfCalls.Should().Be(1);
            this.stateManager.BoundProject.Should().Be(boundProject);
            this.stateManager.BoundProjectKey.Should().BeNull("The key should only be set when there's active section to allow marking it once fetched all the projects");

            // Act (set active section)
            var  section       = ConfigurableSectionController.CreateDefault();
            bool refreshCalled = false;

            section.RefreshCommand = new RelayCommand(() => refreshCalled = true);
            testSubject.SetActiveSection(section);

            // Assert (section has refreshed, no further aborts were required)
            this.stepRunner.AbortAllNumberOfCalls.Should().Be(1);
            this.stateManager.BoundProjectKey.Should().Be(boundProject.Key, "Key was not set, will not be able to mark project as bound after refresh");
            this.stateManager.BoundProject.Should().Be(boundProject);
            refreshCalled.Should().BeTrue("Expected the refresh command to be called");
        }
Пример #15
0
        public void VsSessionHost_ResetBinding_ErrorInReadingBinding()
        {
            // Arrange
            var tracker     = new ConfigurableActiveSolutionTracker();
            var testSubject = this.CreateTestSubject(tracker);

            this.stateManager.SetBoundProject(new Uri("http://bound"), null, "bla");
            SetConfiguration(new BoundSonarQubeProject(new Uri("http://bound"), "bla", "projectName"), SonarLintMode.LegacyConnected);
            var section = ConfigurableSectionController.CreateDefault();

            testSubject.SetActiveSection(section);

            // Sanity
            this.stateManager.AssignedProjectKey.Should().Be("bla");
            this.stepRunner.AbortAllNumberOfCalls.Should().Be(0);

            // Introduce an error
            this.configProvider.GetConfigurationAction = () => { throw new Exception("boom"); };

            // Act (i.e. simulate loading a different solution)
            using (new AssertIgnoreScope()) // Ignore exception assert
            {
                tracker.SimulateActiveSolutionChanged(isSolutionOpen: true);
            }

            // Assert
            this.stateManager.AssignedProjectKey.Should().BeNull();
        }
        public void StateManager_ClearBoundProject()
        {
            // Arrange
            var section = ConfigurableSectionController.CreateDefault();
            ConfigurableUserNotification notifications = (ConfigurableUserNotification)section.UserNotifications;
            ConfigurableHost             host          = new ConfigurableHost();

            host.SetActiveSection(section);
            StateManager testSubject = this.CreateTestSubject(host);

            section.UserNotifications.ShowNotificationError("message", NotificationIds.FailedToFindBoundProjectKeyId, null);
            testSubject.ManagedState.ConnectedServers.Add(new ServerViewModel(new ConnectionInformation(new Uri("http://zzz1"))));
            testSubject.ManagedState.ConnectedServers.Add(new ServerViewModel(new ConnectionInformation(new Uri("http://zzz2"))));
            testSubject.ManagedState.ConnectedServers.ToList().ForEach(s => s.Projects.Add(new ProjectViewModel(s, new SonarQubeProject(Guid.NewGuid().ToString(), ""))));
            var allProjects = testSubject.ManagedState.ConnectedServers.SelectMany(s => s.Projects).ToList();

            testSubject.SetBoundProject(new Uri("http://zzz1"), null, allProjects.First().Project.Key);

            // Sanity
            testSubject.ManagedState.HasBoundProject.Should().BeTrue();

            // Act
            testSubject.ClearBoundProject();

            // Assert
            testSubject.ManagedState.HasBoundProject.Should().BeFalse();
            notifications.AssertNoNotification(NotificationIds.FailedToFindBoundProjectKeyId);
        }
        public void StateManager_BindCommand_DynamicText()
        {
            // Arrange
            var section                  = ConfigurableSectionController.CreateDefault();
            ConfigurableHost host        = new ConfigurableHost();
            StateManager     testSubject = this.CreateTestSubject(host, section);
            var connection1              = new ConnectionInformation(new Uri("http://127.0.0.1"));
            var projects                 = new SonarQubeProject[] { new SonarQubeProject("", "") };

            testSubject.SetProjects(connection1, projects);
            ProjectViewModel projectVM = testSubject.ManagedState.ConnectedServers.Single().Projects.Single();

            host.SetActiveSection(section);
            testSubject.SyncCommandFromActiveSection();
            ContextualCommandViewModel bindCmd = projectVM.Commands.First(x => x.InternalRealCommand.Equals(section.BindCommand));

            // Case 1: Bound
            projectVM.IsBound = true;
            // Act + Assert
            bindCmd.DisplayText.Should().Be(Strings.SyncButtonText, "Unexpected disabled context command text");

            // Case 2: Not bound
            projectVM.IsBound = false;

            // Act + Assert
            bindCmd.DisplayText.Should().Be(Strings.BindButtonText, "Unexpected context command text");
        }
        public void StateManager_SyncCommandFromActiveSection()
        {
            // Arrange
            var section                  = ConfigurableSectionController.CreateDefault();
            ConfigurableHost host        = new ConfigurableHost();
            StateManager     testSubject = this.CreateTestSubject(host, section);
            var connection1              = new ConnectionInformation(new Uri("http://127.0.0.1"));
            var projects                 = new SonarQubeProject[] { new SonarQubeProject("", ""), new SonarQubeProject("", "") };

            testSubject.SetProjects(connection1, projects);
            ServerViewModel serverVM = testSubject.ManagedState.ConnectedServers.Single();

            // Case 1: has active section
            host.SetActiveSection(section);

            // Act
            testSubject.SyncCommandFromActiveSection();
            VerifySectionCommands(section, serverVM);

            // Case 2: has no active section
            host.ClearActiveSection();

            // Act
            testSubject.SyncCommandFromActiveSection();
            VerifyNoCommands(serverVM);

            // Case 3: re-active
            host.SetActiveSection(section);

            // Act
            testSubject.SyncCommandFromActiveSection();
            VerifySectionCommands(section, serverVM);
        }
Пример #19
0
        public void VsSessionHost_ResetBinding_BoundSolutionWithActiveSectionScenario()
        {
            // Arrange
            var tracker     = new ConfigurableActiveSolutionTracker();
            var testSubject = this.CreateTestSubject(tracker);

            this.stateManager.SetBoundProject(new Uri("http://bound"), "org1", "bla");
            SetConfiguration(new BoundSonarQubeProject(new Uri("http://bound"), "bla", "projectName"), SonarLintMode.LegacyConnected);
            var  section       = ConfigurableSectionController.CreateDefault();
            bool refreshCalled = false;

            section.RefreshCommand = new RelayCommand <ConnectionInformation>(c => refreshCalled = true);
            testSubject.SetActiveSection(section);

            // Sanity
            this.stateManager.AssignedProjectKey.Should().Be("bla");
            this.stepRunner.AbortAllNumberOfCalls.Should().Be(0);

            // Act (simulate solution opened event)
            tracker.SimulateActiveSolutionChanged(isSolutionOpen: true);

            // Assert
            this.stepRunner.AbortAllNumberOfCalls.Should().Be(1);
            this.stateManager.BoundProjectKey.Should().Be("bla", "Key was not set, will not be able to mark project as bound after refresh");
            this.stateManager.AssignedProjectKey.Should().Be("bla");
            refreshCalled.Should().BeTrue("Expected the refresh command to be called");
        }
Пример #20
0
        public void ConnectionController_ShowNuGetWarning()
        {
            // Arrange
            ConnectionController testSubject = new ConnectionController(this.host, this.connectionProvider,
                                                                        this.connectionWorkflowMock.Object);

            this.host.SetActiveSection(ConfigurableSectionController.CreateDefault());
            ConfigurableUserNotification notifications = (ConfigurableUserNotification)this.host.ActiveSection.UserNotifications;

            this.connectionProvider.ConnectionInformationToReturn = null;
            var progressEvents = new ConfigurableProgressEvents();

            // Case 1: do NOT show
            // Arrange
            this.settings.ShowServerNuGetTrustWarning = false;

            // Act
            testSubject.SetConnectionInProgress(progressEvents);
            progressEvents.SimulateFinished(ProgressControllerResult.Succeeded);

            // Assert
            notifications.AssertNoNotification(NotificationIds.WarnServerTrustId);

            // Case 2: show, but canceled
            // Arrange
            this.settings.ShowServerNuGetTrustWarning = false;

            // Act
            testSubject.SetConnectionInProgress(progressEvents);
            progressEvents.SimulateFinished(ProgressControllerResult.Cancelled);

            // Assert
            notifications.AssertNoNotification(NotificationIds.WarnServerTrustId);

            // Case 3: show, but failed
            // Arrange
            this.settings.ShowServerNuGetTrustWarning = false;

            // Act
            testSubject.SetConnectionInProgress(progressEvents);
            progressEvents.SimulateFinished(ProgressControllerResult.Failed);

            // Assert
            notifications.AssertNoNotification(NotificationIds.WarnServerTrustId);

            // Test Case 4: show, succeeded
            // Arrange
            this.settings.ShowServerNuGetTrustWarning = true;

            // Act
            testSubject.SetConnectionInProgress(progressEvents);
            progressEvents.SimulateFinished(ProgressControllerResult.Succeeded);

            // Assert
            notifications.AssertNotification(NotificationIds.WarnServerTrustId, Strings.ServerNuGetTrustWarningMessage);
        }
        private StateManager CreateTestSubject(ConfigurableHost host, ConfigurableSectionController section = null)
        {
            var testSubject = new StateManager(host, new TransferableVisualState());

            if (section != null)
            {
                section.ViewModel.State = testSubject.ManagedState;
            }

            return(testSubject);
        }
        public void VsSessionHost_SetActiveSection_TransferState()
        {
            // Setup
            VsSessionHost      testSubject = this.CreateTestSubject(null);
            ISectionController section     = ConfigurableSectionController.CreateDefault();

            // Act
            testSubject.SetActiveSection(section);

            // Verify
            Assert.AreSame(stateManager.ManagedState, testSubject.ActiveSection.ViewModel.State);
        }
Пример #23
0
        public void VsSessionHost_SetActiveSection_TransferState()
        {
            // Arrange
            VsSessionHost      testSubject = this.CreateTestSubject(null);
            ISectionController section     = ConfigurableSectionController.CreateDefault();

            // Act
            testSubject.SetActiveSection(section);

            // Assert
            testSubject.ActiveSection.ViewModel.State.Should().Be(stateManager.ManagedState);
        }
Пример #24
0
        public void ConnectionController_DontWarnAgainCommand_Status()
        {
            // Arrange
            var testSubject = new ConnectionController(this.host);

            this.host.SetActiveSection(ConfigurableSectionController.CreateDefault());
            this.settings.ShowServerNuGetTrustWarning = true;
            this.host.ActiveSection.UserNotifications.ShowNotificationWarning("myMessage", NotificationIds.WarnServerTrustId, new RelayCommand(() => { }));

            // Act + Assert
            testSubject.DontWarnAgainCommand.CanExecute().Should().BeTrue();
        }
Пример #25
0
        public void ConnectionController_DontWarnAgainCommand_Status_NoIIntegrationSettings()
        {
            // Arrange
            this.serviceProvider.RegisterService(typeof(SComponentModel), new ConfigurableComponentModel(), replaceExisting: true);
            var testSubject = new ConnectionController(this.host);

            this.host.SetActiveSection(ConfigurableSectionController.CreateDefault());
            this.settings.ShowServerNuGetTrustWarning = true;
            this.host.ActiveSection.UserNotifications.ShowNotificationWarning("myMessage", NotificationIds.WarnServerTrustId, new RelayCommand(() => { }));

            // Act + Assert
            testSubject.DontWarnAgainCommand.CanExecute().Should().BeFalse();
        }
        public void VsSessionHost_ClearActiveSection_ClearState()
        {
            // Setup
            VsSessionHost      testSubject = this.CreateTestSubject(null);
            ISectionController section     = ConfigurableSectionController.CreateDefault();

            testSubject.SetActiveSection(section);

            // Act
            testSubject.ClearActiveSection();

            // Verify
            Assert.IsNull(testSubject.ActiveSection);
            Assert.IsNull(section.ViewModel.State);
        }
        public void VsSessionHost_SetActiveSection_ChangeHost()
        {
            // Setup
            VsSessionHost      testSubject = this.CreateTestSubject(null);
            ISectionController section     = ConfigurableSectionController.CreateDefault();

            // Sanity
            this.stepRunner.AssertNoCurrentHost();

            // Act
            testSubject.SetActiveSection(section);

            // Verify
            this.stepRunner.AssertCurrentHost(section.ProgressHost);
        }
Пример #28
0
        public void VsSessionHost_ClearActiveSection_ClearState()
        {
            // Arrange
            VsSessionHost      testSubject = this.CreateTestSubject(null);
            ISectionController section     = ConfigurableSectionController.CreateDefault();

            testSubject.SetActiveSection(section);

            // Act
            testSubject.ClearActiveSection();

            // Assert
            testSubject.ActiveSection.Should().BeNull();
            section.ViewModel.State.Should().BeNull();
        }
Пример #29
0
        public void VsSessionHost_SetActiveSection_ChangeHost()
        {
            // Arrange
            VsSessionHost      testSubject = this.CreateTestSubject(null);
            ISectionController section     = ConfigurableSectionController.CreateDefault();

            // Sanity
            this.stepRunner.CurrentHost.Should().BeNull();

            // Act
            testSubject.SetActiveSection(section);

            // Assert
            this.stepRunner.CurrentHost.Should().Be(section.ProgressHost);
        }
Пример #30
0
        private BindingController PrepareCommandForExecution()
        {
            this.host.TestStateManager.IsConnected = true;
            BindingController testSubject = this.CreateBindingController();

            this.host.SetActiveSection(ConfigurableSectionController.CreateDefault());
            this.monitorSelection.SetContext(VSConstants.UICONTEXT.SolutionExistsAndFullyLoaded_guid, true);
            this.monitorSelection.SetContext(VSConstants.UICONTEXT.SolutionExistsAndNotBuildingAndNotDebugging_guid, true);
            ProjectMock project1 = this.solutionMock.AddOrGetProject("project1");

            this.projectSystemHelper.Projects = new[] { project1 };

            // Sanity
            testSubject.BindCommand.CanExecute(CreateBindingArguments("project1", "name1", "http://localhost")).Should().BeTrue("All the requirement should be satisfied for the command to be enabled");

            return(testSubject);
        }
        private StateManager CreateTestSubject(ConfigurableHost host, ConfigurableSectionController section = null)
        {
            var testSubject = new StateManager(host, new TransferableVisualState());

            if (section != null)
            {
                section.ViewModel.State = testSubject.ManagedState;
            }

            return testSubject;
        }