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-1688 Update Quality Profiles on solution open #5884

Merged
Merged
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
13 changes: 9 additions & 4 deletions src/ConnectedMode.UnitTests/BoundSolutionUpdateHandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

using System;
using SonarLint.VisualStudio.ConnectedMode.Hotspots;
using SonarLint.VisualStudio.ConnectedMode.QualityProfiles;
using SonarLint.VisualStudio.ConnectedMode.Suppressions;
using SonarLint.VisualStudio.Core.Binding;
using SonarLint.VisualStudio.TestInfrastructure;
Expand All @@ -35,7 +36,8 @@ public void MefCtor_CheckIsExported()
MefTestHelpers.CheckTypeCanBeImported<BoundSolutionUpdateHandler, BoundSolutionUpdateHandler>(
MefTestHelpers.CreateExport<IActiveSolutionBoundTracker>(),
MefTestHelpers.CreateExport<ISuppressionIssueStoreUpdater>(),
MefTestHelpers.CreateExport<IServerHotspotStoreUpdater>());
MefTestHelpers.CreateExport<IServerHotspotStoreUpdater>(),
MefTestHelpers.CreateExport<IQualityProfileUpdater>());
}

[TestMethod]
Expand All @@ -49,7 +51,7 @@ public void Ctor_SubscribesToEvents()
{
var activeSolutionTracker = new Mock<IActiveSolutionBoundTracker>();

_ = new BoundSolutionUpdateHandler(activeSolutionTracker.Object, Mock.Of<ISuppressionIssueStoreUpdater>(), Mock.Of<IServerHotspotStoreUpdater>());
_ = new BoundSolutionUpdateHandler(activeSolutionTracker.Object, Mock.Of<ISuppressionIssueStoreUpdater>(), 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,24 +63,27 @@ public void InvokeEvents_ServerStoreUpdatersAreCalled()
var activeSolutionTracker = new Mock<IActiveSolutionBoundTracker>();
var suppressionIssueStoreUpdater = new Mock<ISuppressionIssueStoreUpdater>();
var serverHotspotStoreUpdater = new Mock<IServerHotspotStoreUpdater>();
var qualityProfileUpdater = new Mock<IQualityProfileUpdater>();

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

activeSolutionTracker.Raise(x => x.SolutionBindingChanged += null, new ActiveSolutionBindingEventArgs(BindingConfiguration.Standalone));
suppressionIssueStoreUpdater.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));
serverHotspotStoreUpdater.Verify(x => x.UpdateAllServerHotspotsAsync(), Times.Exactly(2));
qualityProfileUpdater.Verify(x => x.UpdateAsync(), Times.Exactly(2));
}

[TestMethod]
public void Dispose_UnsubscribesToEvent()
{
var activeSolutionTracker = new Mock<IActiveSolutionBoundTracker>();

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

testSubject.Dispose();

Expand Down
7 changes: 6 additions & 1 deletion src/ConnectedMode/BoundSolutionUpdateHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using System.ComponentModel.Composition;
using Microsoft.VisualStudio.Threading;
using SonarLint.VisualStudio.ConnectedMode.Hotspots;
using SonarLint.VisualStudio.ConnectedMode.QualityProfiles;
using SonarLint.VisualStudio.ConnectedMode.Suppressions;
using SonarLint.VisualStudio.Core.Binding;

Expand All @@ -34,17 +35,20 @@ internal sealed class BoundSolutionUpdateHandler : IDisposable
private readonly IActiveSolutionBoundTracker activeSolutionBoundTracker;
private readonly ISuppressionIssueStoreUpdater suppressionIssueStoreUpdater;
private readonly IServerHotspotStoreUpdater serverHotspotStoreUpdater;
private readonly IQualityProfileUpdater qualityProfileUpdater;

private bool disposed;

[ImportingConstructor]
public BoundSolutionUpdateHandler(IActiveSolutionBoundTracker activeSolutionBoundTracker,
ISuppressionIssueStoreUpdater suppressionIssueStoreUpdater,
IServerHotspotStoreUpdater serverHotspotStoreUpdater)
IServerHotspotStoreUpdater serverHotspotStoreUpdater,
IQualityProfileUpdater qualityProfileUpdater)
{
this.activeSolutionBoundTracker = activeSolutionBoundTracker;
this.suppressionIssueStoreUpdater = suppressionIssueStoreUpdater;
this.serverHotspotStoreUpdater = serverHotspotStoreUpdater;
this.qualityProfileUpdater = qualityProfileUpdater;

this.activeSolutionBoundTracker.SolutionBindingChanged += OnSolutionBindingChanged;
this.activeSolutionBoundTracker.SolutionBindingUpdated += OnSolutionBindingUpdated;
Expand All @@ -58,6 +62,7 @@ private void TriggerUpdate()
{
suppressionIssueStoreUpdater.UpdateAllServerSuppressionsAsync().Forget();
serverHotspotStoreUpdater.UpdateAllServerHotspotsAsync().Forget();
qualityProfileUpdater.UpdateAsync().Forget();
}

public void Dispose()
Expand Down
Loading