-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SLVS-1376 Binding Dialog: list connections (#5649)
[SLVS-1376](https://sonarsource.atlassian.net/browse/SLVS-1376) [SLVS-1376]: https://sonarsource.atlassian.net/browse/SLVS-1376?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
- Loading branch information
1 parent
8619648
commit acbc463
Showing
17 changed files
with
564 additions
and
91 deletions.
There are no files selected for viewing
125 changes: 125 additions & 0 deletions
125
src/ConnectedMode.UnitTests/ServerConnectionsRepositoryAdapterTests.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,125 @@ | ||
/* | ||
* 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 SonarLint.VisualStudio.Core; | ||
using SonarLint.VisualStudio.Core.Binding; | ||
using SonarLint.VisualStudio.TestInfrastructure; | ||
using static SonarLint.VisualStudio.Core.Binding.ServerConnection; | ||
|
||
namespace SonarLint.VisualStudio.ConnectedMode.UnitTests; | ||
|
||
[TestClass] | ||
public class ServerConnectionsRepositoryAdapterTests | ||
{ | ||
private IServerConnectionsRepository serverConnectionsRepository; | ||
private ServerConnectionsRepositoryAdapter testSubject; | ||
|
||
[TestInitialize] | ||
public void TestInitialize() | ||
{ | ||
serverConnectionsRepository = Substitute.For<IServerConnectionsRepository>(); | ||
testSubject = new ServerConnectionsRepositoryAdapter(serverConnectionsRepository); | ||
} | ||
|
||
[TestMethod] | ||
public void MefCtor_CheckIsExported() | ||
=> MefTestHelpers.CheckTypeCanBeImported<ServerConnectionsRepositoryAdapter, IServerConnectionsRepositoryAdapter>(MefTestHelpers.CreateExport<IServerConnectionsRepository>()); | ||
|
||
[TestMethod] | ||
public void GetAllConnections_CallServerConnectionsRepository() | ||
{ | ||
serverConnectionsRepository.GetAll().Returns([]); | ||
|
||
var connections = testSubject.GetAllConnections(); | ||
|
||
serverConnectionsRepository.Received(1).GetAll(); | ||
connections.Should().BeEmpty(); | ||
} | ||
|
||
[TestMethod] | ||
[DataRow(true)] | ||
[DataRow(false)] | ||
public void GetAllConnections_HasOneSonarCloudConnection_ReturnsOneMappedConnection(bool isSmartNotificationsEnabled) | ||
{ | ||
var sonarCloud = CreateSonarCloudServerConnection(isSmartNotificationsEnabled); | ||
serverConnectionsRepository.GetAll().Returns([sonarCloud]); | ||
|
||
var connections = testSubject.GetAllConnections(); | ||
|
||
connections.Should().BeEquivalentTo([new Connection(new ConnectionInfo(sonarCloud.Id, ConnectionServerType.SonarCloud), isSmartNotificationsEnabled)]); | ||
} | ||
|
||
[TestMethod] | ||
[DataRow(true)] | ||
[DataRow(false)] | ||
public void GetAllConnections_HasOneSonarQubeConnection_ReturnsOneMappedConnection(bool isSmartNotificationsEnabled) | ||
{ | ||
var sonarQube = CreateSonarQubeServerConnection(isSmartNotificationsEnabled); | ||
serverConnectionsRepository.GetAll().Returns([sonarQube]); | ||
|
||
var connections = testSubject.GetAllConnections(); | ||
|
||
connections.Should().BeEquivalentTo([new Connection(new ConnectionInfo(sonarQube.Id, ConnectionServerType.SonarQube), isSmartNotificationsEnabled)]); | ||
} | ||
|
||
[TestMethod] | ||
public void GetAllConnectionsInfo_CallServerConnectionsRepository() | ||
{ | ||
serverConnectionsRepository.GetAll().Returns([]); | ||
|
||
var connections = testSubject.GetAllConnectionsInfo(); | ||
|
||
serverConnectionsRepository.Received(1).GetAll(); | ||
connections.Should().BeEmpty(); | ||
} | ||
|
||
[TestMethod] | ||
public void GetAllConnectionsInfo_HasOneSonarCloudConnection_ReturnsOneMappedConnection() | ||
{ | ||
var sonarCloud = CreateSonarCloudServerConnection(); | ||
serverConnectionsRepository.GetAll().Returns([sonarCloud]); | ||
|
||
var connections = testSubject.GetAllConnectionsInfo(); | ||
|
||
connections.Should().BeEquivalentTo([new ConnectionInfo(sonarCloud.Id, ConnectionServerType.SonarCloud)]); | ||
} | ||
|
||
[TestMethod] | ||
public void GetAllConnectionsInfo_HasOneSonarQubeConnection_ReturnsOneMappedConnection() | ||
{ | ||
var sonarQube = CreateSonarQubeServerConnection(); | ||
serverConnectionsRepository.GetAll().Returns([sonarQube]); | ||
|
||
var connections = testSubject.GetAllConnectionsInfo(); | ||
|
||
connections.Should().BeEquivalentTo([new ConnectionInfo(sonarQube.Id, ConnectionServerType.SonarQube)]); | ||
} | ||
|
||
private static SonarCloud CreateSonarCloudServerConnection(bool isSmartNotificationsEnabled = true) | ||
{ | ||
return new SonarCloud("myOrg", new ServerConnectionSettings(isSmartNotificationsEnabled), Substitute.For<ICredentials>()); | ||
} | ||
|
||
private static ServerConnection.SonarQube CreateSonarQubeServerConnection(bool isSmartNotificationsEnabled = true) | ||
{ | ||
var sonarQube = new ServerConnection.SonarQube(new Uri("http://localhost"), new ServerConnectionSettings(isSmartNotificationsEnabled), Substitute.For<ICredentials>()); | ||
return sonarQube; | ||
} | ||
} |
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.