Skip to content

Commit

Permalink
fix match method
Browse files Browse the repository at this point in the history
  • Loading branch information
ugras-ergun-sonarsource committed Dec 28, 2023
1 parent a4c225e commit 17a753f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
17 changes: 11 additions & 6 deletions src/SLCore.UnitTests/Listener/BranchListenerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

using System.Collections.Generic;
using System.Threading.Tasks;
using SonarLint.VisualStudio.SLCore.Core;
using SonarLint.VisualStudio.SLCore.Listener;
Expand All @@ -41,16 +42,20 @@ public void Mef_CheckIsSingleton()
}

[TestMethod]
[DataRow(null)]
[DataRow(5)]
[DataRow("something")]
public async Task MatchSonarProjectBranch_ReturnsNull(object parameter)
public async Task MatchSonarProjectBranch_ReturnsMainBranch()
{
var param = new MatchSonarProjectBranchParams
{
configurationScopeId = "scopeId",
mainSonarBranchName = "mainBranch",
allSonarBranchesNames = new List<string> { "branch1", "branch2", "mainBranch" }
};

var testSubject = new BranchListener();

var result = await testSubject.MatchSonarProjectBranch(parameter);
var result = await testSubject.MatchSonarProjectBranch(param);

result.Should().BeNull();
result.matchedSonarBranch.Should().Be("mainBranch");
}

[TestMethod]
Expand Down
17 changes: 15 additions & 2 deletions src/SLCore/Listener/BranchListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Threading.Tasks;
using SonarLint.VisualStudio.SLCore.Core;
Expand All @@ -33,9 +34,9 @@ public class BranchListener : ISLCoreListener
/// </summary>
/// <param name="parameters">Parameter's here for compability we discard it</param>
/// <remarks>This will be implemented properly in the future when needed but features we support does not need branch awareness for now</remarks>
public async Task<object> MatchSonarProjectBranch(object parameters)
public async Task<MatchSonarProjectBranchResponse> MatchSonarProjectBranch(MatchSonarProjectBranchParams parameters)
{
return null;
return new MatchSonarProjectBranchResponse { matchedSonarBranch = parameters.mainSonarBranchName };
}

/// <summary>
Expand All @@ -48,4 +49,16 @@ public Task DidChangeMatchedSonarProjectBranch(object parameters)
return Task.CompletedTask;
}
}

public class MatchSonarProjectBranchParams
{
public string configurationScopeId;
public string mainSonarBranchName;
public List<string> allSonarBranchesNames;
}

public class MatchSonarProjectBranchResponse
{
public string matchedSonarBranch;
}
}

0 comments on commit 17a753f

Please sign in to comment.