Exemple #1
0
        public void TestInit()
        {
            this.sonarQubeServiceMock   = new Mock <ISonarQubeService>();
            this.connectionWorkflowMock = new Mock <IConnectionWorkflowExecutor>();
            this.connectionProvider     = new ConfigurableConnectionInformationProvider();
            this.serviceProvider        = new ConfigurableServiceProvider();
            var outputWindow = new ConfigurableVsOutputWindow();

            this.outputWindowPane = outputWindow.GetOrCreateSonarLintPane();
            this.serviceProvider.RegisterService(typeof(SVsOutputWindow), outputWindow);
            this.settings            = new ConfigurableSonarLintSettings();
            this.projectSystemHelper = new ConfigurableVsProjectSystemHelper(this.serviceProvider);
            this.host = new ConfigurableHost(this.serviceProvider, Dispatcher.CurrentDispatcher);
            this.host.SonarQubeService = this.sonarQubeServiceMock.Object;

            IComponentModel componentModel = ConfigurableComponentModel.CreateWithExports(
                new []
            {
                MefTestHelpers.CreateExport <ITelemetryLogger>(new ConfigurableTelemetryLogger()),
                MefTestHelpers.CreateExport <ISonarLintSettings>(settings)
            });

            this.serviceProvider.RegisterService(typeof(SComponentModel), componentModel);
            this.serviceProvider.RegisterService(typeof(IProjectSystemHelper), projectSystemHelper);
        }
        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);
        }
        public void OnApply_Save_SettingsAreUpdated()
        {
            var settings = new ConfigurableSonarLintSettings()
            {
                DaemonLogLevel         = DaemonLogLevel.Verbose,
                IsActivateMoreEnabled  = true,
                SkipActivateMoreDialog = true
            };

            var daemonMock    = new Mock <ISonarLintDaemon>();
            var installerMock = new Mock <IDaemonInstaller>();

            GeneralOptionsDialogPageTestable page = new GeneralOptionsDialogPageTestable();

            ConfigureSiteMock(page, settings, daemonMock.Object, installerMock.Object);
            page.ActivateAccessor();

            page.Control.DaemonVerbosity.SelectedItem = DaemonLogLevel.Minimal;

            // Act
            page.ApplyAccessor(Microsoft.VisualStudio.Shell.DialogPage.ApplyKind.Apply);

            // Assert
            settings.DaemonLogLevel.Should().Be(DaemonLogLevel.Minimal);
        }
        public void OnActivate_WhenDaemonIsInstalled_ControlsAreConfiguredFromSettings1()
        {
            // Daemon is installed so the settings as supplied should be used
            var settings = new ConfigurableSonarLintSettings
            {
                DaemonLogLevel         = DaemonLogLevel.Verbose,
                IsActivateMoreEnabled  = true,
                SkipActivateMoreDialog = true
            };

            var daemonMock    = new Mock <ISonarLintDaemon>();
            var installerMock = new Mock <IDaemonInstaller>();

            installerMock.Setup <bool>(x => x.IsInstalled()).Returns(true);

            GeneralOptionsDialogPageTestable page = new GeneralOptionsDialogPageTestable();

            ConfigureSiteMock(page, settings, daemonMock.Object, installerMock.Object);

            // Act
            page.ActivateAccessor();

            // Assert
            page.Control.Should().NotBeNull();
            page.Control.DaemonVerbosity.SelectedItem.Should().Be(DaemonLogLevel.Verbose);

            // Daemon is activate, so deactivate options should be visible
            page.Control.DeactivateButton.Visibility.Should().Be(Visibility.Visible);
            page.Control.DeactivateText.Visibility.Should().Be(Visibility.Visible);
            page.Control.VerbosityPanel.Visibility.Should().Be(Visibility.Visible);

            // ... and active options should not
            page.Control.ActivateButton.Visibility.Should().Be(Visibility.Collapsed);
            page.Control.ActivateText.Visibility.Should().Be(Visibility.Collapsed);
        }
Exemple #5
0
        public void OnActivate_ControlsAreConfigured()
        {
            var settings = new ConfigurableSonarLintSettings
            {
                DaemonLogLevel        = DaemonLogLevel.Verbose,
                IsActivateMoreEnabled = true,
            };

            GeneralOptionsDialogPageTestable page = new GeneralOptionsDialogPageTestable();

            ConfigureSiteMock(page, settings);

            // Act
            page.ActivateAccessor();

            // Assert
            page.Control.Should().NotBeNull();
            page.Control.DaemonVerbosity.SelectedItem.Should().Be(DaemonLogLevel.Verbose);
            page.Control.VerbosityPanel.Visibility.Should().Be(Visibility.Visible);
        }
Exemple #6
0
        public void OnApply_Cancel_SettingsAreNotUpdated()
        {
            var settings = new ConfigurableSonarLintSettings()
            {
                DaemonLogLevel        = DaemonLogLevel.Verbose,
                IsActivateMoreEnabled = true,
            };

            GeneralOptionsDialogPageTestable page = new GeneralOptionsDialogPageTestable();

            ConfigureSiteMock(page, settings);
            page.ActivateAccessor();

            page.Control.DaemonVerbosity.SelectedItem = DaemonLogLevel.Minimal;

            // Act
            page.ApplyAccessor(Microsoft.VisualStudio.Shell.DialogPage.ApplyKind.Cancel);

            // Assert
            settings.DaemonLogLevel.Should().Be(DaemonLogLevel.Verbose);
        }
Exemple #7
0
        public void OnActivate_ControlsAreConfiguredFromSettings2()
        {
            var settings = new ConfigurableSonarLintSettings
            {
                DaemonLogLevel         = DaemonLogLevel.Info,
                IsActivateMoreEnabled  = true,
                SkipActivateMoreDialog = true
            };

            var daemonMock = new Mock <ISonarLintDaemon>();

            GeneralOptionsDialogPageTestable page = new GeneralOptionsDialogPageTestable();

            ConfigureSiteMock(page, settings, daemonMock.Object);

            // Act
            page.ActivateAccessor();

            // Assert
            page.Control.Should().NotBeNull();
            page.Control.DaemonVerbosity.SelectedItem.Should().Be(DaemonLogLevel.Info);
        }
Exemple #8
0
        public void OnActivate_WhenDaemonIsNotInstalled_ControlsAreConfiguredForActivation()
        {
            // Daemon is not installed so the control should be set up so the user
            // can "Activate"
            var settings = new ConfigurableSonarLintSettings
            {
                DaemonLogLevel         = DaemonLogLevel.Verbose,
                IsActivateMoreEnabled  = true,
                SkipActivateMoreDialog = true
            };

            var daemonMock = new Mock <ISonarLintDaemon>();

            daemonMock.SetupGet <bool>(x => x.IsInstalled).Returns(false);

            GeneralOptionsDialogPageTestable page = new GeneralOptionsDialogPageTestable();

            ConfigureSiteMock(page, settings, daemonMock.Object);

            // Act
            page.ActivateAccessor();

            // Assert
            page.Control.Should().NotBeNull();
            page.Control.DaemonVerbosity.SelectedItem.Should().Be(DaemonLogLevel.Verbose);

            // Daemon is not installed, so deactivate options should not be visible
            page.Control.DeactivateButton.Visibility.Should().Be(Visibility.Collapsed);
            page.Control.DeactivateText.Visibility.Should().Be(Visibility.Collapsed);
            page.Control.VerbosityPanel.Visibility.Should().Be(Visibility.Collapsed);

            // ... and activate options should be visible
            page.Control.ActivateButton.Visibility.Should().Be(Visibility.Visible);
            page.Control.ActivateText.Visibility.Should().Be(Visibility.Visible);
            page.Control.ShowAdditionalLanguageDownloadDialogue.IsChecked.Should().BeFalse();
            page.Control.ShowAdditionalLanguageDownloadText.Visibility.Should().Be(Visibility.Visible);
        }
        public void OnActivate_WhenDaemonIsNotInstalled_ControlsAreConfiguredForActivation()
        {
            // Daemon is not installed. However, that should not affect the activation
            // status of the controls.
            var settings = new ConfigurableSonarLintSettings
            {
                DaemonLogLevel         = DaemonLogLevel.Verbose,
                IsActivateMoreEnabled  = true,
                SkipActivateMoreDialog = true
            };

            var daemonMock    = new Mock <ISonarLintDaemon>();
            var installerMock = new Mock <IDaemonInstaller>();

            installerMock.Setup <bool>(x => x.IsInstalled()).Returns(false);

            GeneralOptionsDialogPageTestable page = new GeneralOptionsDialogPageTestable();

            ConfigureSiteMock(page, settings, daemonMock.Object, installerMock.Object);

            // Act
            page.ActivateAccessor();

            // Assert
            page.Control.Should().NotBeNull();
            page.Control.DaemonVerbosity.SelectedItem.Should().Be(DaemonLogLevel.Verbose);

            // User has enabled activation; the activation status of the daemon should be irrelevant
            page.Control.DeactivateButton.Visibility.Should().Be(Visibility.Visible);
            page.Control.DeactivateText.Visibility.Should().Be(Visibility.Visible);
            page.Control.VerbosityPanel.Visibility.Should().Be(Visibility.Visible);

            // ... and activate options should be visible
            page.Control.ActivateButton.Visibility.Should().Be(Visibility.Collapsed);
            page.Control.ActivateText.Visibility.Should().Be(Visibility.Collapsed);
        }