diff --git a/src/ConnectedMode.UnitTests/Binding/UnintrusiveBindingControllerTests.cs b/src/ConnectedMode.UnitTests/Binding/UnintrusiveBindingControllerTests.cs index 9d0c44769..d91cb2fee 100644 --- a/src/ConnectedMode.UnitTests/Binding/UnintrusiveBindingControllerTests.cs +++ b/src/ConnectedMode.UnitTests/Binding/UnintrusiveBindingControllerTests.cs @@ -98,7 +98,7 @@ public async Task BindAsync_NotifiesBindingChanged() activeSolutionChangedHandler .Received(1) - .HandleBindingChange(false); + .HandleBindingChange(); } [TestMethod] @@ -126,7 +126,7 @@ public void Unbind_BindingDeletionSucceeded_HandlesBindingChangesAndDisconnects( { solutionBindingRepository.DeleteBinding(AnyBoundProject.LocalBindingKey); sonarQubeService.Disconnect(); - activeSolutionChangedHandler.HandleBindingChange(true); + activeSolutionChangedHandler.HandleBindingChange(); }); } @@ -138,7 +138,7 @@ public void Unbind_BindingDeletionFailed_DoesNotCallHandleBindingChange() testSubject.Unbind(AnyBoundProject.LocalBindingKey); solutionBindingRepository.Received(1).DeleteBinding(AnyBoundProject.LocalBindingKey); - activeSolutionChangedHandler.DidNotReceive().HandleBindingChange(true); + activeSolutionChangedHandler.DidNotReceive().HandleBindingChange(); } [TestMethod] diff --git a/src/ConnectedMode/Binding/IUnintrusiveBindingController.cs b/src/ConnectedMode/Binding/IUnintrusiveBindingController.cs index d638d0d73..0431afa0d 100644 --- a/src/ConnectedMode/Binding/IUnintrusiveBindingController.cs +++ b/src/ConnectedMode/Binding/IUnintrusiveBindingController.cs @@ -66,7 +66,7 @@ public async Task BindAsync(BoundServerProject project, CancellationToken cancel var connectionInformation = new ConnectionInformation(project.ServerConnection.ServerUri, project.ServerConnection.Credentials); await sonarQubeService.ConnectAsync(connectionInformation, cancellationToken); await BindAsync(project, null, cancellationToken); - activeSolutionChangedHandler.HandleBindingChange(false); + activeSolutionChangedHandler.HandleBindingChange(); } public async Task BindAsync(BoundServerProject project, IProgress progress, CancellationToken token) @@ -81,7 +81,7 @@ public bool Unbind(string localBindingKey) if (bindingDeleted) { sonarQubeService.Disconnect(); - activeSolutionChangedHandler.HandleBindingChange(true); + activeSolutionChangedHandler.HandleBindingChange(); } return bindingDeleted; } diff --git a/src/Core/Binding/IActiveSolutionBoundTracker.cs b/src/Core/Binding/IActiveSolutionBoundTracker.cs index 77821efe2..342c830fa 100644 --- a/src/Core/Binding/IActiveSolutionBoundTracker.cs +++ b/src/Core/Binding/IActiveSolutionBoundTracker.cs @@ -24,7 +24,7 @@ namespace SonarLint.VisualStudio.Core.Binding { public interface IActiveSolutionChangedHandler { - void HandleBindingChange(bool isBindingCleared); + void HandleBindingChange(); } /// diff --git a/src/Integration.UnitTests/MefServices/ActiveSolutionBoundTrackerTests.cs b/src/Integration.UnitTests/MefServices/ActiveSolutionBoundTrackerTests.cs index 1723121dc..4c348d2d0 100644 --- a/src/Integration.UnitTests/MefServices/ActiveSolutionBoundTrackerTests.cs +++ b/src/Integration.UnitTests/MefServices/ActiveSolutionBoundTrackerTests.cs @@ -190,7 +190,7 @@ public void ActiveSolutionBoundTracker_UnBoundProject_NullPassedToConfigScopeUpd configScopeUpdaterMock.Verify(x => x.UpdateConfigScopeForCurrentSolution(null)); configScopeUpdaterMock.VerifyNoOtherCalls(); } - + [TestMethod] public void ActiveSolutionBoundTracker_Changes() { @@ -220,7 +220,7 @@ public void ActiveSolutionBoundTracker_Changes() activeSolutionTracker.CurrentSolutionName = "solution1"; // Act - testSubject.HandleBindingChange(true); + testSubject.HandleBindingChange(); // Assert testSubject.CurrentConfiguration.Mode.Should().Be(SonarLintMode.Standalone, "Unbound solution should report false activation"); @@ -237,7 +237,7 @@ public void ActiveSolutionBoundTracker_Changes() // Case 2: Set bound project ConfigureSolutionBinding(boundSonarQubeProject); // Act - testSubject.HandleBindingChange(false); + testSubject.HandleBindingChange(); // Assert testSubject.CurrentConfiguration.Mode.Should().Be(SonarLintMode.Connected, "Bound solution should report true activation"); @@ -309,7 +309,7 @@ public void ActiveSolutionBoundTracker_Changes() // Act testSubject.Dispose(); ConfigureSolutionBinding(boundSonarQubeProject); - testSubject.HandleBindingChange(true); + testSubject.HandleBindingChange(); // Assert eventCounter.PreSolutionBindingChangedCount.Should().Be(5, "Once disposed should stop raising the event"); @@ -420,14 +420,14 @@ public void UpdateConnection_Disconnect_ServiceDisconnectedIsCalled() } [TestMethod] - public void HandleBindingChange_WhenClearBoundProject_NotRaised() + public void HandleBindingChange_WhenSameProject_NotRaised() { // Arrange using var testSubject = CreateTestSubject(activeSolutionTracker, configProvider, loggerMock.Object); var eventCounter = new EventCounter(testSubject); // Act - testSubject.HandleBindingChange(true); + testSubject.HandleBindingChange(); // Assert eventCounter.PreSolutionBindingUpdatedCount.Should().Be(0); @@ -437,24 +437,21 @@ public void HandleBindingChange_WhenClearBoundProject_NotRaised() } [TestMethod] - public void HandleBindingChange_WhenSetBoundProject_EventsRaisedInExpectedOrder() + public void HandleBindingChange_WhenProjectChanged_RaisedChangedEvents() { // Arrange using var testSubject = CreateTestSubject(activeSolutionTracker, configProvider, loggerMock.Object); var eventCounter = new EventCounter(testSubject); + ConfigureSolutionBinding(boundSonarQubeProject); // Act - testSubject.HandleBindingChange(false); + testSubject.HandleBindingChange(); // Assert - eventCounter.PreSolutionBindingUpdatedCount.Should().Be(1); - eventCounter.SolutionBindingUpdatedCount.Should().Be(1); - eventCounter.PreSolutionBindingChangedCount.Should().Be(0); - eventCounter.SolutionBindingChangedCount.Should().Be(0); - - eventCounter.RaisedEventNames.Should().HaveCount(2); - eventCounter.RaisedEventNames[0].Should().Be(nameof(testSubject.PreSolutionBindingUpdated)); - eventCounter.RaisedEventNames[1].Should().Be(nameof(testSubject.SolutionBindingUpdated)); + eventCounter.PreSolutionBindingUpdatedCount.Should().Be(0); + eventCounter.SolutionBindingUpdatedCount.Should().Be(0); + eventCounter.PreSolutionBindingChangedCount.Should().Be(1); + eventCounter.SolutionBindingChangedCount.Should().Be(1); } [TestMethod] diff --git a/src/Integration/MefServices/ActiveSolutionBoundTracker.cs b/src/Integration/MefServices/ActiveSolutionBoundTracker.cs index b96e7e926..c0d977011 100644 --- a/src/Integration/MefServices/ActiveSolutionBoundTracker.cs +++ b/src/Integration/MefServices/ActiveSolutionBoundTracker.cs @@ -90,14 +90,14 @@ public ActiveSolutionBoundTracker([Import(typeof(SVsServiceProvider))] IServiceP this.gitEventsMonitor.HeadChanged += GitEventsMonitor_HeadChanged; } - public void HandleBindingChange(bool isBindingCleared) + public void HandleBindingChange() { if (disposed) { return; } - this.RaiseAnalyzersChangedIfBindingChanged(GetBindingConfiguration(), isBindingCleared); + this.RaiseAnalyzersChangedIfBindingChanged(GetBindingConfiguration()); } private BindingConfiguration GetBindingConfiguration() @@ -162,7 +162,7 @@ private async Task UpdateConnectionAsync(BindingConfiguration bindingConfi return isConnected; } - private void RaiseAnalyzersChangedIfBindingChanged(BindingConfiguration newBindingConfiguration, bool? isBindingCleared = null) + private void RaiseAnalyzersChangedIfBindingChanged(BindingConfiguration newBindingConfiguration) { configScopeUpdater.UpdateConfigScopeForCurrentSolution(newBindingConfiguration.Project); @@ -174,11 +174,6 @@ private void RaiseAnalyzersChangedIfBindingChanged(BindingConfiguration newBindi PreSolutionBindingChanged?.Invoke(this, args); SolutionBindingChanged?.Invoke(this, args); } - else if (isBindingCleared == false) - { // todo remove unreachable code & cleanup https://sonarsource.atlassian.net/browse/SLVS-1532 - PreSolutionBindingUpdated?.Invoke(this, EventArgs.Empty); - SolutionBindingUpdated?.Invoke(this, EventArgs.Empty); - } SetBoundSolutionUIContext(); }