diff --git a/src/SLCore.UnitTests/SLCoreListenerSetUpTests.cs b/src/SLCore.UnitTests/Core/SLCoreListenerSetUpTests.cs similarity index 98% rename from src/SLCore.UnitTests/SLCoreListenerSetUpTests.cs rename to src/SLCore.UnitTests/Core/SLCoreListenerSetUpTests.cs index 230b9548e9..dff28f4234 100644 --- a/src/SLCore.UnitTests/SLCoreListenerSetUpTests.cs +++ b/src/SLCore.UnitTests/Core/SLCoreListenerSetUpTests.cs @@ -21,7 +21,7 @@ using SonarLint.VisualStudio.SLCore.Core; using SonarLint.VisualStudio.TestInfrastructure; -namespace SonarLint.VisualStudio.SLCore.UnitTests +namespace SonarLint.VisualStudio.SLCore.UnitTests.Core { [TestClass] public class SLCoreListenerSetUpTests diff --git a/src/SLCore.UnitTests/SLCoreServiceProviderTests.cs b/src/SLCore.UnitTests/Core/SLCoreServiceProviderTests.cs similarity index 97% rename from src/SLCore.UnitTests/SLCoreServiceProviderTests.cs rename to src/SLCore.UnitTests/Core/SLCoreServiceProviderTests.cs index 206c248c5f..51de0f62cb 100644 --- a/src/SLCore.UnitTests/SLCoreServiceProviderTests.cs +++ b/src/SLCore.UnitTests/Core/SLCoreServiceProviderTests.cs @@ -22,7 +22,7 @@ using SonarLint.VisualStudio.SLCore.Core; using SonarLint.VisualStudio.TestInfrastructure; -namespace SonarLint.VisualStudio.SLCore.UnitTests; +namespace SonarLint.VisualStudio.SLCore.UnitTests.Core; [TestClass] public class SLCoreServiceProviderTests @@ -31,20 +31,20 @@ public class SLCoreServiceProviderTests public void MefCtor_CheckIsExported() { MefTestHelpers.CheckTypeCanBeImported(); - } - + } + [TestMethod] public void MefCtor_WriterInterface_CheckIsExported() { MefTestHelpers.CheckTypeCanBeImported(); } - + [TestMethod] public void Mef_CheckIsSingleton() { MefTestHelpers.CheckIsSingletonMefComponent(); } - + [TestMethod] public void TryGetTransientService_TypeNotInterface_Throws() { @@ -62,18 +62,18 @@ public void TryGetTransientService_NotInitialized_ReturnsFalse() testSubject.TryGetTransientService(out ITestSLcoreService1 _).Should().BeFalse(); } - + [TestMethod] public void TryGetTransientService_ConnectionDied_ReturnsFalse() { var rpcMock = new Mock(); SetUpConnectionState(rpcMock, false); - + var testSubject = CreateTestSubject(rpcMock.Object); testSubject.TryGetTransientService(out ITestSLcoreService1 _).Should().BeFalse(); } - + [TestMethod] public void TryGetTransientService_ConnectionIsAlive_ReturnsTrueAndCreatesService() { @@ -81,15 +81,15 @@ public void TryGetTransientService_ConnectionIsAlive_ReturnsTrueAndCreatesServic SetUpConnectionState(rpcMock, true); var service1 = Mock.Of(); SetUpServiceCreation(rpcMock, service1); - + var testSubject = CreateTestSubject(rpcMock.Object); testSubject.TryGetTransientService(out ITestSLcoreService1 requestedService).Should().BeTrue(); requestedService.Should().BeSameAs(service1); rpcMock.Verify(x => x.CreateService(), Times.Once); - } - + } + [TestMethod] public void TryGetTransientService_ServiceAlreadyCreated_ReturnsTrueAndCachedCopy() { @@ -97,7 +97,7 @@ public void TryGetTransientService_ServiceAlreadyCreated_ReturnsTrueAndCachedCop SetUpConnectionState(rpcMock, true); var service1 = Mock.Of(); SetUpServiceCreation(rpcMock, service1); - + var testSubject = CreateTestSubject(rpcMock.Object); testSubject.TryGetTransientService(out ITestSLcoreService1 _); @@ -106,7 +106,7 @@ public void TryGetTransientService_ServiceAlreadyCreated_ReturnsTrueAndCachedCop requestedService.Should().BeSameAs(service1); rpcMock.Verify(x => x.CreateService(), Times.Once); } - + [TestMethod] public void TryGetTransientService_ConnectionReset_ReturnsTrueAndCreatesService() { @@ -114,7 +114,7 @@ public void TryGetTransientService_ConnectionReset_ReturnsTrueAndCreatesService( var rpcMock1 = new Mock(); SetUpConnectionState(rpcMock1, true); SetUpServiceCreation(rpcMock1, service1); - + var testSubject = CreateTestSubject(rpcMock1.Object); testSubject.TryGetTransientService(out ITestSLcoreService1 _); //caching var service2 = Mock.Of(); @@ -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(); var service2New = Mock.Of(); var service3New = Mock.Of(); @@ -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(Mock rpcMock, T serv { rpcMock.Setup(x => x.CreateService()).Returns(service); } - + private static void SetUpConnectionState(Mock 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 { - } } diff --git a/src/SLCore.UnitTests/Listener/ProgressListenerTests.cs b/src/SLCore.UnitTests/Listener/ProgressListenerTests.cs new file mode 100644 index 0000000000..b40f49456c --- /dev/null +++ b/src/SLCore.UnitTests/Listener/ProgressListenerTests.cs @@ -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(); + } + + [TestMethod] + public void Mef_CheckIsSingleton() + { + MefTestHelpers.CheckIsSingletonMefComponent(); + } + + [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); + } + } +} diff --git a/src/SLCore.UnitTests/SLCore.UnitTests.csproj b/src/SLCore.UnitTests/SLCore.UnitTests.csproj index 94d0f5ed77..c0e6e3d7ef 100644 --- a/src/SLCore.UnitTests/SLCore.UnitTests.csproj +++ b/src/SLCore.UnitTests/SLCore.UnitTests.csproj @@ -1,4 +1,4 @@ - + diff --git a/src/SLCore/Listener/ProgressListener.cs b/src/SLCore/Listener/ProgressListener.cs new file mode 100644 index 0000000000..dbc6627658 --- /dev/null +++ b/src/SLCore/Listener/ProgressListener.cs @@ -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 + { + /// + /// Stub method for compability with SLCore. We do not support progress + /// + /// Parameter's here for compability we discard it + public Task StartProgress(object parameters) + { + return Task.CompletedTask; + } + + /// + /// Stub method for compability with SLCore. We do not support progress + /// + /// Parameter's here for compability we discard it + public Task ReportProgress(object parameters) + { + return Task.CompletedTask; + } + } +}