Skip to content

Commit

Permalink
Upd
Browse files Browse the repository at this point in the history
  • Loading branch information
georgii-borovinskikh-sonarsource committed Aug 30, 2024
1 parent 1ee12ee commit ef6696b
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 57 deletions.
44 changes: 0 additions & 44 deletions src/ConnectedMode.UnitTests/Binding/BindingProcessImplTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,50 +171,6 @@ public async Task DownloadQualityProfile_CreatesBoundProjectAndCallsQPDownloader
actualProject.ServerProjectKey.Should().Be("the project key");
}

[TestMethod]
[DataRow("the user name", null)]
[DataRow("the user name", "a password")]
[DataRow(null, null)]
[DataRow(null, "should be ignored")]
public async Task DownloadQualityProfile_HandlesBoundProjectCredentialsCorrectly(string userName, string rawPassword)
{
// todo move test to Unintrusive controller
// var qpDownloader = new Mock<IQualityProfileDownloader>();
// var password = rawPassword == null ? null : rawPassword.ToSecureString();
//
// var connectionInfo = new Conne ctionInformation(new Uri("http://any"), userName, password);
// var bindingArgs = CreateBindCommandArgs();
//
// var testSubject = CreateTestSubject(bindingArgs,
// qpDownloader: qpDownloader.Object);
//
// // Act
// var result = await testSubject.DownloadQualityProfileAsync(Mock.Of<IProgress<FixedStepsProgress>>(), CancellationToken.None);
//
// result.Should().BeTrue();
//
// qpDownloader.Verify(x => x.UpdateAsync(It.IsAny<BoundServerProject>(),
// It.IsAny<IProgress<FixedStepsProgress>>(),
// It.IsAny<CancellationToken>()),
// Times.Once);
//
// var actualProject = (BoundSonarQubeProject)qpDownloader.Invocations[0].Arguments[0];
//
// // Check the credentials were handled correctly
// if (userName == null)
// {
// actualProject.Credentials.Should().BeNull();
// }
// else
// {
// actualProject.Credentials.Should().BeOfType<BasicAuthCredentials>();
// var actualCreds = (BasicAuthCredentials)actualProject.Credentials;
//
// actualCreds.UserName.Should().Be(userName);
// CheckIsExpectedPassword(rawPassword, actualCreds.Password);
// }
}

[TestMethod]
public async Task DownloadQualityProfile_HandlesInvalidOperationException()
{
Expand Down
2 changes: 2 additions & 0 deletions src/ConnectedMode/Persistence/ConnectionInfoConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

using System.Diagnostics.CodeAnalysis;
using SonarLint.VisualStudio.Core.Binding;
using SonarQube.Client.Models;

namespace SonarLint.VisualStudio.ConnectedMode.Persistence;

public static class ConnectionInfoConverter
{
[ExcludeFromCodeCoverage]
public static ServerConnection ToServerConnection(this ConnectionInformation connectionInformation) =>
connectionInformation switch
{
Expand Down
67 changes: 54 additions & 13 deletions src/Core.UnitTests/Binding/ServerConnectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@
*/

using SonarLint.VisualStudio.Core.Binding;
using SonarQube.Client.Models;
using ICredentials = SonarLint.VisualStudio.Core.Binding.ICredentials;

namespace SonarLint.VisualStudio.Core.UnitTests.Binding;

[TestClass]
public class ServerConnectionTests
{
private static readonly Uri localhost = new Uri("http://localhost:5000");
private static readonly string org = "myOrg";
private static readonly Uri Localhost = new Uri("http://localhost:5000");
private const string Org = "myOrg";

[TestMethod]
public void Ctor_SonarCloud_NullOrganization_Throws()
{
Expand All @@ -40,15 +41,15 @@ public void Ctor_SonarCloud_NullOrganization_Throws()
[TestMethod]
public void Ctor_SonarCloud_NullSettings_SetDefault()
{
var sonarCloud = new ServerConnection.SonarCloud(org, null);
var sonarCloud = new ServerConnection.SonarCloud(Org, null);

sonarCloud.Settings.Should().BeSameAs(ServerConnection.DefaultSettings);
}

[TestMethod]
public void Ctor_SonarCloud_NullCredentials_SetsNull()
{
var sonarCloud = new ServerConnection.SonarCloud(org, credentials: null);
var sonarCloud = new ServerConnection.SonarCloud(Org, credentials: null);

sonarCloud.Credentials.Should().BeNull();
}
Expand All @@ -58,10 +59,10 @@ public void Ctor_SonarCloud_SetsProperties()
{
var serverConnectionSettings = new ServerConnectionSettings(false);
var credentials = Substitute.For<ICredentials>();
var sonarCloud = new ServerConnection.SonarCloud(org, serverConnectionSettings, credentials);
var sonarCloud = new ServerConnection.SonarCloud(Org, serverConnectionSettings, credentials);

sonarCloud.Id.Should().BeSameAs(org);
sonarCloud.OrganizationKey.Should().BeSameAs(org);
sonarCloud.Id.Should().BeSameAs(Org);
sonarCloud.OrganizationKey.Should().BeSameAs(Org);
sonarCloud.ServerUri.Should().Be(new Uri("https://sonarcloud.io"));
sonarCloud.Settings.Should().BeSameAs(serverConnectionSettings);
sonarCloud.Credentials.Should().BeSameAs(credentials);
Expand All @@ -78,15 +79,15 @@ public void Ctor_SonarQube_NullUri_Throws()
[TestMethod]
public void Ctor_SonarQube_NullSettings_SetDefault()
{
var sonarQube = new ServerConnection.SonarQube(localhost, null);
var sonarQube = new ServerConnection.SonarQube(Localhost, null);

sonarQube.Settings.Should().BeSameAs(ServerConnection.DefaultSettings);
}

[TestMethod]
public void Ctor_SonarQube_NullCredentials_SetsNull()
{
var sonarQube = new ServerConnection.SonarQube(localhost, credentials: null);
var sonarQube = new ServerConnection.SonarQube(Localhost, credentials: null);

sonarQube.Credentials.Should().BeNull();
}
Expand All @@ -96,11 +97,51 @@ public void Ctor_SonarQube_SetsProperties()
{
var serverConnectionSettings = new ServerConnectionSettings(false);
var credentials = Substitute.For<ICredentials>();
var sonarQube = new ServerConnection.SonarQube(localhost, serverConnectionSettings, credentials);
var sonarQube = new ServerConnection.SonarQube(Localhost, serverConnectionSettings, credentials);

sonarQube.Id.Should().Be(localhost.ToString());
sonarQube.ServerUri.Should().BeSameAs(localhost);
sonarQube.Id.Should().Be(Localhost.ToString());
sonarQube.ServerUri.Should().BeSameAs(Localhost);
sonarQube.Settings.Should().BeSameAs(serverConnectionSettings);
sonarQube.Credentials.Should().BeSameAs(credentials);
}

[TestMethod]
public void FromBoundSonarQubeProject_SonarQubeConnection_ConvertedCorrectly()
{
var credentials = Substitute.For<ICredentials>();
var expectedConnection = new ServerConnection.SonarQube(Localhost, credentials: credentials);

var connection = ServerConnection.FromBoundSonarQubeProject(new BoundSonarQubeProject(Localhost, "any", "any", credentials));

connection.Should().BeEquivalentTo(expectedConnection, options => options.ComparingByMembers<ServerConnection>());
}

[TestMethod]
public void FromBoundSonarQubeProject_SonarCloudConnection_ConvertedCorrectly()
{
var uri = new Uri("https://sonarcloud.io");
var organization = "org";
var credentials = Substitute.For<ICredentials>();
var expectedConnection = new ServerConnection.SonarCloud(organization, credentials: credentials);

var connection = ServerConnection.FromBoundSonarQubeProject(new BoundSonarQubeProject(uri, "any", "any", credentials, new SonarQubeOrganization(organization, null)));

connection.Should().BeEquivalentTo(expectedConnection, options => options.ComparingByMembers<ServerConnection>());
}

[TestMethod]
public void FromBoundSonarQubeProject_InvalidConnection_ReturnsNull()
{
var connection = ServerConnection.FromBoundSonarQubeProject(new BoundSonarQubeProject(){ ProjectKey = "project"});

connection.Should().BeNull();
}

[TestMethod]
public void FromBoundSonarQubeProject_NullConnection_ReturnsNull()
{
var connection = ServerConnection.FromBoundSonarQubeProject(null);

connection.Should().BeNull();
}
}
2 changes: 2 additions & 0 deletions src/Integration/Binding/BindingController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Microsoft.VisualStudio.OLE.Interop;
using SonarLint.VisualStudio.ConnectedMode.Binding;
Expand All @@ -36,6 +37,7 @@ namespace SonarLint.VisualStudio.Integration.Binding
/// <summary>
/// A dedicated controller for the <see cref="BindCommand"/>
/// </summary>
[ExcludeFromCodeCoverage] // todo https://sonarsource.atlassian.net/browse/SLVS-1408
internal class BindingController : HostedCommandControllerBase, IBindingWorkflowExecutor
{
private readonly System.IServiceProvider serviceProvider;
Expand Down
2 changes: 2 additions & 0 deletions src/Integration/WPF/ProjectViewModelToBindingArgsConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/

using System;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Windows.Data;
using SonarLint.VisualStudio.ConnectedMode.Binding;
Expand All @@ -28,6 +29,7 @@

namespace SonarLint.VisualStudio.Integration.WPF
{
[ExcludeFromCodeCoverage] // todo https://sonarsource.atlassian.net/browse/SLVS-1408
[ValueConversion(typeof(ProjectViewModel), typeof(BindCommandArgs))]
public class ProjectViewModelToBindingArgsConverter : IValueConverter
{
Expand Down

0 comments on commit ef6696b

Please sign in to comment.