示例#1
0
        private static void TestPluginSupport(bool expectedResult, string vsVersion, SonarQubePlugin installedPlugin,
                                              MinimumSupportedSonarQubePlugin minimumSupportedPlugin,
                                              string expectedMessage)
        {
            // Arrange
            VisualStudioHelpers.VisualStudioVersion = vsVersion;
            var logger = new TestLogger();

            // Act
            var result = ConnectionWorkflow.IsSonarQubePluginSupported(new[] { installedPlugin }, minimumSupportedPlugin, logger);

            // Assert
            result.Should().Be(expectedResult);
            logger.AssertOutputStrings(expectedMessage);
        }
        private async Task ConnectionWorkflow_ConnectionStep_WhenXPluginAndNoXProject_AbortsWorkflowAndDisconnects(string projectName, string projectKind, MinimumSupportedSonarQubePlugin minimumSupportedSonarQubePlugin)
        {
            // Arrange
            var connectionInfo = new ConnectionInformation(new Uri("http://server"));
            var projects       = new List <SonarQubeProject> {
                new SonarQubeProject("project1", "")
            };

            this.sonarQubeServiceMock.Setup(x => x.GetAllProjectsAsync(It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(projects);
            this.sonarQubeServiceMock.Setup(x => x.GetAllPluginsAsync(It.IsAny <CancellationToken>()))
            .ReturnsAsync(new List <SonarQubePlugin> {
                new SonarQubePlugin(minimumSupportedSonarQubePlugin.Key, minimumSupportedSonarQubePlugin.MinimumVersion)
            });
            this.projectSystemHelper.Projects = new[] { new ProjectMock(projectName)
                                                        {
                                                            ProjectKind = projectKind
                                                        } };
            bool projectChangedCallbackCalled = false;

            this.host.TestStateManager.SetProjectsAction = (c, p) =>
            {
                projectChangedCallbackCalled = true;
                c.Should().Be(connectionInfo, "Unexpected connection");
                CollectionAssert.AreEqual(projects, p.ToArray(), "Unexpected projects");
            };

            var    controller        = new ConfigurableProgressController();
            var    executionEvents   = new ConfigurableProgressStepExecutionEvents();
            string connectionMessage = connectionInfo.ServerUri.ToString();
            var    testSubject       = new ConnectionWorkflow(this.host, new RelayCommand(AssertIfCalled));
            ConfigurableUserNotification notifications = (ConfigurableUserNotification)this.host.ActiveSection.UserNotifications;

            // Act
            await testSubject.ConnectionStepAsync(connectionInfo, controller, executionEvents, CancellationToken.None);

            // Assert
            controller.NumberOfAbortRequests.Should().Be(1);
            AssertServiceDisconnectCalled();
            executionEvents.AssertProgressMessages(
                connectionInfo.ServerUri.ToString(),
                Strings.ConnectionStepValidatinCredentials,
                Strings.DetectingSonarQubePlugins,
                Strings.ConnectionResultFailure);
            projectChangedCallbackCalled.Should().BeFalse("ConnectedProjectsCallaback was called");
            notifications.AssertNotification(NotificationIds.BadSonarQubePluginId, string.Format(Strings.OnlySupportedPluginHasNoProjectInSolution, minimumSupportedSonarQubePlugin.Language.Name));

            AssertCredentialsNotStored(); // Username and password are null
        }