-
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
Add IProgressListener #5139
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
{ | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* 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.Listener; | ||
using SonarLint.VisualStudio.TestInfrastructure; | ||
|
||
namespace SonarLint.VisualStudio.SLCore.UnitTests.Listener | ||
{ | ||
[TestClass] | ||
public class ProgressListenerTests | ||
{ | ||
[TestMethod] | ||
public void MefCtor_CheckIsExported() | ||
{ | ||
MefTestHelpers.CheckTypeCanBeImported<ProgressListener, IProgressListener>(); | ||
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. Wrong export contract |
||
} | ||
|
||
[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); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* 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; | ||
using StreamJsonRpc; | ||
|
||
namespace SonarLint.VisualStudio.SLCore.Listener | ||
{ | ||
public interface IProgressListener : ISLCoreListener | ||
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. We don't need this interface. |
||
{ | ||
[JsonRpcMethod(UseSingleObjectParameterDeserialization = true)] | ||
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.
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. I will try to make the PoC work. Will get back to you. 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. Discussed on slack |
||
Task StartProgress(object parameters); | ||
|
||
[JsonRpcMethod(UseSingleObjectParameterDeserialization = true)] | ||
Task ReportProgress(object parameters); | ||
} | ||
|
||
[Export(typeof(IProgressListener))] | ||
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. Wrong export contract |
||
[PartCreationPolicy(CreationPolicy.Shared)] | ||
public class ProgressListener : IProgressListener | ||
{ | ||
public Task StartProgress(object parameters) | ||
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. You need to add a comment with why this is an object and not some real model ("we don't support this method") |
||
{ | ||
return Task.CompletedTask; | ||
} | ||
|
||
public Task ReportProgress(object parameters) | ||
{ | ||
return Task.CompletedTask; | ||
} | ||
} | ||
} |
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.