From 2534474cdb38e80f363b616cf9465c3ae634df3e Mon Sep 17 00:00:00 2001 From: Gabriela Trutan Date: Wed, 18 Dec 2024 13:25:48 +0100 Subject: [PATCH] SLVS-1721 Call DisplayBindStatusAsync after unbinding instead of AfterUnbind. --- .../ManageBindingViewModelTests.cs | 49 ++++++------------- .../ManageBinding/ManageBindingViewModel.cs | 16 +++--- 2 files changed, 22 insertions(+), 43 deletions(-) diff --git a/src/ConnectedMode.UnitTests/UI/ManageBinding/ManageBindingViewModelTests.cs b/src/ConnectedMode.UnitTests/UI/ManageBinding/ManageBindingViewModelTests.cs index 65c42e376..eb524d86a 100644 --- a/src/ConnectedMode.UnitTests/UI/ManageBinding/ManageBindingViewModelTests.cs +++ b/src/ConnectedMode.UnitTests/UI/ManageBinding/ManageBindingViewModelTests.cs @@ -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()); + x.AfterProgressUpdated == testSubject.OnProgressUpdated)); } [TestMethod] @@ -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()).Returns(expectedResponse); var adapterResponse = await testSubject.UnbindAsync(); @@ -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(); - connectedModeServices.ThreadHandling.Returns(mockedThreadHandling); - mockedThreadHandling.When(x => x.RunOnUIThreadAsync(Arg.Any())).Do(_ => throw new Exception(exceptionMsg)); + connectedModeBindingServices.BindingController.When(x => x.Unbind(Arg.Any())).Do(_ => throw new Exception(exceptionMsg)); var adapterResponse = await testSubject.UnbindAsync(); @@ -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(); } @@ -1079,19 +1059,22 @@ private void MockTryGetServerConnection(ServerConnection expectedServerConnectio private void SetupUnboundProject() { - var configurationProvider = Substitute.For(); - 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(); - 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); } diff --git a/src/ConnectedMode/UI/ManageBinding/ManageBindingViewModel.cs b/src/ConnectedMode/UI/ManageBinding/ManageBindingViewModel.cs index 5e910edf2..34870826e 100644 --- a/src/ConnectedMode/UI/ManageBinding/ManageBindingViewModel.cs +++ b/src/ConnectedMode/UI/ManageBinding/ManageBindingViewModel.cs @@ -164,11 +164,8 @@ public async Task UseSharedBindingWithProgressAsync() public async Task UnbindWithProgressAsync() { - var bind = new TaskToPerformParams(UnbindAsync, UiResources.UnbindingInProgressText, UiResources.UnbindingFailedText) - { - AfterSuccess = AfterUnbind, AfterProgressUpdated = OnProgressUpdated - }; - await ProgressReporter.ExecuteTaskWithProgressAsync(bind); + var unbind = new TaskToPerformParams(UnbindAsync, UiResources.UnbindingInProgressText, UiResources.UnbindingFailedText) { AfterProgressUpdated = OnProgressUpdated }; + await ProgressReporter.ExecuteTaskWithProgressAsync(unbind); } public async Task ExportBindingConfigurationAsync() @@ -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; } @@ -283,10 +280,11 @@ internal bool LoadConnections() internal async Task 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) { @@ -297,8 +295,6 @@ internal async Task UnbindAsync() return new AdapterResponse(succeeded); } - internal void AfterUnbind(AdapterResponse obj) => UpdateBoundProjectProperties(null, null); - private async Task BindAsync(ServerConnection serverConnection, string serverProjectKey) { try