-
Notifications
You must be signed in to change notification settings - Fork 77
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
georgii-borovinskikh-sonarsource
merged 12 commits into
feature/sloop-rule-meta-data
from
ue/bindingToDto
Feb 21, 2024
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
4c23b49
package changes
ugras-ergun-sonarsource d6e66d8
implemented
ugras-ergun-sonarsource 8760549
fixed issues
ugras-ergun-sonarsource ce6fc35
remove redundant cast
ugras-ergun-sonarsource 2760643
removed caching
ugras-ergun-sonarsource 2b817f9
cosmetic changes also realised no need to check null == null
ugras-ergun-sonarsource ba91423
added null check
ugras-ergun-sonarsource 562d55a
changed to OR
ugras-ergun-sonarsource 9c80ba1
equals
ugras-ergun-sonarsource 8229d0a
Added MEF tests
ugras-ergun-sonarsource 22fbcef
merge
ugras-ergun-sonarsource 3e2947f
removed generics
ugras-ergun-sonarsource File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 0 additions & 133 deletions
133
src/ConnectedMode.UnitTests/Binding/BindingInfoProviderTests.cs
This file was deleted.
Oops, something went wrong.
168 changes: 168 additions & 0 deletions
168
src/ConnectedMode.UnitTests/Binding/ServerConnectionConfigurationProviderTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ | ||
[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 }; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing MEF tests