Skip to content

Commit

Permalink
SLVS-1688 Update Quality Profiles on solution open
Browse files Browse the repository at this point in the history
  • Loading branch information
georgii-borovinskikh-sonarsource committed Dec 10, 2024
1 parent 69acfc6 commit 1641c37
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
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

0 comments on commit 1641c37

Please sign in to comment.