Skip to content

Commit

Permalink
SLVS-1563 Provide new configScope
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriela-trutan-sonarsource committed Oct 29, 2024
1 parent dbd6b41 commit ee2ef1e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
30 changes: 17 additions & 13 deletions src/SLCore.UnitTests/State/ActiveConfigScopeTrackerTests.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.ComponentModel;
using SonarLint.VisualStudio.Core;
using SonarLint.VisualStudio.Core.Synchronization;
using SonarLint.VisualStudio.SLCore.Core;
Expand All @@ -39,7 +38,7 @@ public class ActiveConfigScopeTrackerTests
private ISLCoreServiceProvider serviceProvider;
private IAsyncLockFactory asyncLockFactory;
private IThreadHandling threadHandling;
private EventHandler currentConfigScopeChangedEventHandler;
private EventHandler<ConfigurationScope> currentConfigScopeChangedEventHandler;

[TestInitialize]
public void TestInitialize()
Expand All @@ -52,7 +51,7 @@ public void TestInitialize()
threadHandling = Substitute.For<IThreadHandling>();
ConfigureServiceProvider(isServiceAvailable:true);
ConfigureAsyncLockFactory();
currentConfigScopeChangedEventHandler = Substitute.For<EventHandler>();
currentConfigScopeChangedEventHandler = Substitute.For<EventHandler<ConfigurationScope>>();

testSubject = new ActiveConfigScopeTracker(serviceProvider, asyncLockFactory, threadHandling);
testSubject.CurrentConfigurationScopeChanged += currentConfigScopeChangedEventHandler;
Expand Down Expand Up @@ -84,7 +83,7 @@ public void SetCurrentConfigScope_SetsUnboundScope()
VerifyThreadHandling();
VerifyServiceAddCall();
VerifyLockTakenSynchronouslyAndReleased();
VerifyCurrentConfigurationScopeChangedRaised();
VerifyCurrentConfigurationScopeChangedRaised(configScopeId);
}

[TestMethod]
Expand All @@ -100,7 +99,7 @@ public void TryUpdateRootOnCurrentConfigScope_ConfigScopeSame_Updates()

result.Should().BeTrue();
testSubject.currentConfigScope.Should().BeEquivalentTo(new ConfigurationScope(configScopeId, connectionId, sonarProjectKey, "some root", isReady));
VerifyCurrentConfigurationScopeChangedRaised();
VerifyCurrentConfigurationScopeChangedRaised(configScopeId);
}

[TestMethod]
Expand Down Expand Up @@ -132,7 +131,7 @@ public void TryUpdateAnalysisReadinessOnCurrentConfigScope_ConfigScopeSame_Updat

result.Should().BeTrue();
testSubject.currentConfigScope.Should().BeEquivalentTo(new ConfigurationScope(configScopeId, connectionId, sonarProjectKey, root, true));
VerifyCurrentConfigurationScopeChangedRaised();
VerifyCurrentConfigurationScopeChangedRaised(configScopeId);
}

[TestMethod]
Expand Down Expand Up @@ -164,7 +163,7 @@ public void SetCurrentConfigScope_SetsBoundScope()
VerifyThreadHandling();
VerifyServiceAddCall();
VerifyLockTakenSynchronouslyAndReleased();
VerifyCurrentConfigurationScopeChangedRaised();
VerifyCurrentConfigurationScopeChangedRaised(configScopeId);
}

[TestMethod]
Expand All @@ -184,7 +183,7 @@ public void SetCurrentConfigScope_CurrentScopeExists_UpdatesBoundScope()
VerifyThreadHandling();
VerifyServiceUpdateCall();
VerifyLockTakenSynchronouslyAndReleased();
VerifyCurrentConfigurationScopeChangedRaised();
VerifyCurrentConfigurationScopeChangedRaised(configScopeId);
}

[TestMethod]
Expand Down Expand Up @@ -225,7 +224,7 @@ public void RemoveCurrentConfigScope_RemovesScope()
configScopeService.Received().DidRemoveConfigurationScope(Arg.Is<DidRemoveConfigurationScopeParams>(p => p.removedId == configScopeId));
VerifyThreadHandling();
VerifyLockTakenSynchronouslyAndReleased();
VerifyCurrentConfigurationScopeChangedRaised();
VerifyCurrentConfigurationScopeChangedRaised(null);
}

[TestMethod]
Expand Down Expand Up @@ -295,7 +294,7 @@ public void Reset_SetsCurrentScopeToNull()
serviceProvider.ReceivedCalls().Count().Should().Be(0);
VerifyThreadHandling();
VerifyLockTakenSynchronouslyAndReleased();
VerifyCurrentConfigurationScopeChangedRaised();
VerifyCurrentConfigurationScopeChangedRaised(null);
}

[TestMethod]
Expand Down Expand Up @@ -352,14 +351,19 @@ private void ConfigureServiceProvider(bool isServiceAvailable)
});
}

private void VerifyCurrentConfigurationScopeChangedRaised()
private void VerifyCurrentConfigurationScopeChangedRaised(string configScopeId)
{
currentConfigScopeChangedEventHandler.Received(1).Invoke(testSubject, Arg.Any<EventArgs>());
currentConfigScopeChangedEventHandler.Received(1).Invoke(testSubject, Arg.Is<ConfigurationScope>(c => IsSameConfigScope(c, configScopeId)));
}

private bool IsSameConfigScope(ConfigurationScope configurationScope, string configScopeId)
{
return configurationScope?.Id == configScopeId;
}

private void VerifyCurrentConfigurationScopeChangedNotRaised()
{
currentConfigScopeChangedEventHandler.DidNotReceive().Invoke(testSubject, Arg.Any<EventArgs>());
currentConfigScopeChangedEventHandler.DidNotReceive().Invoke(testSubject, Arg.Any<ConfigurationScope>());
}

private class ConfigurationScopeDtoComparer : IEqualityComparer<ConfigurationScopeDto>
Expand Down
6 changes: 3 additions & 3 deletions src/SLCore/State/ActiveConfigScopeTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public interface IActiveConfigScopeTracker : IDisposable

bool TryUpdateAnalysisReadinessOnCurrentConfigScope(string id, bool isReady);

event EventHandler CurrentConfigurationScopeChanged;
event EventHandler<ConfigurationScope> CurrentConfigurationScopeChanged;
}

public record ConfigurationScope(
Expand Down Expand Up @@ -184,7 +184,7 @@ public bool TryUpdateAnalysisReadinessOnCurrentConfigScope(string id, bool isRea
}
}

public event EventHandler CurrentConfigurationScopeChanged;
public event EventHandler<ConfigurationScope> CurrentConfigurationScopeChanged;

public void Dispose()
{
Expand All @@ -197,6 +197,6 @@ private BindingConfigurationDto GetBinding(string connectionId, string sonarProj

private void OnCurrentConfigurationScopeChanged()
{
CurrentConfigurationScopeChanged?.Invoke(this, EventArgs.Empty);
CurrentConfigurationScopeChanged?.Invoke(this, currentConfigScope);
}
}

0 comments on commit ee2ef1e

Please sign in to comment.