From b920961e2590c54b18e704710a09d4b6d763d948 Mon Sep 17 00:00:00 2001 From: Gabriela Trutan Date: Thu, 26 Sep 2024 14:49:32 +0200 Subject: [PATCH] SLVS-1465 Use shared binding: show message when credentials do not exist (#5704) --- .../ManageBindingViewModelTests.cs | 39 ++++++++++++++ src/ConnectedMode/Resources.Designer.cs | 10 ++++ src/ConnectedMode/Resources.resx | 3 ++ .../UI/ManageBinding/ManageBindingDialog.xaml | 2 +- .../ManageBinding/ManageBindingViewModel.cs | 51 ++++++++++++++----- .../UI/Resources/UiResources.Designer.cs | 20 ++++++++ .../UI/Resources/UiResources.resx | 9 ++-- 7 files changed, 117 insertions(+), 17 deletions(-) diff --git a/src/ConnectedMode.UnitTests/UI/ManageBinding/ManageBindingViewModelTests.cs b/src/ConnectedMode.UnitTests/UI/ManageBinding/ManageBindingViewModelTests.cs index 2447a2a7c..5efc3af96 100644 --- a/src/ConnectedMode.UnitTests/UI/ManageBinding/ManageBindingViewModelTests.cs +++ b/src/ConnectedMode.UnitTests/UI/ManageBinding/ManageBindingViewModelTests.cs @@ -852,6 +852,43 @@ await bindingController.DidNotReceive() proj.ServerProjectKey == testSubject.SharedBindingConfigModel.ProjectKey), Arg.Any()); } + [TestMethod] + public async Task UseSharedBindingAsync_SharedBindingSonarCloudConnectionWithMissingCredentials_ReturnsFalseAndLogsAndInformsUser() + { + testSubject.SharedBindingConfigModel = sonarCloudSharedBindingConfigModel; + var expectedServerConnection = new ServerConnection.SonarCloud(testSubject.SharedBindingConfigModel.Organization); + SetupBoundProject(expectedServerConnection); + expectedServerConnection.Credentials = null; + + var response = await testSubject.UseSharedBindingAsync(); + + response.Success.Should().BeFalse(); + logger.WriteLine(Resources.UseSharedBinding_CredentiasNotFound, testSubject.SharedBindingConfigModel.Organization); + messageBox.Received(1).Show(UiResources.NotFoundCredentialsForSharedBindingMessageBoxText, UiResources.NotFoundCredentialsForSharedBindingMessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Warning); + await bindingController.DidNotReceive() + .BindAsync(Arg.Is(proj => + proj.ServerProjectKey == testSubject.SharedBindingConfigModel.ProjectKey), Arg.Any()); + } + + + [TestMethod] + public async Task UseSharedBindingAsync_SharedBindingSonarQubeConnectionWithMissingCredentials_ReturnsFalseAndLogsAndInformsUser() + { + testSubject.SharedBindingConfigModel = sonarQubeSharedBindingConfigModel; + var expectedServerConnection = new ServerConnection.SonarQube(testSubject.SharedBindingConfigModel.Uri); + SetupBoundProject(expectedServerConnection); + expectedServerConnection.Credentials = null; + + var response = await testSubject.UseSharedBindingAsync(); + + response.Success.Should().BeFalse(); + logger.WriteLine(Resources.UseSharedBinding_CredentiasNotFound, testSubject.SharedBindingConfigModel.Uri); + messageBox.Received(1).Show(UiResources.NotFoundCredentialsForSharedBindingMessageBoxText, UiResources.NotFoundCredentialsForSharedBindingMessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Warning); + await bindingController.DidNotReceive() + .BindAsync(Arg.Is(proj => + proj.ServerProjectKey == testSubject.SharedBindingConfigModel.ProjectKey), Arg.Any()); + } + [TestMethod] public async Task UseSharedBindingAsync_BindingFails_ReturnsFalse() { @@ -866,6 +903,7 @@ public async Task UseSharedBindingAsync_BindingFails_ReturnsFalse() response.Success.Should().BeFalse(); } + private void MockServices() { serverConnectionsRepositoryAdapter = Substitute.For(); @@ -908,6 +946,7 @@ private void SetupBoundProject(ServerConnection serverConnection, ServerProject { expectedServerProject ??= serverProject; + serverConnection.Credentials = validCredentials; var boundServerProject = new BoundServerProject(ALocalProjectKey, expectedServerProject.Key, serverConnection); var configurationProvider = Substitute.For(); configurationProvider.GetConfiguration().Returns(new BindingConfiguration(boundServerProject, SonarLintMode.Connected, "binding-dir")); diff --git a/src/ConnectedMode/Resources.Designer.cs b/src/ConnectedMode/Resources.Designer.cs index 6c345152a..897fc6f43 100644 --- a/src/ConnectedMode/Resources.Designer.cs +++ b/src/ConnectedMode/Resources.Designer.cs @@ -1,6 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. +// Runtime Version:4.0.30319.42000 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -653,6 +654,15 @@ internal static string UseSharedBinding_ConnectionNotFound { } } + /// + /// Looks up a localized string similar to [ConnectedMode/UseSharedBinding] The credentials for the connection {0} could not be found. + /// + internal static string UseSharedBinding_CredentiasNotFound { + get { + return ResourceManager.GetString("UseSharedBinding_CredentiasNotFound", resourceCulture); + } + } + /// /// Looks up a localized string similar to [ConnectedMode] Validating credentials failed. /// diff --git a/src/ConnectedMode/Resources.resx b/src/ConnectedMode/Resources.resx index cddfd4dd1..93a17b553 100644 --- a/src/ConnectedMode/Resources.resx +++ b/src/ConnectedMode/Resources.resx @@ -325,4 +325,7 @@ Unexpected server connection type + + [ConnectedMode/UseSharedBinding] The credentials for the connection {0} could not be found + \ No newline at end of file diff --git a/src/ConnectedMode/UI/ManageBinding/ManageBindingDialog.xaml b/src/ConnectedMode/UI/ManageBinding/ManageBindingDialog.xaml index 60c28a15a..4e70f647c 100644 --- a/src/ConnectedMode/UI/ManageBinding/ManageBindingDialog.xaml +++ b/src/ConnectedMode/UI/ManageBinding/ManageBindingDialog.xaml @@ -63,7 +63,7 @@