-
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.
- Loading branch information
1 parent
9a545e1
commit 1d9ff1a
Showing
5 changed files
with
189 additions
and
164 deletions.
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
212 changes: 51 additions & 161 deletions
212
src/Integration.UnitTests/Helpers/SonarLintOutputTests.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 |
---|---|---|
@@ -1,161 +1,51 @@ | ||
// /* | ||
// * SonarLint for Visual Studio | ||
// * Copyright (C) 2016-2024 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; | ||
// using Microsoft.VisualStudio.Shell; | ||
// using Microsoft.VisualStudio.Shell.Interop; | ||
// using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
// using Moq; | ||
// using SonarLint.VisualStudio.Core; | ||
// using SonarLint.VisualStudio.Integration.Helpers; | ||
// using SonarLint.VisualStudio.TestInfrastructure; | ||
// | ||
// namespace SonarLint.VisualStudio.Integration.UnitTests.Helpers | ||
// { | ||
// [TestClass] | ||
// public class SonarLintOutputTests | ||
// { | ||
// [TestMethod] | ||
// public void MefCtor_CheckIsExported() | ||
// { | ||
// MefTestHelpers.CheckTypeCanBeImported<SonarLintOutputLogger, ILogger>( | ||
// MefTestHelpers.CreateExport<SVsServiceProvider>(), | ||
// MefTestHelpers.CreateExport<ISonarLintSettings>()); | ||
// } | ||
// | ||
// [TestMethod] | ||
// public void Write_OutputsToWindow() | ||
// { | ||
// // Arrange | ||
// var windowMock = new ConfigurableVsOutputWindow(); | ||
// var sonarLintSettings = CreateSonarLintSettings(DaemonLogLevel.Info); | ||
// var serviceProviderMock = CreateConfiguredServiceProvider(windowMock); | ||
// | ||
// var testSubject = CreateTestSubject(serviceProviderMock, sonarLintSettings); | ||
// | ||
// // Act | ||
// testSubject.WriteLine("123"); | ||
// testSubject.WriteLine("abc"); | ||
// | ||
// // Assert | ||
// var outputPane = windowMock.AssertPaneExists(VsShellUtils.SonarLintOutputPaneGuid); | ||
// outputPane.AssertOutputStrings("123", "abc"); | ||
// } | ||
// | ||
// [TestMethod] | ||
// [DataRow(DaemonLogLevel.Info)] | ||
// [DataRow(DaemonLogLevel.Minimal)] | ||
// [DataRow(DaemonLogLevel.Verbose)] | ||
// public void LogVerbose_OnlyOutputsToWindowIfLogLevelIsVerbose(DaemonLogLevel logLevel) | ||
// { | ||
// // Arrange | ||
// var windowMock = new ConfigurableVsOutputWindow(); | ||
// var serviceProviderMock = CreateConfiguredServiceProvider(windowMock); | ||
// | ||
// var sonarLintSettings = CreateSonarLintSettings(logLevel); | ||
// | ||
// var testSubject = CreateTestSubject(serviceProviderMock, sonarLintSettings); | ||
// | ||
// testSubject.WriteLine("create window pane"); | ||
// var outputPane = windowMock.AssertPaneExists(VsShellUtils.SonarLintOutputPaneGuid); | ||
// outputPane.Reset(); | ||
// | ||
// // Act | ||
// testSubject.LogVerbose("123 {0} {1}", "param 1", 2); | ||
// testSubject.LogVerbose("{0} {1} abc", 1, "param 2"); | ||
// | ||
// // Assert | ||
// if (logLevel == DaemonLogLevel.Verbose) | ||
// { | ||
// var currentThreadId = System.Threading.Thread.CurrentThread.ManagedThreadId; | ||
// | ||
// outputPane.AssertOutputStrings( | ||
// $"[ThreadId {currentThreadId}] [DEBUG] 123 param 1 2", | ||
// $"[ThreadId {currentThreadId}] [DEBUG] 1 param 2 abc"); | ||
// outputPane.AssertOutputStrings(2); | ||
// } | ||
// else | ||
// { | ||
// outputPane.AssertOutputStrings(0); | ||
// } | ||
// } | ||
// | ||
// [TestMethod] | ||
// [DataRow(DaemonLogLevel.Info)] | ||
// [DataRow(DaemonLogLevel.Minimal)] | ||
// [DataRow(DaemonLogLevel.Verbose)] | ||
// public void WriteLine_ThreadIdIsAddedIfLogLevelIsVerbose(DaemonLogLevel logLevel) | ||
// { | ||
// // Arrange | ||
// var windowMock = new ConfigurableVsOutputWindow(); | ||
// var serviceProviderMock = CreateConfiguredServiceProvider(windowMock); | ||
// | ||
// var sonarLintSettings = CreateSonarLintSettings(logLevel); | ||
// | ||
// var testSubject = CreateTestSubject(serviceProviderMock, sonarLintSettings); | ||
// | ||
// testSubject.WriteLine("create window pane"); | ||
// var outputPane = windowMock.AssertPaneExists(VsShellUtils.SonarLintOutputPaneGuid); | ||
// outputPane.Reset(); | ||
// | ||
// // Act | ||
// testSubject.WriteLine("writeline, no params"); | ||
// testSubject.WriteLine("writeline, with params: {0}", "zzz"); | ||
// | ||
// outputPane.AssertOutputStrings(2); | ||
// | ||
// string expectedPrefix; | ||
// if (logLevel == DaemonLogLevel.Verbose) | ||
// { | ||
// var currentThreadId = System.Threading.Thread.CurrentThread.ManagedThreadId; | ||
// expectedPrefix = $"[ThreadId {currentThreadId}] "; | ||
// } | ||
// else | ||
// { | ||
// expectedPrefix = string.Empty; | ||
// } | ||
// | ||
// outputPane.AssertOutputStrings( | ||
// $"{expectedPrefix}writeline, no params", | ||
// $"{expectedPrefix}writeline, with params: zzz"); | ||
// } | ||
// | ||
// private static IServiceProvider CreateConfiguredServiceProvider(IVsOutputWindow outputWindow) | ||
// { | ||
// var serviceProvider = new ConfigurableServiceProvider(assertOnUnexpectedServiceRequest: true); | ||
// serviceProvider.RegisterService(typeof(SVsOutputWindow), outputWindow); | ||
// return serviceProvider; | ||
// } | ||
// | ||
// private static ISonarLintSettings CreateSonarLintSettings(DaemonLogLevel logLevel) | ||
// { | ||
// var sonarLintSettings = new Mock<ISonarLintSettings>(); | ||
// sonarLintSettings.Setup(x => x.DaemonLogLevel).Returns(logLevel); | ||
// return sonarLintSettings.Object; | ||
// } | ||
// | ||
// private static SonarLintOutputLogger CreateTestSubject(IServiceProvider serviceProvider, | ||
// ISonarLintSettings sonarLintSettings = null) | ||
// { | ||
// sonarLintSettings ??= Mock.Of<ISonarLintSettings>(); | ||
// return new SonarLintOutputLogger(serviceProvider, sonarLintSettings, Substitute.For<ILogContextManager>()); | ||
// } | ||
// } | ||
// } | ||
/* | ||
* SonarLint for Visual Studio | ||
* Copyright (C) 2016-2024 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.Logging; | ||
using SonarLint.VisualStudio.Integration.Helpers; | ||
|
||
namespace SonarLint.VisualStudio.Integration.UnitTests.Helpers | ||
{ | ||
[TestClass] | ||
public class SonarLintOutputTests | ||
{ | ||
// the normal check for export does not work here because this is a special Property export instead of the normal Class export | ||
// [TestMethod] | ||
// public void MefCtor_CheckIsExported() | ||
// { | ||
// MefTestHelpers.CheckTypeCanBeImported<SonarLintOutputLoggerFactory, ILogger>( | ||
// MefTestHelpers.CreateExport<ILoggerFactory>(), | ||
// MefTestHelpers.CreateExport<SVsServiceProvider>(), | ||
// MefTestHelpers.CreateExport<ISonarLintSettings>()); | ||
// } | ||
|
||
[TestMethod] | ||
public void Ctor_CreatesLoggerWithExpectedParameters() | ||
{ | ||
var loggerFactory = Substitute.For<ILoggerFactory>(); | ||
|
||
var testSubject = new SonarLintOutputLoggerFactory(loggerFactory, Substitute.For<IServiceProvider>(), Substitute.For<ISonarLintSettings>()); | ||
|
||
testSubject.Instance.Should().NotBeNull(); | ||
loggerFactory.Create(Arg.Any<SonarLintOutputWindowLogWriter>(), Arg.Any<SonarLintSettingsLogVerbosityIndicator>()); | ||
} | ||
|
||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
src/Integration.UnitTests/Helpers/SonarLintOutputWindowLogWriterTests.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,86 @@ | ||
/* | ||
* SonarLint for Visual Studio | ||
* Copyright (C) 2016-2024 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 Microsoft.VisualStudio.Shell.Interop; | ||
using SonarLint.VisualStudio.Integration.Helpers; | ||
using SonarLint.VisualStudio.TestInfrastructure; | ||
|
||
namespace SonarLint.VisualStudio.Integration.UnitTests.Helpers; | ||
|
||
[TestClass] | ||
public class SonarLintOutputWindowLogWriterTests | ||
{ | ||
private ConfigurableVsOutputWindow windowMock; | ||
private IServiceProvider serviceProviderMock; | ||
private SonarLintOutputWindowLogWriter testSubject; | ||
|
||
[TestInitialize] | ||
public void TestInitialize() | ||
{ | ||
windowMock = new ConfigurableVsOutputWindow(); | ||
serviceProviderMock = CreateConfiguredServiceProvider(windowMock); | ||
testSubject = new SonarLintOutputWindowLogWriter(serviceProviderMock); | ||
} | ||
|
||
[TestMethod] | ||
public void WriteLine_Empty_PutsEmptyLineToCorrectPane() | ||
{ | ||
var message = string.Empty; | ||
|
||
testSubject.WriteLine(message); | ||
|
||
var outputPane = windowMock.AssertPaneExists(VsShellUtils.SonarLintOutputPaneGuid); | ||
outputPane.AssertOutputStrings(message); | ||
} | ||
|
||
[TestMethod] | ||
public void WriteLine_Simple_PutsSingleLineToCorrectPane() | ||
{ | ||
var message = "ABOBA"; | ||
|
||
testSubject.WriteLine(message); | ||
|
||
var outputPane = windowMock.AssertPaneExists(VsShellUtils.SonarLintOutputPaneGuid); | ||
outputPane.AssertOutputStrings(message); | ||
} | ||
|
||
[TestMethod] | ||
public void WriteLine_Multiline_PutsMultiLineToCorrectPane() | ||
{ | ||
var message = | ||
""" | ||
A | ||
B | ||
OBA | ||
"""; | ||
|
||
testSubject.WriteLine(message); | ||
|
||
var outputPane = windowMock.AssertPaneExists(VsShellUtils.SonarLintOutputPaneGuid); | ||
outputPane.AssertOutputStrings(message); | ||
} | ||
|
||
private static IServiceProvider CreateConfiguredServiceProvider(IVsOutputWindow outputWindow) | ||
{ | ||
var serviceProvider = new ConfigurableServiceProvider(assertOnUnexpectedServiceRequest: true); | ||
serviceProvider.RegisterService(typeof(SVsOutputWindow), outputWindow); | ||
return serviceProvider; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/Integration.UnitTests/Helpers/SonarLintSettingsLogVerbosityIndicatorTests.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,49 @@ | ||
/* | ||
* SonarLint for Visual Studio | ||
* Copyright (C) 2016-2024 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.Integration.Helpers; | ||
|
||
namespace SonarLint.VisualStudio.Integration.UnitTests.Helpers; | ||
|
||
[TestClass] | ||
public class SonarLintSettingsLogVerbosityIndicatorTests | ||
{ | ||
private ISonarLintSettings sonarLintSettings; | ||
private SonarLintSettingsLogVerbosityIndicator testSubject; | ||
|
||
[TestInitialize] | ||
public void TestInitialize() | ||
{ | ||
sonarLintSettings = Substitute.For<ISonarLintSettings>(); | ||
testSubject = new SonarLintSettingsLogVerbosityIndicator(sonarLintSettings); | ||
} | ||
|
||
[DataRow(DaemonLogLevel.Verbose, true)] | ||
[DataRow(DaemonLogLevel.Info, false)] | ||
[DataRow(DaemonLogLevel.Minimal, false)] | ||
[DataTestMethod] | ||
public void IsVerboseEnabled_IsThreadIdEnabled_ReturnsFor(DaemonLogLevel logLevel, bool isVerbose) | ||
{ | ||
sonarLintSettings.DaemonLogLevel.Returns(logLevel); | ||
|
||
testSubject.IsVerboseEnabled.Should().Be(isVerbose); | ||
testSubject.IsThreadIdEnabled.Should().Be(isVerbose); | ||
} | ||
} |
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