diff --git a/src/Core.UnitTests/Configuration/ConnectedModeFeaturesConfigurationTests.cs b/src/Core.UnitTests/Configuration/ConnectedModeFeaturesConfigurationTests.cs index 766451ee86..b10e31e1ef 100644 --- a/src/Core.UnitTests/Configuration/ConnectedModeFeaturesConfigurationTests.cs +++ b/src/Core.UnitTests/Configuration/ConnectedModeFeaturesConfigurationTests.cs @@ -37,7 +37,44 @@ public void MefCtor_CheckExports() MefTestHelpers.CheckTypeCanBeImported( MefTestHelpers.CreateExport()); } - + + [TestMethod] + public void IsAcceptTransitionAvailable_NoServerInfo_ReturnsFalse() + { + var testSubject = CreateTestSubject(null); + + testSubject.IsAcceptTransitionAvailable().Should().BeFalse(); + } + + [DataRow(1, 2, 3)] + [DataRow(1231923123, 31312, 0)] + [DataRow(9, 7, 3)] + [DataRow(9, 6, 9)] + [DataRow(0, 0, 0)] + [DataTestMethod] + public void IsAcceptTransitionAvailable_AnySonarCloudVersion_ReturnsTrue(int major, int minor, int build) + { + var testSubject = CreateTestSubject(new ServerInfo(new Version(major, minor, build), ServerType.SonarCloud)); + + testSubject.IsAcceptTransitionAvailable().Should().BeTrue(); + } + + [DataRow(0, 0, 0, false)] + [DataRow(10, 0, 0, false)] + [DataRow(10, 5, 0, true)] + [DataRow(10, 4, 0, true)] + [DataRow(10, 3, 0, false)] + [DataRow(12, 0, 0, true)] + [DataRow(10, 0, 99, false)] + [DataRow(9, 10, 0, false)] + [DataTestMethod] + public void IsAcceptTransitionAvailable_SonarQube_RespectsMinimumVersion(int major, int minor, int build, bool expectedResult) + { + var testSubject = CreateTestSubject(new ServerInfo(new Version(major, minor, build), ServerType.SonarQube)); + + testSubject.IsAcceptTransitionAvailable().Should().Be(expectedResult); + } + [TestMethod] public void IsNewCctAvailable_NoServerInfo_ReturnsTrue() { @@ -45,7 +82,7 @@ public void IsNewCctAvailable_NoServerInfo_ReturnsTrue() testSubject.IsNewCctAvailable().Should().BeTrue(); } - + [DataRow(1, 2, 3)] [DataRow(1231923123, 31312, 0)] [DataRow(9, 7, 3)] @@ -82,7 +119,7 @@ public void IsHotspotsAnalysisEnabled_NoServerInfo_ReturnsFalse() testSubject.IsHotspotsAnalysisEnabled().Should().BeFalse(); } - + [DataRow(1, 2, 3)] [DataRow(1231923123, 31312, 0)] [DataRow(9, 7, 3)] diff --git a/src/Core/Configuration/ConnectedModeFeaturesConfiguration.cs b/src/Core/Configuration/ConnectedModeFeaturesConfiguration.cs index a1928a0e66..4d6fe7056e 100644 --- a/src/Core/Configuration/ConnectedModeFeaturesConfiguration.cs +++ b/src/Core/Configuration/ConnectedModeFeaturesConfiguration.cs @@ -30,15 +30,22 @@ namespace SonarLint.VisualStudio.Core.Configuration public interface IConnectedModeFeaturesConfiguration { /// - /// Indicates whether Local Hotspot Analysis is supported in the current Connected Mode state + /// Indicates whether Local Hotspot Analysis is supported in the current Connected Mode state /// /// True if connected to SCloud or SQube 9.7 and above, False otherwise bool IsHotspotsAnalysisEnabled(); + /// /// Indicates whether the new Clean Code Taxonomy should be used in the current Connected Mode state /// /// False if connected to SQube 10.1.X and below, True otherwise (including Standalone) bool IsNewCctAvailable(); + + /// + /// Indicates whether the Accept transition is supportted in current server + /// + /// True if connected to SCloud or SQube 10.4 and above, False otherwise + bool IsAcceptTransitionAvailable(); } [Export(typeof(IConnectedModeFeaturesConfiguration))] @@ -47,6 +54,7 @@ public class ConnectedModeFeaturesConfiguration : IConnectedModeFeaturesConfigur { private readonly Version minimalSonarQubeVersionForHotspots = new Version(9, 7); private readonly Version minimalSonarQubeVersionForNewTaxonomy = new Version(10, 2); + private readonly Version minimalSonarQubeVersionForAccept = new Version(10, 4); private readonly ISonarQubeService sonarQubeService; [ImportingConstructor] @@ -58,15 +66,15 @@ public ConnectedModeFeaturesConfiguration(ISonarQubeService sonarQubeService) public bool IsNewCctAvailable() { var serverInfo = sonarQubeService.GetServerInfo(); - + // use new cct in standalone, connected to SC or connected to SQ >=10.2 return serverInfo == null || IsSupportedForVersion(serverInfo, minimalSonarQubeVersionForNewTaxonomy); } - + public bool IsHotspotsAnalysisEnabled() { var serverInfo = sonarQubeService.GetServerInfo(); - + // analyze hotspots connected to SC or connected to SQ >= 9.7 return serverInfo != null && IsSupportedForVersion(serverInfo, minimalSonarQubeVersionForHotspots); } @@ -75,5 +83,12 @@ private static bool IsSupportedForVersion(ServerInfo serverInfo, Version minimum serverInfo.ServerType == ServerType.SonarCloud || (serverInfo.ServerType == ServerType.SonarQube && serverInfo.Version >= minimumVersion); + + public bool IsAcceptTransitionAvailable() + { + var serverInfo = sonarQubeService.GetServerInfo(); + + return serverInfo != null && IsSupportedForVersion(serverInfo, minimalSonarQubeVersionForAccept); + } } }