Skip to content

Commit

Permalink
SLVS-1721 Call DisplayBindStatusAsync after unbinding instead of Afte…
Browse files Browse the repository at this point in the history
…rUnbind.
  • Loading branch information
gabriela-trutan-sonarsource committed Dec 18, 2024
1 parent 6c083cc commit 2534474
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,7 @@ await progressReporterViewModel.Received(1)
x.TaskToPerform == testSubject.UnbindAsync &&
x.ProgressStatus == UiResources.UnbindingInProgressText &&
x.WarningText == UiResources.UnbindingFailedText &&
x.AfterProgressUpdated == testSubject.OnProgressUpdated &&
x.AfterSuccess == testSubject.AfterUnbind));
}

[TestMethod]
public async Task UnbindAsync_UnbindsOnUIThread()
{
await testSubject.UnbindAsync();

await threadHandling.Received(1).RunOnUIThreadAsync(Arg.Any<Action>());
x.AfterProgressUpdated == testSubject.OnProgressUpdated));
}

[TestMethod]
Expand All @@ -239,7 +230,6 @@ public async Task UnbindAsync_UnbindsCurrentSolution()
public async Task UnbindAsync_ReturnsResponseOfUnbinding(bool expectedResponse)
{
await InitializeBoundProject();
connectedModeServices.ThreadHandling.Returns(new NoOpThreadHandler());
connectedModeBindingServices.BindingController.Unbind(Arg.Any<string>()).Returns(expectedResponse);

var adapterResponse = await testSubject.UnbindAsync();
Expand All @@ -250,10 +240,9 @@ public async Task UnbindAsync_ReturnsResponseOfUnbinding(bool expectedResponse)
[TestMethod]
public async Task UnbindAsync_UnbindingThrows_ReturnsFalse()
{
await InitializeBoundProject();
var exceptionMsg = "Failed to load connections";
var mockedThreadHandling = Substitute.For<IThreadHandling>();
connectedModeServices.ThreadHandling.Returns(mockedThreadHandling);
mockedThreadHandling.When(x => x.RunOnUIThreadAsync(Arg.Any<Action>())).Do(_ => throw new Exception(exceptionMsg));
connectedModeBindingServices.BindingController.When(x => x.Unbind(Arg.Any<string>())).Do(_ => throw new Exception(exceptionMsg));

var adapterResponse = await testSubject.UnbindAsync();

Expand All @@ -262,23 +251,14 @@ public async Task UnbindAsync_UnbindingThrows_ReturnsFalse()
}

[TestMethod]
public void AfterUnbind_SetsBoundProjectToNull()
public async Task UnbindAsync_ClearsBindingProperties()
{
testSubject.BoundProject = serverProject;
await InitializeBoundProject();
SetupConfigurationProvider(new BindingConfiguration(null, SonarLintMode.Standalone, null));

testSubject.AfterUnbind(new AdapterResponse(true));
await testSubject.UnbindAsync();

testSubject.BoundProject.Should().BeNull();
}

[TestMethod]
public void AfterUnbind_SetsConnectionInfoToNull()
{
testSubject.SelectedConnectionInfo = sonarQubeConnectionInfo;
testSubject.SelectedProject = serverProject;

testSubject.AfterUnbind(new AdapterResponse(true));

testSubject.SelectedConnectionInfo.Should().BeNull();
testSubject.SelectedProject.Should().BeNull();
}
Expand Down Expand Up @@ -1079,19 +1059,22 @@ private void MockTryGetServerConnection(ServerConnection expectedServerConnectio

private void SetupUnboundProject()
{
var configurationProvider = Substitute.For<IConfigurationProvider>();
configurationProvider.GetConfiguration().Returns(new BindingConfiguration(null, SonarLintMode.Standalone, null));
connectedModeServices.ConfigurationProvider.Returns(configurationProvider);
SetupConfigurationProvider(new BindingConfiguration(null, SonarLintMode.Standalone, null));

MockGetServerProjectByKey(false, null);
}

private void SetupBoundProjectThatDoesNotExistOnServer(ServerConnection serverConnection)
private void SetupConfigurationProvider(BindingConfiguration bindingConfiguration)
{
var boundServerProject = new BoundServerProject(ALocalProjectKey, "a-server-project", serverConnection);
var configurationProvider = Substitute.For<IConfigurationProvider>();
configurationProvider.GetConfiguration().Returns(new BindingConfiguration(boundServerProject, SonarLintMode.Connected, "binding-dir"));
configurationProvider.GetConfiguration().Returns(bindingConfiguration);
connectedModeServices.ConfigurationProvider.Returns(configurationProvider);
}

private void SetupBoundProjectThatDoesNotExistOnServer(ServerConnection serverConnection)
{
var boundServerProject = new BoundServerProject(ALocalProjectKey, "a-server-project", serverConnection);
SetupConfigurationProvider(new BindingConfiguration(boundServerProject, SonarLintMode.Connected, "binding-dir"));

MockGetServerProjectByKey(false, null);
}
Expand Down
16 changes: 6 additions & 10 deletions src/ConnectedMode/UI/ManageBinding/ManageBindingViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,8 @@ public async Task UseSharedBindingWithProgressAsync()

public async Task UnbindWithProgressAsync()
{
var bind = new TaskToPerformParams<AdapterResponse>(UnbindAsync, UiResources.UnbindingInProgressText, UiResources.UnbindingFailedText)
{
AfterSuccess = AfterUnbind, AfterProgressUpdated = OnProgressUpdated
};
await ProgressReporter.ExecuteTaskWithProgressAsync(bind);
var unbind = new TaskToPerformParams<AdapterResponse>(UnbindAsync, UiResources.UnbindingInProgressText, UiResources.UnbindingFailedText) { AfterProgressUpdated = OnProgressUpdated };
await ProgressReporter.ExecuteTaskWithProgressAsync(unbind);
}

public async Task ExportBindingConfigurationAsync()
Expand Down Expand Up @@ -255,7 +252,7 @@ internal bool LoadConnections()
if (bindingConfiguration == null || bindingConfiguration.Mode == SonarLintMode.Standalone)
{
var successResponse = new AdapterResponse(true);
AfterUnbind(successResponse);
UpdateBoundProjectProperties(null, null);
return successResponse;
}

Expand Down Expand Up @@ -283,10 +280,11 @@ internal bool LoadConnections()

internal async Task<AdapterResponse> UnbindAsync()
{
var succeeded = false;
bool succeeded;
try
{
await connectedModeServices.ThreadHandling.RunOnUIThreadAsync(() => succeeded = connectedModeBindingServices.BindingController.Unbind(SolutionInfo.Name));
succeeded = connectedModeBindingServices.BindingController.Unbind(SolutionInfo.Name);
await DisplayBindStatusAsync();
}
catch (Exception ex)
{
Expand All @@ -297,8 +295,6 @@ internal async Task<AdapterResponse> UnbindAsync()
return new AdapterResponse(succeeded);
}

internal void AfterUnbind(AdapterResponse obj) => UpdateBoundProjectProperties(null, null);

private async Task<AdapterResponse> BindAsync(ServerConnection serverConnection, string serverProjectKey)
{
try
Expand Down

0 comments on commit 2534474

Please sign in to comment.