示例#1
0
        public void CreateConnectionInformation_BasicAuthCredentials()
        {
            // Arrange
            var creds = new BasicAuthCredentials("UserName", "password".ToSecureString());
            var input = new BoundSonarQubeProject(new Uri("http://server"), "ProjectKey", "projectName", creds,
                                                  new SonarQubeOrganization("org_key", "org_name"));

            // Act
            ConnectionInformation conn = input.CreateConnectionInformation();

            // Assert
            conn.ServerUri.Should().Be(input.ServerUri);
            conn.UserName.Should().Be(creds.UserName);
            conn.Password.ToUnsecureString().Should().Be(creds.Password.ToUnsecureString());
            conn.Organization.Key.Should().Be("org_key");
            conn.Organization.Name.Should().Be("org_name");
        }
示例#2
0
        private void ApplyBindingInformation(BoundSonarQubeProject bound)
        {
            // Set the project key that should become bound once the connection workflow has completed
            this.VisualStateManager.BoundProjectKey = bound.ProjectKey;

            // Recreate the connection information from what was persisted
            ConnectionInformation connectionInformation = bound.CreateConnectionInformation();

            Debug.Assert(this.ActiveSection != null, "Expected ActiveSection to be set");
            Debug.Assert(this.ActiveSection?.RefreshCommand != null, "Refresh command is not set");
            // Run the refresh workflow, passing the connection information
            var refreshCmd = this.ActiveSection.RefreshCommand;

            if (refreshCmd.CanExecute(connectionInformation))
            {
                refreshCmd.Execute(connectionInformation); // start the workflow
            }
        }
示例#3
0
        private void ConfigureValidSonarQubeServiceWrapper(BoundSonarQubeProject binding, DateTime?timestamp, string qualityProfileKey, params Language[] expectedLanguageProfiles)
        {
            var sqService = new ConfigurableSonarQubeServiceWrapper();

            this.host.SonarQubeService = sqService;

            sqService.AllowConnections   = true;
            sqService.ExpectedConnection = binding.CreateConnectionInformation();
            sqService.ExpectedProjectKey = binding.ProjectKey;

            foreach (Language language in expectedLanguageProfiles)
            {
                sqService.ReturnProfile[language] = new QualityProfile
                {
                    Key      = qualityProfileKey,
                    Language = SonarQubeServiceWrapper.GetServerLanguageKey(language),
                    QualityProfileTimestamp = timestamp
                };
            }
        }
示例#4
0
            private bool IsUpdateRequired(BoundSonarQubeProject binding, IEnumerable <Language> projectLanguages, CancellationToken token)
            {
                Debug.Assert(binding != null);

                ConnectionInformation connection = binding.CreateConnectionInformation();
                Dictionary <Language, QualityProfile> newProfiles;

                if (!this.TryGetLatestProfiles(binding, projectLanguages, token, connection, out newProfiles))
                {
                    VsShellUtils.WriteToSonarLintOutputPane(this.host, Strings.SonarLintProfileCheckFailed);
                    return(false); // Error, can't proceed
                }

                if (!newProfiles.Keys.All(binding.Profiles.ContainsKey))
                {
                    VsShellUtils.WriteToSonarLintOutputPane(this.host, Strings.SonarLintProfileCheckSolutionRequiresMoreProfiles);
                    return(true); // Missing profile, refresh
                }

                foreach (var keyValue in binding.Profiles)
                {
                    Language language = keyValue.Key;
                    ApplicableQualityProfile oldProfileInfo = keyValue.Value;

                    if (!newProfiles.ContainsKey(language))
                    {
                        // Not a relevant profile, we should just ignore it.
                        continue;
                    }

                    QualityProfile newProfileInfo = newProfiles[language];
                    if (this.HasProfileChanged(newProfileInfo, oldProfileInfo))
                    {
                        return(true);
                    }
                }

                VsShellUtils.WriteToSonarLintOutputPane(this.host, Strings.SonarLintProfileCheckQualityProfileIsUpToDate);
                return(false); // Up-to-date
            }
            private void ExecuteBindCommand()
            {
                if (this.host.ActiveSection == null)
                {
                    this.OnFinished(BindingRequestResult.NoActiveSection);
                    return;
                }

                ProjectViewModel boundProject = this.FindProject(this.binding.ServerUri, binding.ProjectKey);

                if (boundProject == null)
                {
                    // The user change binding
                    this.OnFinished(BindingRequestResult.RequestIsIrrelevant);
                    return;
                }

                BindCommandArgs bindingArgs = new BindCommandArgs(boundProject.Project?.Key, boundProject.Project?.Name, binding.CreateConnectionInformation());

                if (this.host.ActiveSection.BindCommand.CanExecute(bindingArgs))
                {
                    this.host.ActiveSection.BindCommand.Execute(bindingArgs);
                    this.OnFinished(BindingRequestResult.StartedUpdating);
                }
                else
                {
                    this.OnFinished(BindingRequestResult.CommandIsBusy);
                }
            }