public void ServerViewModel_SetProjects() { // Setup var connInfo = new ConnectionInformation(new Uri("https://myawesomeserver:1234/")); var viewModel = new ServerViewModel(connInfo); IEnumerable<ProjectInformation> projects = new[] { new ProjectInformation { Name = "Project3", Key="1" }, new ProjectInformation { Name = "Project2", Key="2" }, new ProjectInformation { Name = "project1", Key="3" }, }; string[] expectedOrderedProjectNames = projects.Select(p => p.Name).OrderBy(n => n, StringComparer.CurrentCulture).ToArray(); // Act viewModel.SetProjects(projects); // Verify string[] actualProjectNames = viewModel.Projects.Select(p => p.ProjectInformation.Name).OrderBy(n => n, StringComparer.CurrentCulture).ToArray(); CollectionAssert.AreEqual( expectedOrderedProjectNames, actualProjectNames, message: $"VM projects [{string.Join(", ", actualProjectNames)}] do not match the expected projects [{string.Join(", ", expectedOrderedProjectNames)}]" ); // Act again var newProject = new ProjectInformation(); viewModel.SetProjects(new[] { newProject }); // Verify that the collection was replaced with the new one Assert.AreSame(newProject, viewModel.Projects.SingleOrDefault()?.ProjectInformation, "Expected a single project to be present"); }
public void TransferableVisualState_BoundProjectManagement() { // Setup var testSubject = new TransferableVisualState(); var server = new ServerViewModel(new Integration.Service.ConnectionInformation(new System.Uri("http://server"))); var project1 = new ProjectViewModel(server, new Integration.Service.ProjectInformation()); var project2 = new ProjectViewModel(server, new Integration.Service.ProjectInformation()); // Act (bind to something) testSubject.SetBoundProject(project1); // Verify Assert.IsTrue(testSubject.HasBoundProject); Assert.IsTrue(project1.IsBound); Assert.IsFalse(project2.IsBound); Assert.IsFalse(server.ShowAllProjects); // Act (bind to something else) testSubject.SetBoundProject(project2); // Verify Assert.IsTrue(testSubject.HasBoundProject); Assert.IsFalse(project1.IsBound); Assert.IsTrue(project2.IsBound); Assert.IsFalse(server.ShowAllProjects); // Act(clear binding) testSubject.ClearBoundProject(); // Verify Assert.IsFalse(testSubject.HasBoundProject); Assert.IsFalse(project1.IsBound); Assert.IsFalse(project2.IsBound); Assert.IsTrue(server.ShowAllProjects); }
public ProjectViewModel(ServerViewModel owner, SonarQubeProject projectInformation) { if (owner == null) { throw new ArgumentNullException(nameof(owner)); } if (projectInformation == null) { throw new ArgumentNullException(nameof(projectInformation)); } this.Owner = owner; this.Project = projectInformation; }
public ProjectViewModel(ServerViewModel owner, ProjectInformation projectInformation) { if (owner == null) { throw new ArgumentNullException(nameof(owner)); } if (projectInformation == null) { throw new ArgumentNullException(nameof(projectInformation)); } this.Owner = owner; this.ProjectInformation = projectInformation; }
public void ServerViewModel_Ctor() { // Setup var connInfo = new ConnectionInformation(new Uri("https://myawesomeserver:1234/")); IEnumerable<ProjectInformation> projects = new[] { new ProjectInformation { Name = "Project1", Key="1" }, new ProjectInformation { Name = "Project2", Key="2" }, new ProjectInformation { Name = "Project3", Key="3" }, new ProjectInformation { Name = "Project4", Key="4" } }; string[] projectKeys = projects.Select(x => x.Key).ToArray(); // Case 0: default constructed state // Act var emptyViewModel = new ServerViewModel(connInfo); // Verify Assert.IsTrue(emptyViewModel.IsExpanded); Assert.IsFalse(emptyViewModel.ShowAllProjects); // Case 1, projects with default IsExpanded value // Act var viewModel = new ServerViewModel(connInfo); viewModel.SetProjects(projects); // Verify string[] vmProjectKeys = viewModel.Projects.Select(x => x.Key).ToArray(); Assert.IsTrue(viewModel.ShowAllProjects); Assert.IsTrue(viewModel.IsExpanded); Assert.AreEqual(connInfo.ServerUri, viewModel.Url); CollectionAssert.AreEqual( expected: projectKeys, actual: vmProjectKeys, message: $"VM projects [{string.Join(", ", vmProjectKeys)}] do not match input projects [{string.Join(", ", projectKeys)}]" ); // Case 2, null projects with non default IsExpanded value // Act var viewModel2 = new ServerViewModel(connInfo, isExpanded: false); // Verify Assert.AreEqual(0, viewModel2.Projects.Count, "Not expecting projects"); Assert.IsFalse(viewModel2.IsExpanded); }
private void ToggleShowAllProjects(ServerViewModel server) { TelemetryLoggerAccessor.GetLogger(this.ServiceProvider)?.ReportEvent(TelemetryEvent.ToggleShowAllProjectsCommandCommandCalled); server.ShowAllProjects = !server.ShowAllProjects; }
private bool CanToggleShowAllProjects(ServerViewModel server) { return server.Projects.Any(x => x.IsBound); }
private void SetServerProjectsVMCommands(ServerViewModel serverVM) { foreach (ProjectViewModel projectVM in serverVM.Projects) { projectVM.Commands.Clear(); if (this.Host.ActiveSection == null) { // Don't add command (which will be disabled). continue; } var bindContextCommand = new ContextualCommandViewModel(projectVM, this.Host.ActiveSection.BindCommand); bindContextCommand.SetDynamicDisplayText(x => { var ctx = x as ProjectViewModel; Debug.Assert(ctx != null, "Unexpected fixed context for bind context command"); return ctx?.IsBound ?? false ? Strings.SyncButtonText : Strings.BindButtonText; }); bindContextCommand.SetDynamicIcon(x => { var ctx = x as ProjectViewModel; Debug.Assert(ctx != null, "Unexpected fixed context for bind context command"); return new IconViewModel(ctx?.IsBound ?? false ? KnownMonikers.Sync : KnownMonikers.Link); }); var openProjectDashboardCommand = new ContextualCommandViewModel(projectVM, this.Host.ActiveSection.BrowseToProjectDashboardCommand) { DisplayText = Strings.ViewInSonarQubeMenuItemDisplayText, Tooltip = Strings.ViewInSonarQubeMenuItemTooltip, Icon = new IconViewModel(KnownMonikers.OpenWebSite) }; projectVM.Commands.Add(bindContextCommand); projectVM.Commands.Add(openProjectDashboardCommand); } }
private void SetServerVMCommands(ServerViewModel serverVM) { serverVM.Commands.Clear(); if (this.Host.ActiveSection == null) { // Don't add command (which will be disabled). return; } var refreshContextualCommand = new ContextualCommandViewModel(serverVM, this.Host.ActiveSection.RefreshCommand) { DisplayText = Strings.RefreshCommandDisplayText, Tooltip = Strings.RefreshCommandTooltip, Icon = new IconViewModel(KnownMonikers.Refresh) }; var disconnectContextualCommand = new ContextualCommandViewModel(serverVM, this.Host.ActiveSection.DisconnectCommand) { DisplayText = Strings.DisconnectCommandDisplayText, Tooltip = Strings.DisconnectCommandTooltip, Icon = new IconViewModel(KnownMonikers.Disconnect) }; var browseServerContextualCommand = new ContextualCommandViewModel(serverVM.Url.ToString(), this.Host.ActiveSection.BrowseToUrlCommand) { DisplayText = Strings.BrowseServerMenuItemDisplayText, Tooltip = Strings.BrowserServerMenuItemTooltip, Icon = new IconViewModel(KnownMonikers.OpenWebSite) }; var toggleShowAllProjectsCommand = new ContextualCommandViewModel(serverVM, this.Host.ActiveSection.ToggleShowAllProjectsCommand) { Tooltip = Strings.ToggleShowAllProjectsCommandTooltip }; toggleShowAllProjectsCommand.SetDynamicDisplayText(x => { ServerViewModel ctx = x as ServerViewModel; Debug.Assert(ctx != null, "Unexpected fixed context for ToggleShowAllProjects context command"); return ctx?.ShowAllProjects ?? false ? Strings.HideUnboundProjectsCommandText : Strings.ShowAllProjectsCommandText; }); serverVM.Commands.Add(refreshContextualCommand); serverVM.Commands.Add(disconnectContextualCommand); serverVM.Commands.Add(browseServerContextualCommand); serverVM.Commands.Add(toggleShowAllProjectsCommand); }
private void RestoreBoundProject(ServerViewModel serverViewModel) { if (this.BoundProjectKey == null) { // Nothing to restore return; } ProjectInformation boundProject = serverViewModel.Projects.FirstOrDefault(pvm => ProjectInformation.KeyComparer.Equals(pvm.Key, this.BoundProjectKey))?.ProjectInformation; if (boundProject == null) { // Defensive coding: invoked asynchronous and it's safer to assume that value could be null // and just not do anything since if they are null it means that there's no solution open. this.Host.ActiveSection?.UserNotifications?.ShowNotificationError(string.Format(CultureInfo.CurrentCulture, Strings.BoundProjectNotFound, this.BoundProjectKey), NotificationIds.FailedToFindBoundProjectKeyId, null); } else { this.SetBoundProject(boundProject); } }
public void ServerViewModel_AutomationName() { // Setup var connInfo = new ConnectionInformation(new Uri("https://myawesomeserver:1234/")); var testSubject = new ServerViewModel(connInfo); var projects = new[] { new ProjectInformation { Key = "P", Name = "A Project" } }; var expectedProjects = string.Format(CultureInfo.CurrentCulture, Strings.AutomationServerDescription, connInfo.ServerUri); var expectedNoProjects = string.Format(CultureInfo.CurrentCulture, Strings.AutomationServerNoProjectsDescription, connInfo.ServerUri); // Test case 1: no projects // Act var actualNoProjects = testSubject.AutomationName; // Verify Assert.AreEqual(expectedNoProjects, actualNoProjects, "Unexpected description of SonarQube server without projects"); // Test case 2: projects // Act testSubject.SetProjects(projects); var actualProjects = testSubject.AutomationName; // Verify Assert.AreEqual(expectedProjects, actualProjects, "Unexpected description of SonarQube server with projects"); }
private void ToggleShowAllProjects(ServerViewModel server) { server.ShowAllProjects = !server.ShowAllProjects; }
public void SectionController_BrowseToProjectDashboardCommand() { // Setup var webBrowser = new ConfigurableWebBrowser(); var testSubject = this.CreateTestSubject(webBrowser); var serverUrl = new Uri("http://my-sonar-server:5555"); var connectionInfo = new ConnectionInformation(serverUrl); var projectInfo = new ProjectInformation { Key = "p1" }; Uri expectedUrl = new Uri(serverUrl, string.Format(SonarQubeServiceWrapper.ProjectDashboardRelativeUrl, projectInfo.Key)); this.sonarQubeService.RegisterProjectDashboardUrl(connectionInfo, projectInfo, expectedUrl); // Case 1: Null parameter // Act + Verify CanExecute Assert.IsFalse(testSubject.BrowseToProjectDashboardCommand.CanExecute(null)); // Case 2: Project VM var serverViewModel = new ServerViewModel(connectionInfo); var projectViewModel = new ProjectViewModel(serverViewModel, projectInfo); // Act + Verify CanExecute Assert.IsTrue(testSubject.BrowseToProjectDashboardCommand.CanExecute(projectViewModel)); // Act + Verify Execute testSubject.BrowseToProjectDashboardCommand.Execute(projectViewModel); webBrowser.AssertNavigateToCalls(1); webBrowser.AssertRequestToNavigateTo(expectedUrl.ToString()); }
public void SectionController_ToggleShowAllProjectsCommand() { // Setup var testSubject = this.CreateTestSubject(); var connInfo = new ConnectionInformation(new Uri("http://localhost")); var projectInfo = new ProjectInformation { Key = "p1", Name = "proj1" }; var server = new ServerViewModel(connInfo); var project = new ProjectViewModel(server, projectInfo); server.Projects.Add(project); // Case 1: No bound projects project.IsBound = false; // Act + Verify CanExecute Assert.IsFalse(testSubject.ToggleShowAllProjectsCommand.CanExecute(server)); // Case 2: Bound project.IsBound = true; // Act + Verify Assert.IsTrue(testSubject.ToggleShowAllProjectsCommand.CanExecute(server)); // Verify execution bool original = server.ShowAllProjects; // Act testSubject.ToggleShowAllProjectsCommand.Execute(server); // Verify Assert.AreEqual(!original, server.ShowAllProjects); // Act testSubject.ToggleShowAllProjectsCommand.Execute(server); // Verify Assert.AreEqual(original, server.ShowAllProjects); }
private static void VerifyNoCommands(ServerViewModel serverVM) { AssertExpectedNumberOfCommands(serverVM.Commands, 0); Assert.AreEqual(0, serverVM.Projects.Sum(p => p.Commands.Count), "Not expecting any project commands"); }
private void ToggleShowAllProjects(ServerViewModel server) { ServiceProvider.GetMefService <ITelemetryLogger>()?.ReportEvent(TelemetryEvent.ToggleShowAllProjectsCommandCommandCalled); server.ShowAllProjects = !server.ShowAllProjects; }
private static void VerifySectionCommands(ISectionController section, ServerViewModel serverVM) { AssertExpectedNumberOfCommands(serverVM.Commands, 4); VerifyServerViewModelCommand(serverVM, section.DisconnectCommand, fixedContext: serverVM, hasIcon: true); VerifyServerViewModelCommand(serverVM, section.RefreshCommand, fixedContext: serverVM, hasIcon: true); VerifyServerViewModelCommand(serverVM, section.BrowseToUrlCommand, fixedContext: serverVM.ConnectionInformation.ServerUri, hasIcon: true); VerifyServerViewModelCommand(serverVM, section.ToggleShowAllProjectsCommand, fixedContext: serverVM, hasIcon: false); foreach (ProjectViewModel project in serverVM.Projects) { AssertExpectedNumberOfCommands(project.Commands, 2); VerifyProjectViewModelCommand(project, section.BindCommand, fixedContext: project, hasIcon: true); VerifyProjectViewModelCommand(project, section.BrowseToProjectDashboardCommand, fixedContext: project, hasIcon: true); } }
private bool CanToggleShowAllProjects(ServerViewModel server) { return(server.Projects.Any(x => x.IsBound)); }
private static void VerifyServerViewModelCommand(ServerViewModel serverVM, ICommand internalCommand, object fixedContext, bool hasIcon) { ContextualCommandViewModel commandVM = AssertCommandExists(serverVM.Commands, internalCommand); Assert.IsNotNull(commandVM.DisplayText, "DisplayText expected"); Assert.AreEqual(fixedContext, commandVM.InternalFixedContext, "The fixed context is incorrect"); if (hasIcon) { Assert.IsNotNull(commandVM.Icon, "Icon expected"); Assert.IsNotNull(commandVM.Icon.Moniker, "Icon moniker expected"); } else { Assert.IsNull(commandVM.Icon, "Icon not expected"); } }
private ProjectViewModel ConfigureProjectViewModel(ConfigurableSectionController section, Uri serverUri, string projectKey) { if (serverUri == null) { Assert.Inconclusive("Test setup: the server uri is not valid"); } if (string.IsNullOrWhiteSpace(projectKey)) { Assert.Inconclusive("Test setup: the project key is not valid"); } section.ViewModel.State.ConnectedServers.Clear(); var serverVM = new ServerViewModel(new ConnectionInformation(serverUri)); section.ViewModel.State.ConnectedServers.Add(serverVM); var projectVM = new ProjectViewModel(serverVM, new ProjectInformation { Key = projectKey }); serverVM.Projects.Add(projectVM); return projectVM; }
private void SetProjectsUIThread(ConnectionInformation connection, IEnumerable<ProjectInformation> projects) { Debug.Assert(connection != null); this.ClearBindingErrorNotifications(); // !!! Avoid using the service to detect disconnects since it's not thread safe !!! if (projects == null) { // Disconnected, clear all this.ClearBoundProject(); this.DisposeConnections(); this.ManagedState.ConnectedServers.Clear(); } else { var existingServerVM = this.ManagedState.ConnectedServers.SingleOrDefault(serverVM => serverVM.Url == connection.ServerUri); ServerViewModel serverViewModel; if (existingServerVM == null) { // Add new server serverViewModel = new ServerViewModel(connection); this.SetServerVMCommands(serverViewModel); this.ManagedState.ConnectedServers.Add(serverViewModel); } else { // Update existing server serverViewModel = existingServerVM; } serverViewModel.SetProjects(projects); Debug.Assert(serverViewModel.ShowAllProjects, "ShowAllProjects should have been set"); this.SetServerProjectsVMCommands(serverViewModel); this.RestoreBoundProject(serverViewModel); } }