コード例 #1
0
        public async Task ConnectionWorkflow_ConnectionStep_Credentials_Invalid()
        {
            // Arrange
            var connectionInfo = new ConnectionInformation(new Uri("http://server"), "user", "pass".ToSecureString());

            this.sonarQubeServiceMock.Setup(x => x.ConnectAsync(connectionInfo, It.IsAny <CancellationToken>()))
            .Throws(new Exception());

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

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

            // Assert
            controller.NumberOfAbortRequests.Should().Be(1);
            AssertServiceDisconnectCalled();
            executionEvents.AssertProgressMessages(
                connectionMessage,
                Strings.ConnectionStepValidatinCredentials,
                Strings.ConnectionResultFailure);

            this.sonarQubeServiceMock.Verify(
                x => x.ConnectAsync(It.IsAny <ConnectionInformation>(), It.IsAny <CancellationToken>()),
                Times.Once());

            testSubject.ConnectedServer.Should().Be(null);

            ((ConfigurableUserNotification)this.host.ActiveSection.UserNotifications).AssertNoShowErrorMessages();
            ((ConfigurableUserNotification)this.host.ActiveSection.UserNotifications).AssertNotification(NotificationIds.FailedToConnectId);

            AssertCredentialsNotStored(); // Connection was rejected by SonarQube
        }
コード例 #2
0
        public void ConnectionWorkflow_ConnectionStep_WhenMissingCSharpPluginAndVBNetPlugin_AbortsWorkflowAndDisconnects()
        {
            // Setup
            var connectionInfo             = new ConnectionInformation(new Uri("http://server"));
            ConnectionWorkflow testSubject = new ConnectionWorkflow(this.host, new RelayCommand(() => { }));
            var controller = new ConfigurableProgressController();

            this.sonarQubeService.AllowConnections         = true;
            this.sonarQubeService.ReturnProjectInformation = new ProjectInformation[0];
            this.sonarQubeService.ClearServerPlugins();
            this.host.SetActiveSection(ConfigurableSectionController.CreateDefault());
            ConfigurableUserNotification notifications = (ConfigurableUserNotification)this.host.ActiveSection.UserNotifications;
            var executionEvents = new ConfigurableProgressStepExecutionEvents();

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

            // Verify
            controller.AssertNumberOfAbortRequests(1);
            executionEvents.AssertProgressMessages(
                connectionInfo.ServerUri.ToString(),
                Strings.DetectingServerPlugins,
                Strings.ConnectionResultFailure);
            notifications.AssertNotification(NotificationIds.BadServerPluginId, Strings.ServerHasNoSupportedPluginVersion);
        }
コード例 #3
0
        public void ConnectionWorkflow_DownloadServiceParameters_InvalidRegex_UsesDefault()
        {
            // Setup
            var controller     = new ConfigurableProgressController();
            var progressEvents = new ConfigurableProgressStepExecutionEvents();

            var badExpression      = "*-gf/d*-b/try\\*-/r-*yeb/\\";
            var expectedExpression = ServerProperty.TestProjectRegexDefaultValue;

            this.sonarQubeService.RegisterServerProperty(new ServerProperty
            {
                Key   = ServerProperty.TestProjectRegexKey,
                Value = badExpression
            });

            ConnectionWorkflow testSubject = SetTestSubjectWithConnectedServer();

            // Act
            testSubject.DownloadServiceParameters(controller, CancellationToken.None, progressEvents);

            // Verify
            filter.AssertTestRegex(expectedExpression, RegexOptions.IgnoreCase);
            progressEvents.AssertProgressMessages(Strings.DownloadingServerSettingsProgessMessage);
            this.outputWindowPane.AssertOutputStrings(string.Format(CultureInfo.CurrentCulture, Strings.InvalidTestProjectRegexPattern, badExpression));
        }
コード例 #4
0
        public async Task ConnectionWorkflow_ConnectionStep_10KProjectsAndKeyIsNotPartOfIt()
        {
            // Arrange
            var connectionInfo = new ConnectionInformation(new Uri("http://server"), "user", "pass".ToSecureString());
            var projects       = Enumerable.Range(1, 10000)
                                 .Select(i => new SonarQubeProject($"project-{i}", $"Project {i}"))
                                 .ToList();

            this.sonarQubeServiceMock.Setup(x => x.ConnectAsync(connectionInfo, It.IsAny <CancellationToken>()))
            .Returns(Task.Delay(0));
            this.sonarQubeServiceMock.Setup(x => x.GetAllProjectsAsync(It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(projects);
            this.projectSystemHelper.Projects = new[] { new ProjectMock("tttt.csproj")
                                                        {
                                                            ProjectKind = ProjectSystemHelper.CSharpProjectKind
                                                        } };
            bool projectChangedCallbackCalled = false;

            const string boundProjectKey  = "whatever-key";
            const string boundProjectName = "whatever-name";

            this.host.TestStateManager.SetProjectsAction = (c, p) =>
            {
                projectChangedCallbackCalled = true;
                c.Should().Be(connectionInfo, "Unexpected connection");
                var expectedList = new List <SonarQubeProject>(projects);
                expectedList.Insert(0, new SonarQubeProject(boundProjectKey, boundProjectName));
                p.Should().BeEquivalentTo(expectedList);
            };
            this.host.VisualStateManager.BoundProjectKey  = boundProjectKey;
            this.host.VisualStateManager.BoundProjectName = boundProjectName;

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

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

            // Assert
            controller.NumberOfAbortRequests.Should().Be(0);
            AssertServiceDisconnectNotCalled();
            executionEvents.AssertProgressMessages(
                connectionMessage,
                Strings.ConnectionStepValidatinCredentials,
                Strings.DetectingSonarQubePlugins,
                Strings.ConnectionStepRetrievingProjects,
                Strings.ConnectionResultSuccess);
            projectChangedCallbackCalled.Should().BeTrue("ConnectedProjectsCallaback was not called");
            this.sonarQubeServiceMock.Verify(x => x.ConnectAsync(It.IsAny <ConnectionInformation>(),
                                                                 It.IsAny <CancellationToken>()), Times.Once());
            testSubject.ConnectedServer.Should().Be(connectionInfo);
            ((ConfigurableUserNotification)this.host.ActiveSection.UserNotifications).AssertNoShowErrorMessages();
            ((ConfigurableUserNotification)this.host.ActiveSection.UserNotifications).AssertNoNotification(NotificationIds.FailedToConnectId);

            AssertCredentialsStored(connectionInfo);

            this.outputWindowPane.AssertOutputStrings(4);
        }
コード例 #5
0
        public async Task ConnectionWorkflow_ConnectionStep_WhenMissingCSharpPluginAndVBNetPlugin_AbortsWorkflowAndDisconnects()
        {
            // Arrange
            var connectionInfo             = new ConnectionInformation(new Uri("http://server"));
            ConnectionWorkflow testSubject = new ConnectionWorkflow(this.host, new RelayCommand(() => { }));
            var controller = new ConfigurableProgressController();

            this.sonarQubeServiceMock.Setup(x => x.GetAllProjectsAsync(It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(new List <SonarQubeProject>());
            this.sonarQubeServiceMock.Setup(x => x.GetAllPluginsAsync(It.IsAny <CancellationToken>()))
            .ReturnsAsync(new List <SonarQubePlugin>());
            this.host.SetActiveSection(ConfigurableSectionController.CreateDefault());
            ConfigurableUserNotification notifications = (ConfigurableUserNotification)this.host.ActiveSection.UserNotifications;
            var executionEvents = new ConfigurableProgressStepExecutionEvents();

            // 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);
            notifications.AssertNotification(NotificationIds.BadSonarQubePluginId, Strings.ServerHasNoSupportedPluginVersion);

            AssertCredentialsNotStored(); // Username and password are null
        }
コード例 #6
0
        public void ConnectionWorkflow_ConnectionStep_SuccessfulConnection()
        {
            // Setup
            var connectionInfo = new ConnectionInformation(new Uri("http://server"));
            var projects = new ProjectInformation[] { new ProjectInformation { Key = "project1" } };
            this.sonarQubeService.ReturnProjectInformation = projects;
            bool projectChangedCallbackCalled = false;
            this.host.TestStateManager.SetProjectsAction = (c, p) =>
            {
                projectChangedCallbackCalled = true;
                Assert.AreSame(connectionInfo, c, "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));

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

            // Verify
            executionEvents.AssertProgressMessages(connectionMessage, Strings.ConnectionResultSuccess);
            Assert.IsTrue(projectChangedCallbackCalled, "ConnectedProjectsCallaback was not called");
            sonarQubeService.AssertConnectRequests(1);
            Assert.AreEqual(connectionInfo, testSubject.ConnectedServer);
            ((ConfigurableUserNotification)this.host.ActiveSection.UserNotifications).AssertNoShowErrorMessages();
            ((ConfigurableUserNotification)this.host.ActiveSection.UserNotifications).AssertNoNotification(NotificationIds.FailedToConnectId);
        }
コード例 #7
0
        private async Task ConnectionWorkflow_ConnectionStep_WhenXPluginAndNoXProject_AbortsWorkflowAndDisconnects(string projectName, string projectKind,
                                                                                                                   params MinimumSupportedSonarQubePlugin[] minimumSupportedSonarQubePlugins)
        {
            // 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(minimumSupportedSonarQubePlugins.Select(p => new SonarQubePlugin(p.Key, p.MinimumVersion)).ToList());
            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");

            var languageList = string.Join(", ", minimumSupportedSonarQubePlugins.SelectMany(x => x.Languages.Select(l => l.Name)));

            notifications.AssertNotification(NotificationIds.BadSonarQubePluginId, string.Format(Strings.OnlySupportedPluginsHaveNoProjectInSolution, languageList));

            AssertCredentialsNotStored(); // Username and password are null
        }
コード例 #8
0
        private async Task ConnectionWorkflow_ConnectionStep_WhenXPluginAndAnyXProject_SuccessfulConnection(string projectName, string projectKind)
        {
            // Arrange
            var connectionInfo = new ConnectionInformation(new Uri("http://server"), "user", "pass".ToSecureString());
            var projects       = new List <SonarQubeProject> {
                new SonarQubeProject("project1", "")
            };

            this.sonarQubeServiceMock.Setup(x => x.ConnectAsync(connectionInfo, It.IsAny <CancellationToken>()))
            .Returns(Task.Delay(0));
            this.sonarQubeServiceMock.Setup(x => x.GetAllProjectsAsync(It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(projects);
            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));

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

            // Assert
            controller.NumberOfAbortRequests.Should().Be(0);
            AssertServiceDisconnectNotCalled();
            executionEvents.AssertProgressMessages(
                connectionMessage,
                Strings.ConnectionStepValidatinCredentials,
                Strings.DetectingSonarQubePlugins,
                Strings.ConnectionStepRetrievingProjects,
                Strings.ConnectionResultSuccess);
            projectChangedCallbackCalled.Should().BeTrue("ConnectedProjectsCallaback was not called");
            this.sonarQubeServiceMock.Verify(x => x.ConnectAsync(It.IsAny <ConnectionInformation>(),
                                                                 It.IsAny <CancellationToken>()), Times.Once());
            testSubject.ConnectedServer.Should().Be(connectionInfo);
            ((ConfigurableUserNotification)this.host.ActiveSection.UserNotifications).AssertNoShowErrorMessages();
            ((ConfigurableUserNotification)this.host.ActiveSection.UserNotifications).AssertNoNotification(NotificationIds.FailedToConnectId);

            AssertCredentialsStored(connectionInfo);
        }
        public void ProgressStepRunner_Observe()
        {
            // Setup
            ConfigurableProgressController controller = new ConfigurableProgressController();
            ConfigurableProgressControlHost host = new ConfigurableProgressControlHost();
            controller.AddSteps(new ConfigurableProgressStep());// Needs at least one

            // Act
            using (ProgressObserver observer1 = ProgressStepRunner.Observe(controller, host))
            {
                // Verify
                Assert.IsNotNull(observer1, "Unexpected return value");
                Assert.AreSame(observer1, ProgressStepRunner.ObservedControllers[controller]);
                host.AssertHasProgressControl();
            }
        }
コード例 #10
0
        public void ProgressStepRunner_Observe()
        {
            // Setup
            ConfigurableProgressController  controller = new ConfigurableProgressController();
            ConfigurableProgressControlHost host       = new ConfigurableProgressControlHost();

            controller.AddSteps(new ConfigurableProgressStep());// Needs at least one

            // Act
            using (ProgressObserver observer1 = ProgressStepRunner.Observe(controller, host))
            {
                // Verify
                Assert.IsNotNull(observer1, "Unexpected return value");
                Assert.AreSame(observer1, ProgressStepRunner.ObservedControllers[controller]);
                host.AssertHasProgressControl();
            }
        }
コード例 #11
0
        public void ProgressStepRunner_Observe()
        {
            // Arrange
            ConfigurableProgressController  controller = new ConfigurableProgressController();
            ConfigurableProgressControlHost host       = new ConfigurableProgressControlHost();

            controller.AddSteps(new ConfigurableProgressStep());// Needs at least one

            // Act
            using (ProgressObserver observer1 = ProgressStepRunner.Observe(controller, host))
            {
                // Assert
                observer1.Should().NotBeNull("Unexpected return value");
                ProgressStepRunner.ObservedControllers[controller].Should().Be(observer1);
                host.ProgressControl.Should().NotBeNull();
            }
        }
コード例 #12
0
        private void ConnectionWorkflow_ConnectionStep_WhenXPluginAndNoXProject_AbortsWorkflowAndDisconnects(string projectName, string projectKind, MinimumSupportedServerPlugin minimumSupportedServerPlugin)
        {
            // Arrange
            var connectionInfo = new ConnectionInformation(new Uri("http://server"));
            var projects       = new ProjectInformation[] { new ProjectInformation {
                                                                Key = "project1"
                                                            } };

            this.sonarQubeService.ReturnProjectInformation = projects;
            this.sonarQubeService.ClearServerPlugins();
            this.sonarQubeService.RegisterServerPlugin(new ServerPlugin {
                Key = minimumSupportedServerPlugin.Key, Version = minimumSupportedServerPlugin.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
            testSubject.ConnectionStep(controller, CancellationToken.None, connectionInfo, executionEvents);

            // Assert
            controller.NumberOfAbortRequests.Should().Be(1);
            executionEvents.AssertProgressMessages(
                connectionInfo.ServerUri.ToString(),
                Strings.ConnectionStepValidatinCredentials,
                Strings.DetectingServerPlugins,
                Strings.ConnectionResultFailure);
            projectChangedCallbackCalled.Should().BeFalse("ConnectedProjectsCallaback was called");
            notifications.AssertNotification(NotificationIds.BadServerPluginId, string.Format(Strings.OnlySupportedPluginHasNoProjectInSolution, minimumSupportedServerPlugin.Language.Name));
        }
コード例 #13
0
        public void ConnectionWorkflow_DownloadServiceParameters_RegexPropertyNotSet_SetsFilterWithDefaultExpression()
        {
            // Setup
            var controller                 = new ConfigurableProgressController();
            var progressEvents             = new ConfigurableProgressStepExecutionEvents();
            var expectedExpression         = ServerProperty.TestProjectRegexDefaultValue;
            ConnectionWorkflow testSubject = SetTestSubjectWithConnectedServer();

            // Sanity
            Assert.IsFalse(this.sonarQubeService.ServerProperties.Any(x => x.Key != ServerProperty.TestProjectRegexKey), "Test project regex property should not be set");

            // Act
            testSubject.DownloadServiceParameters(controller, CancellationToken.None, progressEvents);

            // Verify
            filter.AssertTestRegex(expectedExpression, RegexOptions.IgnoreCase);
            progressEvents.AssertProgressMessages(Strings.DownloadingServerSettingsProgessMessage);
        }
コード例 #14
0
        private void ConnectionWorkflow_ConnectionStep_WhenXPluginAndAnyXProject_SuccessfulConnection(string projectName, string projectKind)
        {
            // Arrange
            var connectionInfo = new ConnectionInformation(new Uri("http://server"));
            var projects       = new ProjectInformation[] { new ProjectInformation {
                                                                Key = "project1"
                                                            } };

            this.sonarQubeService.ReturnProjectInformation = projects;
            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));

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

            // Assert
            controller.NumberOfAbortRequests.Should().Be(0);
            executionEvents.AssertProgressMessages(
                connectionMessage,
                Strings.ConnectionStepValidatinCredentials,
                Strings.DetectingServerPlugins,
                Strings.ConnectionStepRetrievingProjects,
                Strings.ConnectionResultSuccess);
            projectChangedCallbackCalled.Should().BeTrue("ConnectedProjectsCallaback was not called");
            sonarQubeService.ConnectionRequestsCount.Should().Be(1);
            testSubject.ConnectedServer.Should().Be(connectionInfo);
            ((ConfigurableUserNotification)this.host.ActiveSection.UserNotifications).AssertNoShowErrorMessages();
            ((ConfigurableUserNotification)this.host.ActiveSection.UserNotifications).AssertNoNotification(NotificationIds.FailedToConnectId);
        }
コード例 #15
0
        public async Task ConnectionWorkflow_DownloadServiceParameters_NoTestProjectRegexProperty()
        {
            // Arrange
            var controller     = new ConfigurableProgressController();
            var progressEvents = new ConfigurableProgressStepExecutionEvents();

            this.sonarQubeServiceMock.Setup(x => x.GetAllPropertiesAsync(It.IsAny <CancellationToken>()))
            .ReturnsAsync(new List <SonarQubeProperty> {
            });

            ConnectionWorkflow testSubject = SetTestSubjectWithConnectedServer();

            // Act
            await testSubject.DownloadServiceParametersAsync(controller, progressEvents, CancellationToken.None);

            // Assert
            filter.AssertTestRegex(SonarQubeProperty.TestProjectRegexDefaultValue, RegexOptions.IgnoreCase);
            progressEvents.AssertProgressMessages(Strings.DownloadingServerSettingsProgessMessage);
        }
コード例 #16
0
        public async Task ConnectionWorkflow_DownloadServiceParameters_Cancelled_AbortsWorkflow()
        {
            // Arrange
            var controller     = new ConfigurableProgressController();
            var progressEvents = new ConfigurableProgressStepExecutionEvents();

            ConnectionWorkflow testSubject = SetTestSubjectWithConnectedServer();

            var cts = new CancellationTokenSource();

            cts.Cancel();

            // Act
            await testSubject.DownloadServiceParametersAsync(controller, progressEvents, cts.Token);

            // Assert
            progressEvents.AssertProgressMessages(Strings.DownloadingServerSettingsProgessMessage);
            controller.NumberOfAbortRequests.Should().Be(1);
        }
コード例 #17
0
        public void ConnectionWorkflow_DownloadServiceParameters_Cancelled_AbortsWorkflow()
        {
            // Setup
            var controller     = new ConfigurableProgressController();
            var progressEvents = new ConfigurableProgressStepExecutionEvents();

            ConnectionWorkflow testSubject = SetTestSubjectWithConnectedServer();

            var cts = new CancellationTokenSource();

            cts.Cancel();

            // Act
            testSubject.DownloadServiceParameters(controller, cts.Token, progressEvents);

            // Verify
            progressEvents.AssertProgressMessages(Strings.DownloadingServerSettingsProgessMessage);
            controller.AssertNumberOfAbortRequests(1);
        }
コード例 #18
0
        public async Task ConnectionWorkflow_ConnectionStep_WhenPluginOkAndNoProjects_AbortsWorkflowAndDisconnects()
        {
            // 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);
            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, Strings.SolutionContainsNoSupportedProject);

            AssertCredentialsNotStored(); // Username and password are null
        }
コード例 #19
0
        public async Task ConnectionWorkflow_DownloadServiceParameters_CustomRegexProperty_SetsFilterWithCorrectExpression()
        {
            // Arrange
            var controller     = new ConfigurableProgressController();
            var progressEvents = new ConfigurableProgressStepExecutionEvents();

            var expectedExpression = ".*spoon.*";

            this.sonarQubeServiceMock.Setup(x => x.GetAllPropertiesAsync(It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(new List <SonarQubeProperty> {
                new SonarQubeProperty(SonarQubeProperty.TestProjectRegexKey, expectedExpression)
            });

            ConnectionWorkflow testSubject = SetTestSubjectWithConnectedServer();

            // Act
            await testSubject.DownloadServiceParametersAsync(controller, progressEvents, CancellationToken.None);

            // Assert
            testProjectRegexSetter.Verify(x => x.SetTestRegex(expectedExpression), Times.Once);
        }
コード例 #20
0
        public void ProgressStepRunner_AbortAll()
        {
            // Arrange
            ConfigurableProgressController controller1 = new ConfigurableProgressController();

            controller1.AddSteps(new ConfigurableProgressStep());// Needs at least one
            ConfigurableProgressControlHost host1      = new ConfigurableProgressControlHost();
            ProgressObserver observer1                 = ProgressStepRunner.Observe(controller1, host1);
            ConfigurableProgressController controller2 = new ConfigurableProgressController();

            controller2.AddSteps(new ConfigurableProgressStep());// Needs at least one
            ConfigurableProgressControlHost host2 = new ConfigurableProgressControlHost();
            ProgressObserver observer2            = ProgressStepRunner.Observe(controller2, host2);

            // Act
            ProgressStepRunner.AbortAll();

            // Assert
            controller1.NumberOfAbortRequests.Should().Be(1);
            controller2.NumberOfAbortRequests.Should().Be(1);
        }
        public void ProgressStepRunner_ChangeHost()
        {
            // Setup
            ConfigurableProgressController controller = new ConfigurableProgressController();
            controller.AddSteps(new ConfigurableProgressStep());// Needs at least one
            ConfigurableProgressControlHost host1 = new ConfigurableProgressControlHost();
            ProgressObserver observer = ProgressStepRunner.Observe(controller, host1);

            // Act
            ConfigurableProgressControlHost host2 = new ConfigurableProgressControlHost();
            ProgressStepRunner.ChangeHost(host2);

            // Verify
            using (var newObserver = ProgressStepRunner.ObservedControllers[controller])
            {
                Assert.IsNotNull(newObserver);
                Assert.AreNotSame(newObserver, observer);
                Assert.AreSame(observer.State, newObserver.State, "State was not transferred");
                host2.AssertHasProgressControl();
            }
        }
コード例 #22
0
        public void ProgressStepRunner_ChangeHost()
        {
            // Arrange
            ConfigurableProgressController controller = new ConfigurableProgressController();

            controller.AddSteps(new ConfigurableProgressStep());// Needs at least one
            ConfigurableProgressControlHost host1 = new ConfigurableProgressControlHost();
            ProgressObserver observer             = ProgressStepRunner.Observe(controller, host1);

            // Act
            ConfigurableProgressControlHost host2 = new ConfigurableProgressControlHost();

            ProgressStepRunner.ChangeHost(host2);

            // Assert
            using (var newObserver = ProgressStepRunner.ObservedControllers[controller])
            {
                newObserver.Should().NotBeNull();
                observer.Should().NotBe(newObserver);
                newObserver.State.Should().Be(observer.State, "State was not transferred");
                host2.ProgressControl.Should().NotBeNull();
            }
        }
コード例 #23
0
        public void ConnectionWorkflow_DownloadServiceParameters_CustomRegexProperty_SetsFilterWithCorrectExpression()
        {
            // Setup
            var controller     = new ConfigurableProgressController();
            var progressEvents = new ConfigurableProgressStepExecutionEvents();

            var expectedExpression = ".*spoon.*";

            this.sonarQubeService.RegisterServerProperty(new ServerProperty
            {
                Key   = ServerProperty.TestProjectRegexKey,
                Value = expectedExpression
            });

            ConnectionWorkflow testSubject = SetTestSubjectWithConnectedServer();

            // Act
            testSubject.DownloadServiceParameters(controller, CancellationToken.None, progressEvents);

            // Verify
            filter.AssertTestRegex(expectedExpression, RegexOptions.IgnoreCase);
            progressEvents.AssertProgressMessages(Strings.DownloadingServerSettingsProgessMessage);
        }
コード例 #24
0
        public void ProgressStepRunner_ChangeHost()
        {
            // Setup
            ConfigurableProgressController controller = new ConfigurableProgressController();

            controller.AddSteps(new ConfigurableProgressStep());// Needs at least one
            ConfigurableProgressControlHost host1 = new ConfigurableProgressControlHost();
            ProgressObserver observer             = ProgressStepRunner.Observe(controller, host1);

            // Act
            ConfigurableProgressControlHost host2 = new ConfigurableProgressControlHost();

            ProgressStepRunner.ChangeHost(host2);

            // Verify
            using (var newObserver = ProgressStepRunner.ObservedControllers[controller])
            {
                Assert.IsNotNull(newObserver);
                Assert.AreNotSame(newObserver, observer);
                Assert.AreSame(observer.State, newObserver.State, "State was not transferred");
                host2.AssertHasProgressControl();
            }
        }
コード例 #25
0
        public void ConnectionWorkflow_ConnectionStep_WhenPluginOkAndNoProjects_AbortsWorkflowAndDisconnects()
        {
            // Arrange
            var connectionInfo = new ConnectionInformation(new Uri("http://server"));
            var projects       = new ProjectInformation[] { new ProjectInformation {
                                                                Key = "project1"
                                                            } };

            this.sonarQubeService.ReturnProjectInformation = projects;
            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
            testSubject.ConnectionStep(controller, CancellationToken.None, connectionInfo, executionEvents);

            // Assert
            controller.NumberOfAbortRequests.Should().Be(1);
            executionEvents.AssertProgressMessages(
                connectionInfo.ServerUri.ToString(),
                Strings.ConnectionStepValidatinCredentials,
                Strings.DetectingServerPlugins,
                Strings.ConnectionResultFailure);
            projectChangedCallbackCalled.Should().BeFalse("ConnectedProjectsCallaback was called");
            notifications.AssertNotification(NotificationIds.BadServerPluginId, Strings.SolutionContainsNoSupportedProject);
        }
コード例 #26
0
        public async Task ConnectionWorkflow_DownloadServiceParameters_InvalidRegex_UsesDefault()
        {
            // Arrange
            var controller     = new ConfigurableProgressController();
            var progressEvents = new ConfigurableProgressStepExecutionEvents();

            var badExpression      = "*-gf/d*-b/try\\*-/r-*yeb/\\";
            var expectedExpression = SonarQubeProperty.TestProjectRegexDefaultValue;

            this.sonarQubeServiceMock.Setup(x => x.GetAllPropertiesAsync(It.IsAny <CancellationToken>()))
            .ReturnsAsync(new List <SonarQubeProperty> {
                new SonarQubeProperty(SonarQubeProperty.TestProjectRegexKey, badExpression)
            });

            ConnectionWorkflow testSubject = SetTestSubjectWithConnectedServer();

            // Act
            await testSubject.DownloadServiceParametersAsync(controller, progressEvents, CancellationToken.None);

            // Assert
            filter.AssertTestRegex(expectedExpression, RegexOptions.IgnoreCase);
            progressEvents.AssertProgressMessages(Strings.DownloadingServerSettingsProgessMessage);
            this.outputWindowPane.AssertOutputStrings(string.Format(CultureInfo.CurrentCulture, Strings.InvalidTestProjectRegexPattern, badExpression));
        }
        private void ConnectionWorkflow_ConnectionStep_WhenXPluginAndNoXProject_AbortsWorkflowAndDisconnects(string projectName, string projectKind, MinimumSupportedServerPlugin minimumSupportedServerPlugin)
        {
            // Arrange
            var connectionInfo = new ConnectionInformation(new Uri("http://server"));
            var projects = new ProjectInformation[] { new ProjectInformation { Key = "project1" } };
            this.sonarQubeService.ReturnProjectInformation = projects;
            this.sonarQubeService.ClearServerPlugins();
            this.sonarQubeService.RegisterServerPlugin(new ServerPlugin { Key = minimumSupportedServerPlugin.Key, Version = minimumSupportedServerPlugin.MinimumVersion });
            this.projectSystemHelper.Projects = new[] { new ProjectMock(projectName) { ProjectKind = projectKind } };
            bool projectChangedCallbackCalled = false;
            this.host.TestStateManager.SetProjectsAction = (c, p) =>
            {
                projectChangedCallbackCalled = true;
                Assert.AreSame(connectionInfo, c, "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
            testSubject.ConnectionStep(controller, CancellationToken.None, connectionInfo, executionEvents);

            // Verify
            controller.AssertNumberOfAbortRequests(1);
            executionEvents.AssertProgressMessages(
                connectionInfo.ServerUri.ToString(),
                Strings.DetectingServerPlugins,
                Strings.ConnectionResultFailure);
            Assert.IsFalse(projectChangedCallbackCalled, "ConnectedProjectsCallaback was called");
            notifications.AssertNotification(NotificationIds.BadServerPluginId, string.Format(Strings.OnlySupportedPluginHasNoProjectInSolution, minimumSupportedServerPlugin.Language.Name));
        }
コード例 #28
0
        public void ConnectionWorkflow_DownloadServiceParameters_Cancelled_AbortsWorkflow()
        {
            // Setup
            var controller = new ConfigurableProgressController();
            var progressEvents = new ConfigurableProgressStepExecutionEvents();

            ConnectionWorkflow testSubject = SetTestSubjectWithConnectedServer();

            var cts = new CancellationTokenSource();
            cts.Cancel();

            // Act
            testSubject.DownloadServiceParameters(controller, cts.Token, progressEvents);

            // Verify
            progressEvents.AssertProgressMessages(Strings.DownloadingServerSettingsProgessMessage);
            controller.AssertNumberOfAbortRequests(1);
        }
コード例 #29
0
        public void ConnectionWorkflow_DownloadServiceParameters_InvalidRegex_UsesDefault()
        {
            // Setup
            var controller = new ConfigurableProgressController();
            var progressEvents = new ConfigurableProgressStepExecutionEvents();

            var badExpression = "*-gf/d*-b/try\\*-/r-*yeb/\\";
            var expectedExpression = ServerProperty.TestProjectRegexDefaultValue;
            this.sonarQubeService.RegisterServerProperty(new ServerProperty
            {
                Key = ServerProperty.TestProjectRegexKey,
                Value = badExpression
            });

            ConnectionWorkflow testSubject = SetTestSubjectWithConnectedServer();

            // Act
            testSubject.DownloadServiceParameters(controller, CancellationToken.None, progressEvents);

            // Verify
            filter.AssertTestRegex(expectedExpression, RegexOptions.IgnoreCase);
            progressEvents.AssertProgressMessages(Strings.DownloadingServerSettingsProgessMessage);
            this.outputWindowPane.AssertOutputStrings(string.Format(CultureInfo.CurrentCulture, Strings.InvalidTestProjectRegexPattern, badExpression));
        }
        public void ConnectionWorkflow_ConnectionStep_WhenPluginOkAndNoProjects_AbortsWorkflowAndDisconnects()
        {
            // Arrange
            var connectionInfo = new ConnectionInformation(new Uri("http://server"));
            var projects = new ProjectInformation[] { new ProjectInformation { Key = "project1" } };
            this.sonarQubeService.ReturnProjectInformation = projects;
            bool projectChangedCallbackCalled = false;
            this.host.TestStateManager.SetProjectsAction = (c, p) =>
            {
                projectChangedCallbackCalled = true;
                Assert.AreSame(connectionInfo, c, "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
            testSubject.ConnectionStep(controller, CancellationToken.None, connectionInfo, executionEvents);

            // Verify
            controller.AssertNumberOfAbortRequests(1);
            executionEvents.AssertProgressMessages(
                connectionInfo.ServerUri.ToString(),
                Strings.DetectingServerPlugins,
                Strings.ConnectionResultFailure);
            Assert.IsFalse(projectChangedCallbackCalled, "ConnectedProjectsCallaback was called");
            notifications.AssertNotification(NotificationIds.BadServerPluginId, Strings.SolutionContainsNoSupportedProject);
        }
コード例 #31
0
        public void ConnectionWorkflow_DownloadServiceParameters_RegexPropertyNotSet_SetsFilterWithDefaultExpression()
        {
            // Setup
            var controller = new ConfigurableProgressController();
            var progressEvents = new ConfigurableProgressStepExecutionEvents();
            var expectedExpression = ServerProperty.TestProjectRegexDefaultValue;
            ConnectionWorkflow testSubject = SetTestSubjectWithConnectedServer();

            // Sanity
            Assert.IsFalse(this.sonarQubeService.ServerProperties.Any(x => x.Key != ServerProperty.TestProjectRegexKey), "Test project regex property should not be set");

            // Act
            testSubject.DownloadServiceParameters(controller, CancellationToken.None, progressEvents);

            // Verify
            filter.AssertTestRegex(expectedExpression, RegexOptions.IgnoreCase);
            progressEvents.AssertProgressMessages(Strings.DownloadingServerSettingsProgessMessage);
        }
コード例 #32
0
        public void ConnectionWorkflow_DownloadServiceParameters_CustomRegexProperty_SetsFilterWithCorrectExpression()
        {
            // Setup
            var controller = new ConfigurableProgressController();
            var progressEvents = new ConfigurableProgressStepExecutionEvents();

            var expectedExpression = ".*spoon.*";
            this.sonarQubeService.RegisterServerProperty(new ServerProperty
            {
                Key = ServerProperty.TestProjectRegexKey,
                Value = expectedExpression
            });

            ConnectionWorkflow testSubject = SetTestSubjectWithConnectedServer();

            // Act
            testSubject.DownloadServiceParameters(controller, CancellationToken.None, progressEvents);

            // Verify
            filter.AssertTestRegex(expectedExpression, RegexOptions.IgnoreCase);
            progressEvents.AssertProgressMessages(Strings.DownloadingServerSettingsProgessMessage);
        }
        public void ConnectionWorkflow_ConnectionStep_WhenMissingCSharpPluginAndVBNetPlugin_AbortsWorkflowAndDisconnects()
        {
            // Setup
            var connectionInfo = new ConnectionInformation(new Uri("http://server"));
            ConnectionWorkflow testSubject = new ConnectionWorkflow(this.host, new RelayCommand(() => { }));
            var controller = new ConfigurableProgressController();
            this.sonarQubeService.AllowConnections = true;
            this.sonarQubeService.ReturnProjectInformation = new ProjectInformation[0];
            this.sonarQubeService.ClearServerPlugins();
            this.host.SetActiveSection(ConfigurableSectionController.CreateDefault());
            ConfigurableUserNotification notifications = (ConfigurableUserNotification)this.host.ActiveSection.UserNotifications;
            var executionEvents = new ConfigurableProgressStepExecutionEvents();

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

            // Verify
            controller.AssertNumberOfAbortRequests(1);
            executionEvents.AssertProgressMessages(
                connectionInfo.ServerUri.ToString(),
                Strings.DetectingServerPlugins,
                Strings.ConnectionResultFailure);
            notifications.AssertNotification(NotificationIds.BadServerPluginId, Strings.ServerHasNoSupportedPluginVersion);
        }
コード例 #34
0
        public void ConnectionWorkflow_ConnectionStep_MissingCSharpPlugin_AbortsWorkflowAndDisconnects()
        {
            // Setup
            var connectionInfo = new ConnectionInformation(new Uri("http://server"));
            ConnectionWorkflow testSubject = new ConnectionWorkflow(this.host, new RelayCommand(() => { }));
            var controller = new ConfigurableProgressController();
            this.sonarQubeService.AllowConnections = true;
            this.sonarQubeService.ReturnProjectInformation = new ProjectInformation[0];
            this.sonarQubeService.ClearServerPlugins();
            this.host.SetActiveSection(ConfigurableSectionController.CreateDefault());
            ConfigurableUserNotification notifications = (ConfigurableUserNotification)this.host.ActiveSection.UserNotifications;
            var executionEvents = new ConfigurableProgressStepExecutionEvents();

            string expectedErrorMsg = string.Format(CultureInfo.CurrentCulture, Strings.ServerDoesNotHaveCorrectVersionOfCSharpPlugin, ServerPlugin.CSharpPluginMinimumVersion);

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

            // Verify
            controller.AssertNumberOfAbortRequests(1);
            executionEvents.AssertProgressMessages(
                connectionInfo.ServerUri.ToString(),
                expectedErrorMsg,
                Strings.ConnectionResultFailure);
            notifications.AssertNotification(NotificationIds.BadServerPluginId, expectedErrorMsg);
        }
コード例 #35
0
        public async Task ConnectionWorkflow_ConnectionStep_UnsuccessfulConnection()
        {
            // Arrange
            this.sonarQubeServiceMock.Setup(x => x.GetAllProjectsAsync(It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .Returns(() => { throw new Exception(); });
            var  connectionInfo = new ConnectionInformation(new Uri("http://server"));
            bool projectChangedCallbackCalled = false;

            this.host.TestStateManager.SetProjectsAction = (c, p) =>
            {
                projectChangedCallbackCalled = true;
                c.Should().Be(connectionInfo, "Unexpected connection");
                p.Should().BeNull("Not expecting any projects");
            };
            this.projectSystemHelper.Projects = new[] { new ProjectMock("foo.csproj")
                                                        {
                                                            ProjectKind = ProjectSystemHelper.CSharpProjectKind
                                                        } };
            var    controller        = new ConfigurableProgressController();
            var    executionEvents   = new ConfigurableProgressStepExecutionEvents();
            string connectionMessage = connectionInfo.ServerUri.ToString();
            var    testSubject       = new ConnectionWorkflow(this.host, new RelayCommand(AssertIfCalled));

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

            // Assert
            executionEvents.AssertProgressMessages(
                connectionMessage,
                Strings.ConnectionStepValidatinCredentials,
                Strings.DetectingSonarQubePlugins,
                Strings.ConnectionStepRetrievingProjects,
                Strings.ConnectionResultFailure);
            projectChangedCallbackCalled.Should().BeFalse("Callback should not have been called");
            this.sonarQubeServiceMock.Verify(x => x.ConnectAsync(It.IsAny <ConnectionInformation>(),
                                                                 It.IsAny <CancellationToken>()), Times.Once());
            this.host.VisualStateManager.IsConnected.Should().BeFalse();
            ((ConfigurableUserNotification)this.host.ActiveSection.UserNotifications).AssertNotification(NotificationIds.FailedToConnectId, Strings.ConnectionFailed);

            // Act (reconnect with same bad connection)
            executionEvents.Reset();
            projectChangedCallbackCalled = false;
            await testSubject.ConnectionStepAsync(connectionInfo, controller, executionEvents, CancellationToken.None);

            // Assert
            executionEvents.AssertProgressMessages(
                connectionMessage,
                Strings.ConnectionStepValidatinCredentials,
                Strings.DetectingSonarQubePlugins,
                Strings.ConnectionStepRetrievingProjects,
                Strings.ConnectionResultFailure);
            projectChangedCallbackCalled.Should().BeFalse("Callback should not have been called");
            this.sonarQubeServiceMock.Verify(x => x.ConnectAsync(It.IsAny <ConnectionInformation>(),
                                                                 It.IsAny <CancellationToken>()), Times.Exactly(2));
            this.host.VisualStateManager.IsConnected.Should().BeFalse();
            ((ConfigurableUserNotification)this.host.ActiveSection.UserNotifications).AssertNotification(NotificationIds.FailedToConnectId, Strings.ConnectionFailed);

            // Canceled connections
            CancellationTokenSource tokenSource = new CancellationTokenSource();

            executionEvents.Reset();
            projectChangedCallbackCalled = false;
            CancellationToken token = tokenSource.Token;

            tokenSource.Cancel();

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

            // Assert
            executionEvents.AssertProgressMessages(
                connectionMessage,
                Strings.ConnectionStepValidatinCredentials,
                Strings.DetectingSonarQubePlugins,
                Strings.ConnectionStepRetrievingProjects,
                Strings.ConnectionResultCancellation);
            projectChangedCallbackCalled.Should().BeFalse("Callback should not have been called");
            this.sonarQubeServiceMock.Verify(x => x.ConnectAsync(It.IsAny <ConnectionInformation>(),
                                                                 It.IsAny <CancellationToken>()), Times.Exactly(3));
            this.host.VisualStateManager.IsConnected.Should().BeFalse();
            ((ConfigurableUserNotification)this.host.ActiveSection.UserNotifications).AssertNotification(NotificationIds.FailedToConnectId, Strings.ConnectionFailed);

            AssertCredentialsNotStored(); // Username and password are null
        }
        public void ProgressStepRunner_AbortAll()
        {
            // Setup
            ConfigurableProgressController controller1 = new ConfigurableProgressController();
            controller1.AddSteps(new ConfigurableProgressStep());// Needs at least one
            ConfigurableProgressControlHost host1 = new ConfigurableProgressControlHost();
            ProgressObserver observer1 = ProgressStepRunner.Observe(controller1, host1);
            ConfigurableProgressController controller2 = new ConfigurableProgressController();
            controller2.AddSteps(new ConfigurableProgressStep());// Needs at least one
            ConfigurableProgressControlHost host2 = new ConfigurableProgressControlHost();
            ProgressObserver observer2 = ProgressStepRunner.Observe(controller2, host2);

            // Act
            ProgressStepRunner.AbortAll();

            // Verify
            controller1.AssertNumberOfAbortRequests(1);
            controller2.AssertNumberOfAbortRequests(1);
        }
コード例 #37
0
        public void ConnectionWorkflow_ConnectionStep_UnsuccessfulConnection()
        {
            // Setup
            var  connectionInfo = new ConnectionInformation(new Uri("http://server"));
            bool projectChangedCallbackCalled = false;

            this.host.TestStateManager.SetProjectsAction = (c, p) =>
            {
                projectChangedCallbackCalled = true;
                Assert.AreSame(connectionInfo, c, "Unexpected connection");
                Assert.IsNull(p, "Not expecting any projects");
            };
            this.projectSystemHelper.Projects = new[] { new ProjectMock("foo.csproj")
                                                        {
                                                            ProjectKind = ProjectSystemHelper.CSharpProjectKind
                                                        } };
            var controller = new ConfigurableProgressController();

            this.sonarQubeService.AllowConnections = false;
            var    executionEvents   = new ConfigurableProgressStepExecutionEvents();
            string connectionMessage = connectionInfo.ServerUri.ToString();
            var    testSubject       = new ConnectionWorkflow(this.host, new RelayCommand(AssertIfCalled));

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

            // Verify
            executionEvents.AssertProgressMessages(
                connectionMessage,
                Strings.DetectingServerPlugins,
                Strings.ConnectionResultFailure);
            Assert.IsFalse(projectChangedCallbackCalled, "Callback should not have been called");
            this.sonarQubeService.AssertConnectRequests(1);
            Assert.IsFalse(this.host.VisualStateManager.IsConnected);
            ((ConfigurableUserNotification)this.host.ActiveSection.UserNotifications).AssertNotification(NotificationIds.FailedToConnectId, Strings.ConnectionFailed);

            // Act (reconnect with same bad connection)
            executionEvents.Reset();
            projectChangedCallbackCalled = false;
            testSubject.ConnectionStep(controller, CancellationToken.None, connectionInfo, executionEvents);

            // Verify
            executionEvents.AssertProgressMessages(
                connectionMessage,
                Strings.DetectingServerPlugins,
                Strings.ConnectionResultFailure);
            Assert.IsFalse(projectChangedCallbackCalled, "Callback should not have been called");
            this.sonarQubeService.AssertConnectRequests(2);
            Assert.IsFalse(this.host.VisualStateManager.IsConnected);
            ((ConfigurableUserNotification)this.host.ActiveSection.UserNotifications).AssertNotification(NotificationIds.FailedToConnectId, Strings.ConnectionFailed);

            // Canceled connections
            CancellationTokenSource tokenSource = new CancellationTokenSource();

            executionEvents.Reset();
            projectChangedCallbackCalled = false;
            CancellationToken token = tokenSource.Token;

            tokenSource.Cancel();

            // Act
            testSubject.ConnectionStep(controller, token, connectionInfo, executionEvents);

            // Verify
            executionEvents.AssertProgressMessages(
                connectionMessage,
                Strings.DetectingServerPlugins,
                Strings.ConnectionResultCancellation);
            Assert.IsFalse(projectChangedCallbackCalled, "Callback should not have been called");
            this.sonarQubeService.AssertConnectRequests(3);
            Assert.IsFalse(this.host.VisualStateManager.IsConnected);
            ((ConfigurableUserNotification)this.host.ActiveSection.UserNotifications).AssertNotification(NotificationIds.FailedToConnectId, Strings.ConnectionFailed);
        }
コード例 #38
0
        public void ConnectionWorkflow_ConnectionStep_UnsuccessfulConnection()
        {
            // Setup
            var connectionInfo = new ConnectionInformation(new Uri("http://server"));
            bool projectChangedCallbackCalled = false;
            this.host.TestStateManager.SetProjectsAction = (c, p) =>
            {
                projectChangedCallbackCalled = true;
                Assert.AreSame(connectionInfo, c, "Unexpected connection");
                Assert.IsNull(p, "Not expecting any projects");
            };
            var controller = new ConfigurableProgressController();
            this.sonarQubeService.AllowConnections = false;
            var executionEvents = new ConfigurableProgressStepExecutionEvents();
            string connectionMessage = connectionInfo.ServerUri.ToString();
            var testSubject = new ConnectionWorkflow(this.host, new RelayCommand(AssertIfCalled));

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

            // Verify
            executionEvents.AssertProgressMessages(connectionMessage, Strings.ConnectionResultFailure);
            Assert.IsFalse(projectChangedCallbackCalled, "Callback should not have been called");
            this.sonarQubeService.AssertConnectRequests(1);
            Assert.IsFalse(this.host.VisualStateManager.IsConnected);
            ((ConfigurableUserNotification)this.host.ActiveSection.UserNotifications).AssertNotification(NotificationIds.FailedToConnectId, Strings.ConnectionFailed);

            // Act (reconnect with same bad connection)
            executionEvents.Reset();
            projectChangedCallbackCalled = false;
            testSubject.ConnectionStep(controller, CancellationToken.None, connectionInfo, executionEvents);

            // Verify
            executionEvents.AssertProgressMessages(connectionMessage, Strings.ConnectionResultFailure);
            Assert.IsFalse(projectChangedCallbackCalled, "Callback should not have been called");
            this.sonarQubeService.AssertConnectRequests(2);
            Assert.IsFalse(this.host.VisualStateManager.IsConnected);
            ((ConfigurableUserNotification)this.host.ActiveSection.UserNotifications).AssertNotification(NotificationIds.FailedToConnectId, Strings.ConnectionFailed);

            // Cancelled connections
            CancellationTokenSource tokenSource = new CancellationTokenSource();
            executionEvents.Reset();
            projectChangedCallbackCalled = false;
            CancellationToken token = tokenSource.Token;
            tokenSource.Cancel();

            // Act
            testSubject.ConnectionStep(controller, token, connectionInfo, executionEvents);

            // Verify
            executionEvents.AssertProgressMessages(connectionMessage, Strings.ConnectionResultCancellation);
            Assert.IsFalse(projectChangedCallbackCalled, "Callback should not have been called");
            this.sonarQubeService.AssertConnectRequests(3);
            Assert.IsFalse(this.host.VisualStateManager.IsConnected);
            ((ConfigurableUserNotification)this.host.ActiveSection.UserNotifications).AssertNotification(NotificationIds.FailedToConnectId, Strings.ConnectionFailed);
        }