From 1641c372553e3c09baea620e6bccd3503be270bc Mon Sep 17 00:00:00 2001 From: Georgii Borovinskikh Date: Tue, 10 Dec 2024 14:39:03 +0100 Subject: [PATCH] SLVS-1688 Update Quality Profiles on solution open --- .../BoundSolutionUpdateHandlerTests.cs | 13 +++++++++---- src/ConnectedMode/BoundSolutionUpdateHandler.cs | 7 ++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/ConnectedMode.UnitTests/BoundSolutionUpdateHandlerTests.cs b/src/ConnectedMode.UnitTests/BoundSolutionUpdateHandlerTests.cs index 894fdff43f..fb9f941ceb 100644 --- a/src/ConnectedMode.UnitTests/BoundSolutionUpdateHandlerTests.cs +++ b/src/ConnectedMode.UnitTests/BoundSolutionUpdateHandlerTests.cs @@ -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; @@ -35,7 +36,8 @@ public void MefCtor_CheckIsExported() MefTestHelpers.CheckTypeCanBeImported( MefTestHelpers.CreateExport(), MefTestHelpers.CreateExport(), - MefTestHelpers.CreateExport()); + MefTestHelpers.CreateExport(), + MefTestHelpers.CreateExport()); } [TestMethod] @@ -49,7 +51,7 @@ public void Ctor_SubscribesToEvents() { var activeSolutionTracker = new Mock(); - _ = new BoundSolutionUpdateHandler(activeSolutionTracker.Object, Mock.Of(), Mock.Of()); + _ = new BoundSolutionUpdateHandler(activeSolutionTracker.Object, Mock.Of(), Mock.Of(), Mock.Of()); activeSolutionTracker.VerifyAdd(x => x.SolutionBindingChanged += It.IsAny>(), Times.Once); activeSolutionTracker.VerifyAdd(x => x.SolutionBindingUpdated += It.IsAny(), Times.Once); @@ -61,16 +63,19 @@ public void InvokeEvents_ServerStoreUpdatersAreCalled() var activeSolutionTracker = new Mock(); var suppressionIssueStoreUpdater = new Mock(); var serverHotspotStoreUpdater = new Mock(); + var qualityProfileUpdater = new Mock(); - _ = 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] @@ -78,7 +83,7 @@ public void Dispose_UnsubscribesToEvent() { var activeSolutionTracker = new Mock(); - var testSubject = new BoundSolutionUpdateHandler(activeSolutionTracker.Object, Mock.Of(), Mock.Of()); + var testSubject = new BoundSolutionUpdateHandler(activeSolutionTracker.Object, Mock.Of(), Mock.Of(), Mock.Of()); testSubject.Dispose(); diff --git a/src/ConnectedMode/BoundSolutionUpdateHandler.cs b/src/ConnectedMode/BoundSolutionUpdateHandler.cs index 5c8811e43d..ac4eeac6b2 100644 --- a/src/ConnectedMode/BoundSolutionUpdateHandler.cs +++ b/src/ConnectedMode/BoundSolutionUpdateHandler.cs @@ -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; @@ -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; @@ -58,6 +62,7 @@ private void TriggerUpdate() { suppressionIssueStoreUpdater.UpdateAllServerSuppressionsAsync().Forget(); serverHotspotStoreUpdater.UpdateAllServerHotspotsAsync().Forget(); + qualityProfileUpdater.UpdateAsync().Forget(); } public void Dispose()