-
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-1884 Add RPC method helpGenerateUserToken (#6048)
- Loading branch information
1 parent
7bca71c
commit 01345f7
Showing
10 changed files
with
354 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
src/SLCore.Listeners.UnitTests/Implementation/BrowserListenerTests.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,57 @@ | ||
/* | ||
* 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 SonarLint.VisualStudio.Core; | ||
using SonarLint.VisualStudio.SLCore.Listener.Visualization; | ||
using SonarLint.VisualStudio.SLCore.Listener.Visualization.Models; | ||
|
||
namespace SonarLint.VisualStudio.SLCore.Listeners.UnitTests.Implementation; | ||
|
||
[TestClass] | ||
public class BrowserListenerTests | ||
{ | ||
private IBrowserService browserService; | ||
private BrowserListener testSubject; | ||
|
||
[TestInitialize] | ||
public void SetUp() | ||
{ | ||
browserService = Substitute.For<IBrowserService>(); | ||
testSubject = new BrowserListener(browserService); | ||
} | ||
|
||
[TestMethod] | ||
public void MefCtor_CheckIsExported() => | ||
MefTestHelpers.CheckTypeCanBeImported<BrowserListener, IBrowserListener>( | ||
MefTestHelpers.CreateExport<IBrowserService>()); | ||
|
||
[TestMethod] | ||
public void MefCtor_CheckIsSingleton() => MefTestHelpers.CheckIsSingletonMefComponent<BrowserListener>(); | ||
|
||
[TestMethod] | ||
public void OpenUrlInBrowser_NavigatesToUrl() | ||
{ | ||
var url = "http://example.com"; | ||
|
||
testSubject.OpenUrlInBrowser(new OpenUrlInBrowserParams(url)); | ||
|
||
browserService.Received(1).Navigate(url); | ||
} | ||
} |
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,34 @@ | ||
/* | ||
* 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 System.ComponentModel.Composition; | ||
using SonarLint.VisualStudio.Core; | ||
using SonarLint.VisualStudio.SLCore.Listener.Visualization; | ||
using SonarLint.VisualStudio.SLCore.Listener.Visualization.Models; | ||
|
||
namespace SonarLint.VisualStudio.SLCore.Listeners.Implementation; | ||
|
||
[Export(typeof(IBrowserListener))] | ||
[PartCreationPolicy(CreationPolicy.Shared)] | ||
[method: ImportingConstructor] | ||
public class BrowserListener(IBrowserService browserService) : IBrowserListener | ||
{ | ||
public void OpenUrlInBrowser(OpenUrlInBrowserParams parameters) => browserService.Navigate(parameters.url); | ||
} |
38 changes: 38 additions & 0 deletions
38
src/SLCore.UnitTests/Listener/Visualization/OpenUrlInBrowserParamsTests.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,38 @@ | ||
using Newtonsoft.Json; | ||
using SonarLint.VisualStudio.SLCore.Listener.Visualization.Models; | ||
|
||
namespace SonarLint.VisualStudio.SLCore.UnitTests.Listener.Visualization; | ||
|
||
[TestClass] | ||
public class OpenUrlInBrowserParamsTests | ||
{ | ||
[TestMethod] | ||
public void Serialize_AsExpected() | ||
{ | ||
var openUrlInBrowserParams = new OpenUrlInBrowserParams("http://localhost:9000/home"); | ||
var expected = """ | ||
{ | ||
"url": "http://localhost:9000/home" | ||
} | ||
"""; | ||
|
||
var actual = JsonConvert.SerializeObject(openUrlInBrowserParams, Formatting.Indented); | ||
|
||
actual.Should().Be(expected); | ||
} | ||
|
||
[TestMethod] | ||
public void Deserialize_AsExpected() | ||
{ | ||
var expected = new OpenUrlInBrowserParams("http://localhost:9000/home"); | ||
var serialized = """ | ||
{ | ||
"url": "http://localhost:9000/home" | ||
} | ||
"""; | ||
|
||
var actual = JsonConvert.DeserializeObject<OpenUrlInBrowserParams>(serialized); | ||
|
||
actual.Should().BeEquivalentTo(expected, options => options.ComparingByMembers<OpenUrlInBrowserParams>()); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/SLCore.UnitTests/Service/Connection/Models/HelpGenerateUserTokenParamsTests.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,43 @@ | ||
/* | ||
* 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.Service.Connection.Models; | ||
|
||
namespace SonarLint.VisualStudio.SLCore.UnitTests.Service.Connection.Models; | ||
|
||
[TestClass] | ||
public class HelpGenerateUserTokenParamsTests | ||
{ | ||
[TestMethod] | ||
public void Serialize_AsExpected() | ||
{ | ||
var helpGenerateUserTokenParams = new HelpGenerateUserTokenParams("http://localhost:9000"); | ||
var expected = """ | ||
{ | ||
"serverUrl": "http://localhost:9000" | ||
} | ||
"""; | ||
|
||
var actual = JsonConvert.SerializeObject(helpGenerateUserTokenParams, Formatting.Indented); | ||
|
||
actual.Should().Be(expected); | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
src/SLCore.UnitTests/Service/Connection/Models/HelpGenerateUserTokenResponseTests.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,68 @@ | ||
/* | ||
* 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.Service.Connection.Models; | ||
|
||
namespace SonarLint.VisualStudio.SLCore.UnitTests.Service.Connection.Models; | ||
|
||
[TestClass] | ||
public class HelpGenerateUserTokenResponseTests | ||
{ | ||
[TestMethod] | ||
[DataRow(""" | ||
{ | ||
"token": "A186C072-9D8F-404C-9BA8-31EC450409B2" | ||
} | ||
""", "A186C072-9D8F-404C-9BA8-31EC450409B2")] | ||
[DataRow(""" | ||
{ | ||
"token": null | ||
} | ||
""", null)] | ||
public void Serialize_AsExpected(string expected, string token) | ||
{ | ||
var helpGenerateUserTokenParams = new HelpGenerateUserTokenResponse(token); | ||
|
||
var actual = JsonConvert.SerializeObject(helpGenerateUserTokenParams, Formatting.Indented); | ||
|
||
actual.Should().Be(expected); | ||
} | ||
|
||
[TestMethod] | ||
[DataRow(""" | ||
{ | ||
"token": "A186C072-9D8F-404C-9BA8-31EC450409B2" | ||
} | ||
""", "A186C072-9D8F-404C-9BA8-31EC450409B2")] | ||
[DataRow(""" | ||
{ | ||
"token": null | ||
} | ||
""", null)] | ||
public void Deserialize_AsExpected(string serialized, string expectedToken) | ||
{ | ||
var expected = new HelpGenerateUserTokenResponse(expectedToken); | ||
|
||
var actual = JsonConvert.DeserializeObject<HelpGenerateUserTokenResponse>(serialized); | ||
|
||
actual.Should().BeEquivalentTo(expected, options => options.ComparingByMembers<HelpGenerateUserTokenResponse>()); | ||
} | ||
} |
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,29 @@ | ||
/* | ||
* 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 SonarLint.VisualStudio.SLCore.Core; | ||
using SonarLint.VisualStudio.SLCore.Listener.Visualization.Models; | ||
|
||
namespace SonarLint.VisualStudio.SLCore.Listener.Visualization; | ||
|
||
public interface IBrowserListener : ISLCoreListener | ||
{ | ||
void OpenUrlInBrowser(OpenUrlInBrowserParams parameters); | ||
} |
25 changes: 25 additions & 0 deletions
25
src/SLCore/Listener/Visualization/Models/OpenUrlInBrowserParams.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,25 @@ | ||
/* | ||
* 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.Visualization.Models; | ||
|
||
public record OpenUrlInBrowserParams(string url) | ||
{ | ||
} |
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
25 changes: 25 additions & 0 deletions
25
src/SLCore/Service/Connection/Models/HelpGenerateUserTokenParams.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,25 @@ | ||
/* | ||
* 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.Service.Connection.Models; | ||
|
||
public record HelpGenerateUserTokenParams(string serverUrl) | ||
{ | ||
} |
25 changes: 25 additions & 0 deletions
25
src/SLCore/Service/Connection/Models/HelpGenerateUserTokenResponse.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,25 @@ | ||
/* | ||
* 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.Service.Connection.Models; | ||
|
||
public record HelpGenerateUserTokenResponse(string token) | ||
{ | ||
} |