Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SLVS-1491 Refactor: use ConnectedModeManager #5730

Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class SharedBindingSuggestionServiceTests
private IConnectedModeServices connectedModeServices;
private IConnectedModeBindingServices connectedModeBindingServices;
private IActiveSolutionTracker activeSolutionTracker;
private IConnectedModeUIManager connectedModeManager;

[TestInitialize]
public void TestInitialize()
Expand All @@ -45,8 +46,9 @@ public void TestInitialize()
connectedModeServices = Substitute.For<IConnectedModeServices>();
connectedModeBindingServices = Substitute.For<IConnectedModeBindingServices>();
activeSolutionTracker = Substitute.For<IActiveSolutionTracker>();
connectedModeManager = Substitute.For<IConnectedModeUIManager>();

testSubject = new SharedBindingSuggestionService(suggestSharedBindingGoldBar, connectedModeServices, connectedModeBindingServices, activeSolutionTracker);
testSubject = new SharedBindingSuggestionService(suggestSharedBindingGoldBar, connectedModeServices, connectedModeBindingServices, connectedModeManager, activeSolutionTracker);
}

[TestMethod]
Expand All @@ -56,6 +58,7 @@ public void MefCtor_CheckExports()
MefTestHelpers.CreateExport<ISuggestSharedBindingGoldBar>(),
MefTestHelpers.CreateExport<IConnectedModeServices>(),
MefTestHelpers.CreateExport<IConnectedModeBindingServices>(),
MefTestHelpers.CreateExport<IConnectedModeUIManager>(),
MefTestHelpers.CreateExport<IActiveSolutionTracker>());
}

Expand Down Expand Up @@ -127,6 +130,24 @@ public void Dispose_UnsubscribesFromActiveSolutionChanged()
activeSolutionTracker.Received(1).ActiveSolutionChanged -= Arg.Any<EventHandler<ActiveSolutionChangedEventArgs>>();
}

[TestMethod]
public void ActiveSolutionChanged_SolutionIsOpened_ShowsGoldBarAndShowManageBindingDialog()
{
MockSharedBindingConfigExists();
MockSolutionMode(SonarLintMode.Standalone);
Action showAction = null;
suggestSharedBindingGoldBar.When(x => x.Show(ServerType.SonarQube, Arg.Any<Action>())).Do(callInfo =>
{
showAction = callInfo.Arg<Action>();
});

RaiseActiveSolutionChanged(true);
showAction();

showAction.Should().NotBeNull();
connectedModeManager.Received(1).ShowManageBindingDialog(true);
}

private void RaiseActiveSolutionChanged(bool isSolutionOpened)
{
activeSolutionTracker.ActiveSolutionChanged += Raise.EventWith(new ActiveSolutionChangedEventArgs(isSolutionOpened));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ public void PackageCommandManager_Initialize()
Mock.Of<IProjectPropertyManager>(),
Mock.Of<IOutputWindowService>(),
Mock.Of<IShowInBrowserService>(),
Mock.Of<IBrowserService>(),
Mock.Of<PackageCommandManager.ShowOptionsPage>(),
Mock.Of<IConnectedModeServices>(),
Mock.Of<IConnectedModeBindingServices>());
Mock.Of<IConnectedModeBindingServices>(),
Mock.Of<IConnectedModeUIManager>());

// Assert
menuService.Commands.Should().HaveCountGreaterOrEqualTo(allCommands.Count, "Unexpected number of commands");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
8 changes: 4 additions & 4 deletions src/Integration.Vsix/Commands/PackageCommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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));
}

Expand Down
4 changes: 2 additions & 2 deletions src/Integration.Vsix/SonarLintIntegrationPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ private async Task InitOnUIThreadAsync()
serviceProvider.GetMefService<IProjectPropertyManager>(),
serviceProvider.GetMefService<IOutputWindowService>(),
serviceProvider.GetMefService<IShowInBrowserService>(),
serviceProvider.GetMefService<IBrowserService>(),
ShowOptionPage,
serviceProvider.GetMefService<IConnectedModeServices>(),
serviceProvider.GetMefService<IConnectedModeBindingServices>());
serviceProvider.GetMefService<IConnectedModeBindingServices>(),
serviceProvider.GetMefService<IConnectedModeUIManager>());

this.roslynSettingsFileSynchronizer = await this.GetMefServiceAsync<IRoslynSettingsFileSynchronizer>();
roslynSettingsFileSynchronizer.UpdateFileStorageAsync().Forget(); // don't wait for it to finish
Expand Down
6 changes: 4 additions & 2 deletions src/Integration/MefServices/SharedBindingSuggestionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,21 @@ 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]
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;
Expand All @@ -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)
Expand Down