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

SLVS-1790 Add assistBinding method & related models to IConnectedModeSuggestionListener #6051

Open
wants to merge 2 commits into
base: feature/automatic-connected-mode
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,30 @@ namespace SonarLint.VisualStudio.SLCore.Listeners.UnitTests.Implementation;
[TestClass]
public class ConnectedModeSuggestionListenerTests
{
[TestMethod]
public void MefCtor_CheckExports()
private IBindingSuggestionHandler bindingSuggestionHandler;
private IActiveConfigScopeTracker activeConfigScopeTracer;
private ConnectedModeSuggestionListener testSubject;

[TestInitialize]
public void TestInitialize()
{
bindingSuggestionHandler = Substitute.For<IBindingSuggestionHandler>();
activeConfigScopeTracer = Substitute.For<IActiveConfigScopeTracker>();
testSubject = new ConnectedModeSuggestionListener(bindingSuggestionHandler, activeConfigScopeTracer);
}

[TestMethod]
public void MefCtor_CheckExports() =>
MefTestHelpers.CheckTypeCanBeImported<ConnectedModeSuggestionListener, ISLCoreListener>(
MefTestHelpers.CreateExport<IBindingSuggestionHandler>(),
MefTestHelpers.CreateExport<IActiveConfigScopeTracker>());
}

[TestMethod]
public void AssistCreatingConnectionAsync_Notifies()
{
var bindingSuggestionHandler = Substitute.For<IBindingSuggestionHandler>();
var activeConfigScopeTracer = Substitute.For<IActiveConfigScopeTracker>();
const string scopeId = "scope-id";
activeConfigScopeTracer.Current.Returns(new ConfigurationScope(scopeId));

var testSubject = new ConnectedModeSuggestionListener(bindingSuggestionHandler, activeConfigScopeTracer);
var response = testSubject.AssistCreatingConnectionAsync(new AssistCreatingConnectionParams()
{
connectionParams = new SonarQubeConnectionParams(new Uri("http://localhost:9000"), "a-token", "a-token-value")
Expand All @@ -55,12 +62,16 @@ public void AssistCreatingConnectionAsync_Notifies()
}

[TestMethod]
public void NoBindingSuggestionFound_Notifies()
public void AssistBindingAsync_NotImplemented()
{
var bindingSuggestionHandler = Substitute.For<IBindingSuggestionHandler>();
var activeConfigScopeTracer = Substitute.For<IActiveConfigScopeTracker>();
Action act = () => testSubject.AssistBindingAsync(new AssistBindingParams("A_CONNECTION_ID", "A_PROJECT_KEY", "A_CONFIG_SCOPE_ID", false));

act.Should().Throw<NotImplementedException>();
}

var testSubject = new ConnectedModeSuggestionListener(bindingSuggestionHandler, activeConfigScopeTracer);
[TestMethod]
public void NoBindingSuggestionFound_Notifies()
{
testSubject.NoBindingSuggestionFound(new NoBindingSuggestionFoundParams("a-project-key"));

bindingSuggestionHandler.Received().Notify();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public Task<AssistCreatingConnectionResponse> AssistCreatingConnectionAsync(Assi
return Task.FromResult(result);
}

public Task<AssistBindingResponse> AssistBindingAsync(AssistBindingParams parameters) => throw new NotImplementedException();

public void NoBindingSuggestionFound(NoBindingSuggestionFoundParams parameters)
{
bindingSuggestionHandler.Notify();
Expand Down
64 changes: 64 additions & 0 deletions src/SLCore.UnitTests/Listener/Binding/AssistBindingParamsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* SonarLint for Visual Studio
* Copyright (C) 2016-2025 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 Newtonsoft.Json;
using SonarLint.VisualStudio.SLCore.Listener.Binding;

namespace SonarLint.VisualStudio.SLCore.UnitTests.Listener.Binding;

[TestClass]
public class AssistBindingParamsTests
{
[TestMethod]
public void AssistBindingParams_DeserializesCorrectly()
{
var expected = new AssistBindingParams("connectionId", "projectKey", "configScopeId", true);
const string serialized = """
{
"connectionId": "connectionId",
"projectKey": "projectKey",
"configScopeId": "configScopeId",
"isFromSharedConfiguration": true
}
""";

var actual = JsonConvert.DeserializeObject<AssistBindingParams>(serialized);

actual.Should().BeEquivalentTo(expected, options => options.ComparingByMembers<AssistCreatingConnectionParams>());
}

[TestMethod]
public void AssistBindingParams_SerializesCorrectly()
{
var assistBindingParams = new AssistBindingParams("connectionId", "projectKey", "configScopeId", true);
const string expected = """
{
"connectionId": "connectionId",
"projectKey": "projectKey",
"configScopeId": "configScopeId",
"isFromSharedConfiguration": true
}
""";

var actual = JsonConvert.SerializeObject(assistBindingParams, Formatting.Indented);

actual.Should().BeEquivalentTo(expected);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* SonarLint for Visual Studio
* Copyright (C) 2016-2025 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 Newtonsoft.Json;
using SonarLint.VisualStudio.SLCore.Listener.Binding;

namespace SonarLint.VisualStudio.SLCore.UnitTests.Listener.Binding;

[TestClass]
public class AssistBindingResponseTests
{
[TestMethod]
public void AssistBindingResponse_DeserializesCorrectly()
{
var expected = new AssistBindingResponse("configScopeId");
const string serialized = """
{
"configurationScopeId": "configScopeId"
}
""";

var actual = JsonConvert.DeserializeObject<AssistBindingResponse>(serialized);

actual.Should().BeEquivalentTo(expected, options => options.ComparingByMembers<AssistBindingResponse>());
}

[TestMethod]
public void AssistBindingResponse_SerializesCorrectly()
{
var assistBindingResponse = new AssistBindingResponse("configScopeId");
const string expected = """
{
"configurationScopeId": "configScopeId"
}
""";

var actual = JsonConvert.SerializeObject(assistBindingResponse, Formatting.Indented);

actual.Should().BeEquivalentTo(expected);
}
}
23 changes: 23 additions & 0 deletions src/SLCore/Listener/Binding/AssistBindingParams.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* SonarLint for Visual Studio
* Copyright (C) 2016-2025 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.
*/

namespace SonarLint.VisualStudio.SLCore.Listener.Binding;

public record AssistBindingParams(string connectionId, string projectKey, string configScopeId, bool isFromSharedConfiguration);
23 changes: 23 additions & 0 deletions src/SLCore/Listener/Binding/AssistBindingResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* SonarLint for Visual Studio
* Copyright (C) 2016-2025 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.
*/

namespace SonarLint.VisualStudio.SLCore.Listener.Binding;

public record AssistBindingResponse(string configurationScopeId);
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

using System.Threading.Tasks;
using SonarLint.VisualStudio.SLCore.Core;

namespace SonarLint.VisualStudio.SLCore.Listener.Binding
{
public interface IConnectedModeSuggestionListener : ISLCoreListener
{
Task<AssistCreatingConnectionResponse> AssistCreatingConnectionAsync(AssistCreatingConnectionParams parameters);
Task<AssistBindingResponse> AssistBindingAsync(AssistBindingParams parameters);
void NoBindingSuggestionFound(NoBindingSuggestionFoundParams parameters);
}
}