Skip to content

Commit

Permalink
Change ProjectRootCalculator to use IActiveSolutionBoundTracker (#5071)
Browse files Browse the repository at this point in the history
Fixes #5070
  • Loading branch information
georgii-borovinskikh-sonarsource authored Dec 1, 2023
1 parent 07d802e commit 7870ad7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions src/ConnectedMode.UnitTests/ProjectRootCalculatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void MefCtor_CheckIsExported()
{
MefTestHelpers.CheckTypeCanBeImported<ProjectRootCalculator, IProjectRootCalculator>(
MefTestHelpers.CreateExport<ISonarQubeService>(),
MefTestHelpers.CreateExport<IConfigurationProvider>(),
MefTestHelpers.CreateExport<IActiveSolutionBoundTracker>(),
MefTestHelpers.CreateExport<IStatefulServerBranchProvider>());
}

Expand All @@ -49,7 +49,7 @@ public void MefCtor_CheckIsSingleton()
public async Task CalculateBasedOnLocalPathAsync_StandaloneMode_ReturnsNull()
{
var testSubject = CreateTestSubject(out _, out var configurationProviderMock, out _);
configurationProviderMock.Setup(x => x.GetConfiguration()).Returns(BindingConfiguration.Standalone);
configurationProviderMock.SetupGet(x => x.CurrentConfiguration).Returns(BindingConfiguration.Standalone);

var result = await testSubject.CalculateBasedOnLocalPathAsync(@"c:\somepath", CancellationToken.None);

Expand All @@ -64,7 +64,7 @@ public async Task CalculateBasedOnLocalPathAsync_ConnectedMode_ReturnsCorrectRoo

var testSubject = CreateTestSubject(out var sonarQubeServiceMock, out var configurationProviderMock, out var branchProviderMock);
configurationProviderMock
.Setup(x => x.GetConfiguration())
.SetupGet(x => x.CurrentConfiguration)
.Returns(BindingConfiguration.CreateBoundConfiguration(
new BoundSonarQubeProject(){ProjectKey = projectKey},
SonarLintMode.Connected,
Expand All @@ -82,11 +82,11 @@ public async Task CalculateBasedOnLocalPathAsync_ConnectedMode_ReturnsCorrectRoo
}

private ProjectRootCalculator CreateTestSubject(out Mock<ISonarQubeService> sonarQubeServiceMock,
out Mock<IConfigurationProvider> configurationProviderMock,
out Mock<IActiveSolutionBoundTracker> activeSolutionBoundTracker,
out Mock<IStatefulServerBranchProvider> statefulServerBranchProviderMock)
{
return new ProjectRootCalculator((sonarQubeServiceMock = new Mock<ISonarQubeService>(MockBehavior.Strict)).Object,
(configurationProviderMock = new Mock<IConfigurationProvider>(MockBehavior.Strict)).Object,
(activeSolutionBoundTracker = new Mock<IActiveSolutionBoundTracker>(MockBehavior.Strict)).Object,
(statefulServerBranchProviderMock = new Mock<IStatefulServerBranchProvider>(MockBehavior.Strict)).Object);
}
}
8 changes: 4 additions & 4 deletions src/ConnectedMode/ProjectRootCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,20 @@ internal interface IProjectRootCalculator
internal class ProjectRootCalculator : IProjectRootCalculator
{
private readonly ISonarQubeService sonarQubeService;
private readonly IConfigurationProvider configurationProvider;
private readonly IActiveSolutionBoundTracker activeSolutionBoundTracker;
private readonly IStatefulServerBranchProvider branchProvider;

[ImportingConstructor]
public ProjectRootCalculator(ISonarQubeService sonarQubeService, IConfigurationProvider configurationProvider, IStatefulServerBranchProvider branchProvider)
public ProjectRootCalculator(ISonarQubeService sonarQubeService, IActiveSolutionBoundTracker activeSolutionBoundTracker, IStatefulServerBranchProvider branchProvider)
{
this.sonarQubeService = sonarQubeService;
this.configurationProvider = configurationProvider;
this.activeSolutionBoundTracker = activeSolutionBoundTracker;
this.branchProvider = branchProvider;
}

public async Task<string> CalculateBasedOnLocalPathAsync(string localPath, CancellationToken token)
{
var bindingConfiguration = configurationProvider.GetConfiguration();
var bindingConfiguration = activeSolutionBoundTracker.CurrentConfiguration;

if (bindingConfiguration.Mode == SonarLintMode.Standalone)
{
Expand Down

0 comments on commit 7870ad7

Please sign in to comment.