diff --git a/src/Integration.UnitTests/MefServices/SharedBindingSuggestionServiceTests.cs b/src/Integration.UnitTests/MefServices/SharedBindingSuggestionServiceTests.cs index e418188a3..b0500738a 100644 --- a/src/Integration.UnitTests/MefServices/SharedBindingSuggestionServiceTests.cs +++ b/src/Integration.UnitTests/MefServices/SharedBindingSuggestionServiceTests.cs @@ -37,6 +37,7 @@ public class SharedBindingSuggestionServiceTests private IConnectedModeServices connectedModeServices; private IConnectedModeBindingServices connectedModeBindingServices; private IActiveSolutionTracker activeSolutionTracker; + private IConnectedModeUIManager connectedModeManager; [TestInitialize] public void TestInitialize() @@ -45,8 +46,9 @@ public void TestInitialize() connectedModeServices = Substitute.For(); connectedModeBindingServices = Substitute.For(); activeSolutionTracker = Substitute.For(); + connectedModeManager = Substitute.For(); - testSubject = new SharedBindingSuggestionService(suggestSharedBindingGoldBar, connectedModeServices, connectedModeBindingServices, activeSolutionTracker); + testSubject = new SharedBindingSuggestionService(suggestSharedBindingGoldBar, connectedModeServices, connectedModeBindingServices, connectedModeManager, activeSolutionTracker); } [TestMethod] @@ -56,6 +58,7 @@ public void MefCtor_CheckExports() MefTestHelpers.CreateExport(), MefTestHelpers.CreateExport(), MefTestHelpers.CreateExport(), + MefTestHelpers.CreateExport(), MefTestHelpers.CreateExport()); } @@ -127,6 +130,24 @@ public void Dispose_UnsubscribesFromActiveSolutionChanged() activeSolutionTracker.Received(1).ActiveSolutionChanged -= Arg.Any>(); } + [TestMethod] + public void ActiveSolutionChanged_SolutionIsOpened_ShowsGoldBarAndShowManageBindingDialog() + { + MockSharedBindingConfigExists(); + MockSolutionMode(SonarLintMode.Standalone); + Action showAction = null; + suggestSharedBindingGoldBar.When(x => x.Show(ServerType.SonarQube, Arg.Any())).Do(callInfo => + { + showAction = callInfo.Arg(); + }); + + RaiseActiveSolutionChanged(true); + showAction(); + + showAction.Should().NotBeNull(); + connectedModeManager.Received(1).ShowManageBindingDialog(true); + } + private void RaiseActiveSolutionChanged(bool isSolutionOpened) { activeSolutionTracker.ActiveSolutionChanged += Raise.EventWith(new ActiveSolutionChangedEventArgs(isSolutionOpened)); diff --git a/src/Integration.Vsix.UnitTests/Commands/PackageCommandManagerTests.cs b/src/Integration.Vsix.UnitTests/Commands/PackageCommandManagerTests.cs index 2d760d38e..f9b7a00f4 100644 --- a/src/Integration.Vsix.UnitTests/Commands/PackageCommandManagerTests.cs +++ b/src/Integration.Vsix.UnitTests/Commands/PackageCommandManagerTests.cs @@ -56,10 +56,10 @@ public void PackageCommandManager_Initialize() Mock.Of(), Mock.Of(), Mock.Of(), - Mock.Of(), Mock.Of(), Mock.Of(), -Mock.Of()); +Mock.Of(), + Mock.Of()); // Assert menuService.Commands.Should().HaveCountGreaterOrEqualTo(allCommands.Count, "Unexpected number of commands"); diff --git a/src/Integration.Vsix/Commands/ConnectedModeMenu/ManageConnectionsCommand.cs b/src/Integration.Vsix/Commands/ConnectedModeMenu/ManageConnectionsCommand.cs index 00e50d713..fa6210d87 100644 --- a/src/Integration.Vsix/Commands/ConnectedModeMenu/ManageConnectionsCommand.cs +++ b/src/Integration.Vsix/Commands/ConnectedModeMenu/ManageConnectionsCommand.cs @@ -18,28 +18,24 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -using System.Windows; using SonarLint.VisualStudio.ConnectedMode.UI; -using SonarLint.VisualStudio.ConnectedMode.UI.ManageBinding; namespace SonarLint.VisualStudio.Integration.Vsix.Commands.ConnectedModeMenu { [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] internal class ManageConnectionsCommand : VsCommandBase { - private readonly IConnectedModeServices connectedModeServices; - private readonly IConnectedModeBindingServices connectedModeBindingServices; + private readonly IConnectedModeUIManager connectedModeUiManager; internal const int Id = 0x102; - public ManageConnectionsCommand(IConnectedModeServices connectedModeServices, IConnectedModeBindingServices connectedModeBindingServices) + public ManageConnectionsCommand(IConnectedModeUIManager connectedModeUiManager) { - this.connectedModeServices = connectedModeServices; - this.connectedModeBindingServices = connectedModeBindingServices; + this.connectedModeUiManager = connectedModeUiManager; } protected override void InvokeInternal() { - new ManageBindingDialog(connectedModeServices, connectedModeBindingServices).ShowDialog(Application.Current.MainWindow); + connectedModeUiManager.ShowManageBindingDialog(); } } } diff --git a/src/Integration.Vsix/Commands/PackageCommandManager.cs b/src/Integration.Vsix/Commands/PackageCommandManager.cs index f64268c80..ac92f70ec 100644 --- a/src/Integration.Vsix/Commands/PackageCommandManager.cs +++ b/src/Integration.Vsix/Commands/PackageCommandManager.cs @@ -46,10 +46,10 @@ public void Initialize( IProjectPropertyManager projectPropertyManager, IOutputWindowService outputWindowService, IShowInBrowserService showInBrowserService, - IBrowserService browserService, ShowOptionsPage showOptionsPage, IConnectedModeServices connectedModeServices, - IConnectedModeBindingServices connectedModeBindingServices) + IConnectedModeBindingServices connectedModeBindingServices, + IConnectedModeUIManager connectedModeManager) { RegisterCommand((int)PackageCommandId.ProjectExcludePropertyToggle, new ProjectExcludePropertyToggleCommand(projectPropertyManager)); RegisterCommand((int)PackageCommandId.ProjectTestPropertyAuto, new ProjectTestPropertySetCommand(projectPropertyManager, null)); @@ -65,11 +65,11 @@ public void Initialize( // Help menu buttons RegisterCommand(CommonGuids.HelpMenuCommandSet, ShowLogsCommand.Id, new ShowLogsCommand(outputWindowService)); RegisterCommand(CommonGuids.HelpMenuCommandSet, ViewDocumentationCommand.Id, new ViewDocumentationCommand(showInBrowserService)); - RegisterCommand(CommonGuids.HelpMenuCommandSet, AboutCommand.Id, new AboutCommand(browserService)); + RegisterCommand(CommonGuids.HelpMenuCommandSet, AboutCommand.Id, new AboutCommand(connectedModeServices.BrowserService)); RegisterCommand(CommonGuids.HelpMenuCommandSet, ShowCommunityPageCommand.Id, new ShowCommunityPageCommand(showInBrowserService)); // Connected mode buttons - RegisterCommand(CommonGuids.ConnectedModeMenuCommandSet, ManageConnectionsCommand.Id, new ManageConnectionsCommand(connectedModeServices, connectedModeBindingServices)); + RegisterCommand(CommonGuids.ConnectedModeMenuCommandSet, ManageConnectionsCommand.Id, new ManageConnectionsCommand(connectedModeManager)); RegisterCommand(CommonGuids.ConnectedModeMenuCommandSet, SaveSharedConnectionCommand.Id, new SaveSharedConnectionCommand(connectedModeServices.ConfigurationProvider, connectedModeBindingServices.SharedBindingConfigProvider)); } diff --git a/src/Integration.Vsix/SonarLintIntegrationPackage.cs b/src/Integration.Vsix/SonarLintIntegrationPackage.cs index e90c26166..83c6f039a 100644 --- a/src/Integration.Vsix/SonarLintIntegrationPackage.cs +++ b/src/Integration.Vsix/SonarLintIntegrationPackage.cs @@ -96,10 +96,10 @@ private async Task InitOnUIThreadAsync() serviceProvider.GetMefService(), serviceProvider.GetMefService(), serviceProvider.GetMefService(), - serviceProvider.GetMefService(), ShowOptionPage, serviceProvider.GetMefService(), - serviceProvider.GetMefService()); + serviceProvider.GetMefService(), + serviceProvider.GetMefService()); this.roslynSettingsFileSynchronizer = await this.GetMefServiceAsync(); roslynSettingsFileSynchronizer.UpdateFileStorageAsync().Forget(); // don't wait for it to finish diff --git a/src/Integration/MefServices/SharedBindingSuggestionService.cs b/src/Integration/MefServices/SharedBindingSuggestionService.cs index 89cbf795e..49b0b53fa 100644 --- a/src/Integration/MefServices/SharedBindingSuggestionService.cs +++ b/src/Integration/MefServices/SharedBindingSuggestionService.cs @@ -41,6 +41,7 @@ internal sealed class SharedBindingSuggestionService : ISharedBindingSuggestionS private readonly ISuggestSharedBindingGoldBar suggestSharedBindingGoldBar; private readonly IConnectedModeServices connectedModeServices; private readonly IConnectedModeBindingServices connectedModeBindingServices; + private readonly IConnectedModeUIManager connectedModeUiManager; private readonly IActiveSolutionTracker activeSolutionTracker; [ImportingConstructor] @@ -48,11 +49,13 @@ public SharedBindingSuggestionService( ISuggestSharedBindingGoldBar suggestSharedBindingGoldBar, IConnectedModeServices connectedModeServices, IConnectedModeBindingServices connectedModeBindingServices, + IConnectedModeUIManager connectedModeUiManager, IActiveSolutionTracker activeSolutionTracker) { this.suggestSharedBindingGoldBar = suggestSharedBindingGoldBar; this.connectedModeServices = connectedModeServices; this.connectedModeBindingServices = connectedModeBindingServices; + this.connectedModeUiManager = connectedModeUiManager; this.activeSolutionTracker = activeSolutionTracker; this.activeSolutionTracker.ActiveSolutionChanged += OnActiveSolutionChanged; @@ -76,8 +79,7 @@ public void Dispose() private void ShowManageBindingDialog() { - var manageBindingDialog = new ManageBindingDialog(connectedModeServices, connectedModeBindingServices, useSharedBindingOnInitialization:true); - manageBindingDialog.ShowDialog(Application.Current.MainWindow); + connectedModeUiManager.ShowManageBindingDialog(useSharedBindingOnInitialization:true); } private void OnActiveSolutionChanged(object sender, ActiveSolutionChangedEventArgs e)