Skip to content
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

SLVS-1708 [Visual Studio] Migrate Mute Issue to SLCore #6035

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions src/ConnectedMode.UnitTests/BoundSolutionUpdateHandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

using System;
using SonarLint.VisualStudio.ConnectedMode.Hotspots;
using SonarLint.VisualStudio.ConnectedMode.QualityProfiles;
using SonarLint.VisualStudio.ConnectedMode.Suppressions;
Expand All @@ -35,7 +34,7 @@ public void MefCtor_CheckIsExported()
{
MefTestHelpers.CheckTypeCanBeImported<BoundSolutionUpdateHandler, BoundSolutionUpdateHandler>(
MefTestHelpers.CreateExport<IActiveSolutionBoundTracker>(),
MefTestHelpers.CreateExport<ISuppressionIssueStoreUpdater>(),
MefTestHelpers.CreateExport<ISuppressionUpdater>(),
MefTestHelpers.CreateExport<IServerHotspotStoreUpdater>(),
MefTestHelpers.CreateExport<IQualityProfileUpdater>());
}
Expand All @@ -51,7 +50,7 @@ public void Ctor_SubscribesToEvents()
{
var activeSolutionTracker = new Mock<IActiveSolutionBoundTracker>();

_ = new BoundSolutionUpdateHandler(activeSolutionTracker.Object, Mock.Of<ISuppressionIssueStoreUpdater>(), Mock.Of<IServerHotspotStoreUpdater>(), Mock.Of<IQualityProfileUpdater>());
_ = new BoundSolutionUpdateHandler(activeSolutionTracker.Object, Mock.Of<ISuppressionUpdater>(), Mock.Of<IServerHotspotStoreUpdater>(), Mock.Of<IQualityProfileUpdater>());

activeSolutionTracker.VerifyAdd(x => x.SolutionBindingChanged += It.IsAny<EventHandler<ActiveSolutionBindingEventArgs>>(), Times.Once);
activeSolutionTracker.VerifyAdd(x => x.SolutionBindingUpdated += It.IsAny<EventHandler>(), Times.Once);
Expand All @@ -61,19 +60,19 @@ public void Ctor_SubscribesToEvents()
public void InvokeEvents_ServerStoreUpdatersAreCalled()
{
var activeSolutionTracker = new Mock<IActiveSolutionBoundTracker>();
var suppressionIssueStoreUpdater = new Mock<ISuppressionIssueStoreUpdater>();
var suppressionUpdater = new Mock<ISuppressionUpdater>();
var serverHotspotStoreUpdater = new Mock<IServerHotspotStoreUpdater>();
var qualityProfileUpdater = new Mock<IQualityProfileUpdater>();

_ = new BoundSolutionUpdateHandler(activeSolutionTracker.Object, suppressionIssueStoreUpdater.Object, serverHotspotStoreUpdater.Object, qualityProfileUpdater.Object);
_ = new BoundSolutionUpdateHandler(activeSolutionTracker.Object, suppressionUpdater.Object, serverHotspotStoreUpdater.Object, qualityProfileUpdater.Object);

activeSolutionTracker.Raise(x => x.SolutionBindingChanged += null, new ActiveSolutionBindingEventArgs(BindingConfiguration.Standalone));
suppressionIssueStoreUpdater.Verify(x => x.UpdateAllServerSuppressionsAsync(), Times.Once);
suppressionUpdater.Verify(x => x.UpdateAllServerSuppressionsAsync(), Times.Once);
serverHotspotStoreUpdater.Verify(x => x.UpdateAllServerHotspotsAsync(), Times.Once);
qualityProfileUpdater.Verify(x => x.UpdateAsync(), Times.Once);

activeSolutionTracker.Raise(x => x.SolutionBindingUpdated += null, EventArgs.Empty);
suppressionIssueStoreUpdater.Verify(x => x.UpdateAllServerSuppressionsAsync(), Times.Exactly(2));
suppressionUpdater.Verify(x => x.UpdateAllServerSuppressionsAsync(), Times.Exactly(2));
serverHotspotStoreUpdater.Verify(x => x.UpdateAllServerHotspotsAsync(), Times.Exactly(2));
qualityProfileUpdater.Verify(x => x.UpdateAsync(), Times.Exactly(2));
}
Expand All @@ -83,7 +82,7 @@ public void Dispose_UnsubscribesToEvent()
{
var activeSolutionTracker = new Mock<IActiveSolutionBoundTracker>();

var testSubject = new BoundSolutionUpdateHandler(activeSolutionTracker.Object, Mock.Of<ISuppressionIssueStoreUpdater>(), Mock.Of<IServerHotspotStoreUpdater>(), Mock.Of<IQualityProfileUpdater>());
var testSubject = new BoundSolutionUpdateHandler(activeSolutionTracker.Object, Mock.Of<ISuppressionUpdater>(), Mock.Of<IServerHotspotStoreUpdater>(), Mock.Of<IQualityProfileUpdater>());

testSubject.Dispose();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

using Microsoft.VisualStudio.TestTools.UnitTesting.Logging;
using SonarLint.VisualStudio.ConnectedMode.Binding;
using SonarLint.VisualStudio.ConnectedMode.Migration;
using SonarLint.VisualStudio.ConnectedMode.Shared;
Expand All @@ -37,11 +36,10 @@ public class ConnectedModeMigrationTests
{
private static readonly LegacySettings DefaultTestLegacySettings = new LegacySettings("folder", "cs ruleset", "cs xml", "vb ruleset", "vb xml");

private static BoundSonarQubeProject AnyBoundProject = new BoundSonarQubeProject(new Uri("http://localhost:9000"), "any-key", "any-name");
private static readonly BoundSonarQubeProject AnyBoundProject = new BoundSonarQubeProject(new Uri("http://localhost:9000"), "any-key", "any-name");

[TestMethod]
public void MefCtor_CheckTypeIsNonShared()
=> MefTestHelpers.CheckIsNonSharedMefComponent<ConnectedModeMigration>();
public void MefCtor_CheckTypeIsNonShared() => MefTestHelpers.CheckIsNonSharedMefComponent<ConnectedModeMigration>();

[TestMethod]
public void MefCtor_CheckIsExported()
Expand All @@ -53,7 +51,7 @@ public void MefCtor_CheckIsExported()
MefTestHelpers.CreateExport<IVsAwareFileSystem>(),
MefTestHelpers.CreateExport<ISonarQubeService>(),
MefTestHelpers.CreateExport<IUnintrusiveBindingController>(),
MefTestHelpers.CreateExport<ISuppressionIssueStoreUpdater>(),
MefTestHelpers.CreateExport<ISuppressionUpdater>(),
MefTestHelpers.CreateExport<ISharedBindingConfigProvider>(),
MefTestHelpers.CreateExport<ILogger>(),
MefTestHelpers.CreateExport<IThreadHandling>(),
Expand Down Expand Up @@ -399,13 +397,13 @@ public async Task Migrate_ConnectionsJsonFileDoesNotExistAndNewBindingsExist_Doe
serverConnectionsRepository: serverConnectionsRepositoryMock.Object,
unintrusiveBindingController: unintrusiveBindingControllerMock.Object,
unintrusiveBindingPathProvider: bindingPathProvider.Object,
logger:logger.Object);
logger: logger.Object);
serverConnectionsRepositoryMock.Setup(mock => mock.ConnectionsFileExists()).Returns(false);
bindingPathProvider.Setup(mock => mock.GetBindingPaths()).Returns(["binding1"]);

await testSubject.MigrateAsync(AnyBoundProject, Mock.Of<IProgress<MigrationProgress>>(), false, CancellationToken.None);

logger.Verify(x=> x.WriteLine(MigrationStrings.ConnectionsJson_DoesNotExist), Times.Once);
logger.Verify(x => x.WriteLine(MigrationStrings.ConnectionsJson_DoesNotExist), Times.Once);
serverConnectionsRepositoryMock.Verify(mock => mock.TryAdd(It.IsAny<ServerConnection>()), Times.Never);
unintrusiveBindingControllerMock.Verify(
x => x.BindAsync(
Expand All @@ -426,7 +424,7 @@ public async Task Migrate_ConnectionsJsonFileDoesNotExistAndNoNewBindingsExist_M
var testSubject = CreateTestSubject(
serverConnectionsRepository: serverConnectionsRepositoryMock.Object,
unintrusiveBindingController: unintrusiveBindingControllerMock.Object,
unintrusiveBindingPathProvider:bindingPathProvider.Object,
unintrusiveBindingPathProvider: bindingPathProvider.Object,
logger: logger.Object);
serverConnectionsRepositoryMock.Setup(mock => mock.ConnectionsFileExists()).Returns(false);
bindingPathProvider.Setup(mock => mock.GetBindingPaths()).Returns([]);
Expand Down Expand Up @@ -454,9 +452,9 @@ public void Migrate_InvalidServerInformation_Throws()
[TestMethod]
public async Task Migrate_RoslynSuppressionUpdateIsTriggered()
{
var suppressionsUpdater = new Mock<ISuppressionIssueStoreUpdater>();
var suppressionsUpdater = new Mock<ISuppressionUpdater>();

var testSubject = CreateTestSubject(suppressionIssueStoreUpdater: suppressionsUpdater.Object);
var testSubject = CreateTestSubject(suppressionUpdater: suppressionsUpdater.Object);
await testSubject.MigrateAsync(AnyBoundProject, null, false, CancellationToken.None);

suppressionsUpdater.Verify(x => x.UpdateAllServerSuppressionsAsync(), Times.Once);
Expand All @@ -467,7 +465,7 @@ public async Task Migrate_SwitchToBackgroundThread()
{
var threadHandling = new Mock<IThreadHandling>();
threadHandling.Setup(x => x.SwitchToBackgroundThread())
.Returns(() => new NoOpThreadHandler.NoOpAwaitable());
.Returns(() => new NoOpThreadHandler.NoOpAwaitable());

var testSubject = CreateTestSubject(threadHandling: threadHandling.Object);
await testSubject.MigrateAsync(AnyBoundProject, It.IsAny<IProgress<MigrationProgress>>(), false, CancellationToken.None);
Expand All @@ -482,7 +480,7 @@ private static ConnectedModeMigration CreateTestSubject(
IMigrationSettingsProvider settingsProvider = null,
ISonarQubeService sonarQubeService = null,
IUnintrusiveBindingController unintrusiveBindingController = null,
ISuppressionIssueStoreUpdater suppressionIssueStoreUpdater = null,
ISuppressionUpdater suppressionUpdater = null,
ISharedBindingConfigProvider sharedBindingConfigProvider = null,
ILogger logger = null,
IThreadHandling threadHandling = null,
Expand All @@ -495,7 +493,7 @@ private static ConnectedModeMigration CreateTestSubject(
fileSystem ??= Mock.Of<IVsAwareFileSystem>();
sonarQubeService ??= Mock.Of<ISonarQubeService>();
unintrusiveBindingController ??= Mock.Of<IUnintrusiveBindingController>();
suppressionIssueStoreUpdater ??= Mock.Of<ISuppressionIssueStoreUpdater>();
suppressionUpdater ??= Mock.Of<ISuppressionUpdater>();
settingsProvider ??= CreateSettingsProvider(DefaultTestLegacySettings).Object;
sharedBindingConfigProvider ??= Mock.Of<ISharedBindingConfigProvider>();
solutionInfoProvider ??= CreateSolutionInfoProviderMock().Object;
Expand All @@ -511,7 +509,7 @@ private static ConnectedModeMigration CreateTestSubject(
fileSystem,
sonarQubeService,
unintrusiveBindingController,
suppressionIssueStoreUpdater,
suppressionUpdater,
sharedBindingConfigProvider,
logger,
threadHandling,
Expand Down Expand Up @@ -555,7 +553,10 @@ private static Mock<IServerConnectionsRepository> CreateServerConnectionsReposit
return serverConnectionsRepositoryMock;
}

private static void MockIServerConnectionsRepositoryTryGet(Mock<IServerConnectionsRepository> serverConnectionsRepositoryMock, string id = null, ServerConnection.SonarQube storedConnection = null)
private static void MockIServerConnectionsRepositoryTryGet(
Mock<IServerConnectionsRepository> serverConnectionsRepositoryMock,
string id = null,
ServerConnection.SonarQube storedConnection = null)
{
serverConnectionsRepositoryMock.Setup(service => service.TryGet(id ?? It.IsAny<string>(), out It.Ref<ServerConnection>.IsAny))
.Returns((string _, out ServerConnection value) =>
Expand Down Expand Up @@ -589,32 +590,27 @@ namespace ConnectedModeMigrationTestsExtensions
{
internal static class MockExtensions
{
public static void SetupFileToClean(this Mock<IFileCleaner> fileCleaner, string input, string output)
=> fileCleaner.Setup(x => x.Clean(input, It.IsAny<LegacySettings>(), It.IsAny<CancellationToken>()))
public static void SetupFileToClean(this Mock<IFileCleaner> fileCleaner, string input, string output) =>
fileCleaner.Setup(x => x.Clean(input, It.IsAny<LegacySettings>(), It.IsAny<CancellationToken>()))
.Returns(output);

public static void VerifyFileCleaned(this Mock<IFileCleaner> fileCleaner, string expectedContent)
=> fileCleaner.Verify(x => x.Clean(expectedContent,
public static void VerifyFileCleaned(this Mock<IFileCleaner> fileCleaner, string expectedContent) =>
fileCleaner.Verify(x => x.Clean(expectedContent,
It.IsAny<LegacySettings>(),
It.IsAny<CancellationToken>()), Times.Once);

public static void AddFile(this Mock<IVsAwareFileSystem> fileSystem, string filePath, string content)
=> fileSystem.Setup(x => x.LoadAsTextAsync(filePath)).Returns(Task.FromResult(content));
public static void AddFile(this Mock<IVsAwareFileSystem> fileSystem, string filePath, string content) =>
fileSystem.Setup(x => x.LoadAsTextAsync(filePath)).Returns(Task.FromResult(content));

public static void VerifyFileLoaded(this Mock<IVsAwareFileSystem> fileSystem, string filePath)
=> fileSystem.Verify(x => x.LoadAsTextAsync(filePath), Times.Once);
public static void VerifyFileLoaded(this Mock<IVsAwareFileSystem> fileSystem, string filePath) => fileSystem.Verify(x => x.LoadAsTextAsync(filePath), Times.Once);

public static void VerifyFileSaved(this Mock<IVsAwareFileSystem> fileSystem, string filePath, string content)
=> fileSystem.Verify(x => x.SaveAsync(filePath, content), Times.Once);
public static void VerifyFileSaved(this Mock<IVsAwareFileSystem> fileSystem, string filePath, string content) => fileSystem.Verify(x => x.SaveAsync(filePath, content), Times.Once);

public static void VerifyFileNotSaved(this Mock<IVsAwareFileSystem> fileSystem, string filePath)
=> fileSystem.Verify(x => x.SaveAsync(filePath, It.IsAny<string>()), Times.Never);
public static void VerifyFileNotSaved(this Mock<IVsAwareFileSystem> fileSystem, string filePath) => fileSystem.Verify(x => x.SaveAsync(filePath, It.IsAny<string>()), Times.Never);

public static void VerifyNoFilesSaved(this Mock<IVsAwareFileSystem> fileSystem)
=> fileSystem.Verify(x => x.SaveAsync(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
public static void VerifyNoFilesSaved(this Mock<IVsAwareFileSystem> fileSystem) => fileSystem.Verify(x => x.SaveAsync(It.IsAny<string>(), It.IsAny<string>()), Times.Never);

public static void VerifyDirectoryDeleted(this Mock<IVsAwareFileSystem> fileSystem, string folderPath)
=> fileSystem.Verify(x => x.DeleteFolderAsync(folderPath), Times.Once);
public static void VerifyDirectoryDeleted(this Mock<IVsAwareFileSystem> fileSystem, string folderPath) => fileSystem.Verify(x => x.DeleteFolderAsync(folderPath), Times.Once);
}
}
}
Loading