Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert Binding to SLOOP Dto #5237

Merged
1 change: 1 addition & 0 deletions src/CFamily.UnitTests/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -1588,6 +1588,7 @@
"Newtonsoft.Json": "[13.0.3, )",
"SonarLint.VisualStudio.Core": "[1.0.0, )",
"SonarLint.VisualStudio.IssueVisualization": "[1.0.0, )",
"SonarLint.VisualStudio.SLCore": "[1.0.0, )",
"StrongNamer": "[0.0.8, )"
}
},
Expand Down
8 changes: 8 additions & 0 deletions src/CloudSecrets.UnitTests/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -1525,6 +1525,7 @@
"Newtonsoft.Json": "[13.0.3, )",
"SonarLint.VisualStudio.Core": "[1.0.0, )",
"SonarLint.VisualStudio.IssueVisualization": "[1.0.0, )",
"SonarLint.VisualStudio.SLCore": "[1.0.0, )",
"StrongNamer": "[0.0.8, )"
}
},
Expand Down Expand Up @@ -1603,6 +1604,13 @@
"SonarLint.VisualStudio.Progress": "[1.0.0, )"
}
},
"SonarLint.VisualStudio.SLCore": {
"type": "Project",
"dependencies": {
"SonarLint.VisualStudio.Core": "[1.0.0, )",
"StreamJsonRpc": "[2.5.46, )"
}
},
"sonarqube.client": {
"type": "Project",
"dependencies": {
Expand Down
133 changes: 0 additions & 133 deletions src/ConnectedMode.UnitTests/Binding/BindingInfoProviderTests.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
/*
* SonarLint for Visual Studio
* Copyright (C) 2016-2024 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

using System;
using System.Linq;
using SonarLint.VisualStudio.ConnectedMode.Binding;
using SonarLint.VisualStudio.ConnectedMode.Persistence;
using SonarLint.VisualStudio.Core;
using SonarLint.VisualStudio.Core.Binding;
using SonarLint.VisualStudio.SLCore.Common.Helpers;
using SonarLint.VisualStudio.SLCore.Service.Connection.Models;
using SonarLint.VisualStudio.TestInfrastructure;
using SonarQube.Client.Models;

namespace SonarLint.VisualStudio.ConnectedMode.UnitTests.Binding
{
[TestClass]
public class ServerConnectionConfigurationProviderTests

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing MEF tests

{
[TestMethod]
public void MefCtor_CheckIsExported()
{
MefTestHelpers.CheckTypeCanBeImported<ServerConnectionConfigurationProvider, IServerConnectionConfigurationProvider>(
MefTestHelpers.CreateExport<ISolutionBindingRepository>());
}

[TestMethod]
public void MefCtor_CheckIsSingleton()
{
MefTestHelpers.CheckIsSingletonMefComponent<ServerConnectionConfigurationProvider>();
}

[TestMethod]
public void GetServerConnectionConfiguration_ConvertsSQBindindCorrectly()
{
var project = CreateBoundSonarQubeProject("http://someuri.com");

var solutionBindingRepository = CreateRepository(project);

var testSubject = CreateTestSubject(solutionBindingRepository.Object);

var bindings = testSubject.GetServerConnectionConfiguration().OfType<SonarQubeConnectionConfigurationDto>().ToList();

bindings.Should().HaveCount(1);
bindings[0].connectionId.Should().Be("sq|http://someuri.com/");
bindings[0].serverUrl.Should().Be("http://someuri.com/");
bindings[0].disableNotification.Should().BeTrue();
}

[TestMethod]
public void GetServerConnectionConfiguration_ConvertsSCBindindCorrectly()
{
var project = CreateBoundSonarQubeProject("https://sonarcloud.io", "org");

var solutionBindingRepository = CreateRepository(project);

var testSubject = CreateTestSubject(solutionBindingRepository.Object);

var bindings = testSubject.GetServerConnectionConfiguration().OfType<SonarCloudConnectionConfigurationDto>().ToList();

bindings.Should().HaveCount(1);
bindings[0].connectionId.Should().Be("sc|org");
bindings[0].organization.Should().Be("org");
bindings[0].disableNotification.Should().BeTrue();
}

[TestMethod]
public void GetServerConnectionConfiguration_HaveBothSQAndSC_ReturnsCorrectly()
{
var project1 = CreateBoundSonarQubeProject("http://someuri.com");
var project2 = CreateBoundSonarQubeProject("http://someuri2.com");
var project3 = CreateBoundSonarQubeProject("http://145.68.22.15:8964");
var project4 = CreateBoundSonarQubeProject("https://sonarcloud.io", "org1");

var solutionBindingRepository = CreateRepository(project1, project2, project3, project4);

var testSubject = CreateTestSubject(solutionBindingRepository.Object);

var sqBindings = testSubject.GetServerConnectionConfiguration().OfType<SonarQubeConnectionConfigurationDto>();
var scBindings = testSubject.GetServerConnectionConfiguration().OfType<SonarCloudConnectionConfigurationDto>();

sqBindings.Should().HaveCount(3);
scBindings.Should().HaveCount(1);
}

[TestMethod]
public void GetServerConnectionConfiguration_HaveMultipleBindingWithSameUri_Aggregates()
{
var project1 = CreateBoundSonarQubeProject("http://someuri.com");
var project2 = CreateBoundSonarQubeProject("http://someuri.com");
var project3 = CreateBoundSonarQubeProject("http://145.68.22.15:8964");
var project4 = CreateBoundSonarQubeProject("https://sonarcloud.io", "org1");
var project5 = CreateBoundSonarQubeProject("https://sonarcloud.io", "org2");

var solutionBindingRepository = CreateRepository(project1, project2, project3, project4, project5);

var testSubject = CreateTestSubject(solutionBindingRepository.Object);

var sqBindings = testSubject.GetServerConnectionConfiguration().OfType<SonarQubeConnectionConfigurationDto>();
var scBindings = testSubject.GetServerConnectionConfiguration().OfType<SonarCloudConnectionConfigurationDto>();

sqBindings.Should().HaveCount(2);
scBindings.Should().HaveCount(1);
}

[TestMethod]
public void GetServerConnectionConfiguration_ThrowsOnUIThread()
{
var threadHandling = new Mock<IThreadHandling>();

var testSubject = CreateTestSubject(threadHandling: threadHandling.Object);

_ = testSubject.GetServerConnectionConfiguration();

threadHandling.Verify(th => th.ThrowIfOnUIThread(), Times.Once);
threadHandling.VerifyNoOtherCalls();
}

private static ServerConnectionConfigurationProvider CreateTestSubject(ISolutionBindingRepository solutionBindingRepository = null, IThreadHandling threadHandling = null)
{
solutionBindingRepository ??= CreateRepository().Object;
threadHandling ??= Mock.Of<IThreadHandling>();
var connectionIdHelper = CreateConnectionIdHelper().Object;

return new ServerConnectionConfigurationProvider(solutionBindingRepository, threadHandling, connectionIdHelper);
}

private static Mock<ISolutionBindingRepository> CreateRepository(params BoundSonarQubeProject[] projects)
{
var solutionBindingRepository = new Mock<ISolutionBindingRepository>();
solutionBindingRepository.Setup(sbr => sbr.List()).Returns(projects);
return solutionBindingRepository;
}

private static Mock<IConnectionIdHelper> CreateConnectionIdHelper()
{
var connectionIdHelper = new Mock<IConnectionIdHelper>();
connectionIdHelper.Setup(c => c.GetConnectionIdFromUri(It.IsAny<Uri>(), It.IsAny<string>())).Returns((Uri uri, string organization) => new ConnectionIdHelper().GetConnectionIdFromUri(uri, organization));
return connectionIdHelper;
}

private BoundSonarQubeProject CreateBoundSonarQubeProject(string serverUriString, string organisationKey = null)
{
var serverUri = new Uri(serverUriString);
//To make sure if the organisation is null program do not break
var organization = organisationKey is not null ? new SonarQubeOrganization(organisationKey, null) : null;

return new BoundSonarQubeProject { ServerUri = serverUri, Organization = organization };
}
}
}
8 changes: 8 additions & 0 deletions src/ConnectedMode.UnitTests/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -1541,6 +1541,7 @@
"Newtonsoft.Json": "[13.0.3, )",
"SonarLint.VisualStudio.Core": "[1.0.0, )",
"SonarLint.VisualStudio.IssueVisualization": "[1.0.0, )",
"SonarLint.VisualStudio.SLCore": "[1.0.0, )",
"StrongNamer": "[0.0.8, )"
}
},
Expand Down Expand Up @@ -1619,6 +1620,13 @@
"SonarLint.VisualStudio.Progress": "[1.0.0, )"
}
},
"SonarLint.VisualStudio.SLCore": {
"type": "Project",
"dependencies": {
"SonarLint.VisualStudio.Core": "[1.0.0, )",
"StreamJsonRpc": "[2.5.46, )"
}
},
"sonarqube.client": {
"type": "Project",
"dependencies": {
Expand Down
Loading
Loading