-
Notifications
You must be signed in to change notification settings - Fork 77
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
Add IProgressListener #5139
Merged
ugras-ergun-sonarsource
merged 3 commits into
feature/sloop-rule-meta-data
from
ue/progressListener
Dec 27, 2023
Merged
Add IProgressListener #5139
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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 |
---|---|---|
|
@@ -22,7 +22,7 @@ | |
using SonarLint.VisualStudio.SLCore.Core; | ||
using SonarLint.VisualStudio.TestInfrastructure; | ||
|
||
namespace SonarLint.VisualStudio.SLCore.UnitTests; | ||
namespace SonarLint.VisualStudio.SLCore.UnitTests.Core; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see comment on SLCoreListenerSetUpTests. (This also had some whitespace fixes done automatically) |
||
|
||
[TestClass] | ||
public class SLCoreServiceProviderTests | ||
|
@@ -31,20 +31,20 @@ public class SLCoreServiceProviderTests | |
public void MefCtor_CheckIsExported() | ||
{ | ||
MefTestHelpers.CheckTypeCanBeImported<SLCoreServiceProvider, ISLCoreServiceProvider>(); | ||
} | ||
} | ||
|
||
[TestMethod] | ||
public void MefCtor_WriterInterface_CheckIsExported() | ||
{ | ||
MefTestHelpers.CheckTypeCanBeImported<SLCoreServiceProvider, ISLCoreServiceProviderWriter>(); | ||
} | ||
|
||
[TestMethod] | ||
public void Mef_CheckIsSingleton() | ||
{ | ||
MefTestHelpers.CheckIsSingletonMefComponent<SLCoreServiceProvider>(); | ||
} | ||
|
||
[TestMethod] | ||
public void TryGetTransientService_TypeNotInterface_Throws() | ||
{ | ||
|
@@ -62,42 +62,42 @@ public void TryGetTransientService_NotInitialized_ReturnsFalse() | |
|
||
testSubject.TryGetTransientService(out ITestSLcoreService1 _).Should().BeFalse(); | ||
} | ||
|
||
[TestMethod] | ||
public void TryGetTransientService_ConnectionDied_ReturnsFalse() | ||
{ | ||
var rpcMock = new Mock<ISLCoreJsonRpc>(); | ||
SetUpConnectionState(rpcMock, false); | ||
|
||
var testSubject = CreateTestSubject(rpcMock.Object); | ||
|
||
testSubject.TryGetTransientService(out ITestSLcoreService1 _).Should().BeFalse(); | ||
} | ||
|
||
[TestMethod] | ||
public void TryGetTransientService_ConnectionIsAlive_ReturnsTrueAndCreatesService() | ||
{ | ||
var rpcMock = new Mock<ISLCoreJsonRpc>(); | ||
SetUpConnectionState(rpcMock, true); | ||
var service1 = Mock.Of<ITestSLcoreService1>(); | ||
SetUpServiceCreation(rpcMock, service1); | ||
|
||
var testSubject = CreateTestSubject(rpcMock.Object); | ||
|
||
testSubject.TryGetTransientService(out ITestSLcoreService1 requestedService).Should().BeTrue(); | ||
|
||
requestedService.Should().BeSameAs(service1); | ||
rpcMock.Verify(x => x.CreateService<ITestSLcoreService1>(), Times.Once); | ||
} | ||
} | ||
|
||
[TestMethod] | ||
public void TryGetTransientService_ServiceAlreadyCreated_ReturnsTrueAndCachedCopy() | ||
{ | ||
var rpcMock = new Mock<ISLCoreJsonRpc>(); | ||
SetUpConnectionState(rpcMock, true); | ||
var service1 = Mock.Of<ITestSLcoreService1>(); | ||
SetUpServiceCreation(rpcMock, service1); | ||
|
||
var testSubject = CreateTestSubject(rpcMock.Object); | ||
testSubject.TryGetTransientService(out ITestSLcoreService1 _); | ||
|
||
|
@@ -106,15 +106,15 @@ public void TryGetTransientService_ServiceAlreadyCreated_ReturnsTrueAndCachedCop | |
requestedService.Should().BeSameAs(service1); | ||
rpcMock.Verify(x => x.CreateService<ITestSLcoreService1>(), Times.Once); | ||
} | ||
|
||
[TestMethod] | ||
public void TryGetTransientService_ConnectionReset_ReturnsTrueAndCreatesService() | ||
{ | ||
var service1 = Mock.Of<ITestSLcoreService1>(); | ||
var rpcMock1 = new Mock<ISLCoreJsonRpc>(); | ||
SetUpConnectionState(rpcMock1, true); | ||
SetUpServiceCreation(rpcMock1, service1); | ||
|
||
var testSubject = CreateTestSubject(rpcMock1.Object); | ||
testSubject.TryGetTransientService(out ITestSLcoreService1 _); //caching | ||
var service2 = Mock.Of<ITestSLcoreService1>(); | ||
|
@@ -146,7 +146,7 @@ public void SetCurrentConnection_ClearsAllCachedServices() | |
testSubject.TryGetTransientService(out ITestSLcoreService1 _).Should().BeTrue(); | ||
testSubject.TryGetTransientService(out ITestSLcoreService2 _).Should().BeTrue(); | ||
testSubject.TryGetTransientService(out ITestSLcoreService3 _).Should().BeTrue(); | ||
|
||
var service1New = Mock.Of<ITestSLcoreService1>(); | ||
var service2New = Mock.Of<ITestSLcoreService2>(); | ||
var service3New = Mock.Of<ITestSLcoreService3>(); | ||
|
@@ -155,9 +155,9 @@ public void SetCurrentConnection_ClearsAllCachedServices() | |
SetUpServiceCreation(rpcMock2, service1New); | ||
SetUpServiceCreation(rpcMock2, service2New); | ||
SetUpServiceCreation(rpcMock2, service3New); | ||
|
||
testSubject.SetCurrentConnection(rpcMock2.Object); | ||
|
||
testSubject.TryGetTransientService(out ITestSLcoreService1 requestedService1).Should().BeTrue(); | ||
requestedService1.Should().BeSameAs(service1New).And.NotBeSameAs(service1); | ||
testSubject.TryGetTransientService(out ITestSLcoreService2 requestedService2).Should().BeTrue(); | ||
|
@@ -170,12 +170,12 @@ private static void SetUpServiceCreation<T>(Mock<ISLCoreJsonRpc> rpcMock, T serv | |
{ | ||
rpcMock.Setup(x => x.CreateService<T>()).Returns(service); | ||
} | ||
|
||
private static void SetUpConnectionState(Mock<ISLCoreJsonRpc> rpcMock, bool isAlive) | ||
{ | ||
rpcMock.SetupGet(x => x.IsAlive).Returns(isAlive); | ||
} | ||
|
||
private SLCoreServiceProvider CreateTestSubject(ISLCoreJsonRpc jsonRpc = null) | ||
{ | ||
var testSubject = new SLCoreServiceProvider(); | ||
|
@@ -188,21 +188,17 @@ private SLCoreServiceProvider CreateTestSubject(ISLCoreJsonRpc jsonRpc = null) | |
|
||
public class TestSLCoreService : ISLCoreService | ||
{ | ||
|
||
} | ||
|
||
public interface ITestSLcoreService1 : ISLCoreService | ||
{ | ||
|
||
} | ||
|
||
public interface ITestSLcoreService2 : ISLCoreService | ||
{ | ||
|
||
} | ||
|
||
public interface ITestSLcoreService3 : ISLCoreService | ||
{ | ||
|
||
} | ||
} |
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,69 @@ | ||
/* | ||
* SonarLint for Visual Studio | ||
* Copyright (C) 2016-2023 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.Threading.Tasks; | ||
using SonarLint.VisualStudio.SLCore.Core; | ||
using SonarLint.VisualStudio.SLCore.Listener; | ||
using SonarLint.VisualStudio.TestInfrastructure; | ||
|
||
namespace SonarLint.VisualStudio.SLCore.UnitTests.Listener | ||
{ | ||
[TestClass] | ||
public class ProgressListenerTests | ||
{ | ||
[TestMethod] | ||
public void MefCtor_CheckIsExported() | ||
{ | ||
MefTestHelpers.CheckTypeCanBeImported<ProgressListener, ISLCoreListener>(); | ||
} | ||
|
||
[TestMethod] | ||
public void Mef_CheckIsSingleton() | ||
{ | ||
MefTestHelpers.CheckIsSingletonMefComponent<ProgressListener>(); | ||
} | ||
|
||
[TestMethod] | ||
[DataRow(null)] | ||
[DataRow(5)] | ||
[DataRow("something")] | ||
public void StartProgress_ReturnsCompletedTaskAlways(object parameter) | ||
{ | ||
var testSubject = new ProgressListener(); | ||
|
||
var result = testSubject.StartProgress(parameter); | ||
|
||
result.Should().Be(Task.CompletedTask); | ||
} | ||
|
||
[TestMethod] | ||
[DataRow(null)] | ||
[DataRow(5)] | ||
[DataRow("something")] | ||
public void ReportProgress_ReturnsCompletedTaskAlways(object parameter) | ||
{ | ||
var testSubject = new ProgressListener(); | ||
|
||
var result = testSubject.ReportProgress(parameter); | ||
|
||
result.Should().Be(Task.CompletedTask); | ||
} | ||
} | ||
} |
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
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,49 @@ | ||
/* | ||
* SonarLint for Visual Studio | ||
* Copyright (C) 2016-2023 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 System.Threading.Tasks; | ||
using SonarLint.VisualStudio.SLCore.Core; | ||
|
||
namespace SonarLint.VisualStudio.SLCore.Listener | ||
{ | ||
[Export(typeof(ISLCoreListener))] | ||
[PartCreationPolicy(CreationPolicy.Shared)] | ||
public class ProgressListener : ISLCoreListener | ||
{ | ||
/// <summary> | ||
/// Stub method for compability with SLCore. We do not support progress | ||
/// </summary> | ||
/// <param name="parameters">Parameter's here for compability we discard it</param> | ||
public Task StartProgress(object parameters) | ||
{ | ||
return Task.CompletedTask; | ||
} | ||
|
||
/// <summary> | ||
/// Stub method for compability with SLCore. We do not support progress | ||
/// </summary> | ||
/// <param name="parameters">Parameter's here for compability we discard it</param> | ||
public Task ReportProgress(object parameters) | ||
{ | ||
return Task.CompletedTask; | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved tests to core folder so it would have same structure with the main project. It's 2 tasks in 1 PR but since PR is so small I think it's OK.