DispatchFrame() public static method

public static DispatchFrame ( DispatcherPriority priority = DispatcherPriority.Background ) : void
priority DispatcherPriority
return void
        private void VerifyBackgroundExecution(bool updateRequired, ErrorListInfoBarController.QualityProfileBackgroundProcessor testSubject, params string[] expectedOutput)
        {
            // Act
            int called = 0;

            testSubject.QueueCheckIfUpdateIsRequired((customMessage) =>
            {
                customMessage.Should().BeNull("Not expecting any message customizations");
                called++;
            });

            // Assert
            called.Should().Be(0, "Not expected to be immediate");
            testSubject.BackgroundTask.Should().NotBeNull("Expected to start processing in the background");

            // Run the background task
            testSubject.BackgroundTask.Wait(TimeSpan.FromSeconds(60)).Should().BeTrue("Timeout waiting for the background task");
            called.Should().Be(0, "The UI thread (this one) should be blocked");

            // Run the UI async action
            DispatcherHelper.DispatchFrame(DispatcherPriority.Normal); // Allow the BeginInvoke to run

            if (updateRequired)
            {
                called.Should().Be(1, "Expected to call the update action");
            }
            else
            {
                called.Should().Be(0, "Not expected to call the update action");
            }

            this.outputWindowPane.AssertOutputStrings(expectedOutput);
        }
Example #2
0
        public void ErrorListInfoBarController_CurrentBackgroundProcessorCancellation()
        {
            // Setup
            this.IsActiveSolutionBound = true;
            var testSubject = new ErrorListInfoBarController(this.host);

            this.ConfigureLoadedSolution(hasUnboundProject: false);
            var projectSystem = new ConfigurableVsProjectSystemHelper(this.serviceProvider);

            this.serviceProvider.RegisterService(typeof(IProjectSystemHelper), projectSystem);
            var project = new ProjectMock("project.proj");

            project.SetCSProjectKind();
            projectSystem.FilteredProjects = new[] { project };
            this.solutionBindingSerializer.CurrentBinding.Profiles = new Dictionary <Language, Persistence.ApplicableQualityProfile>();
            this.solutionBindingSerializer.CurrentBinding.Profiles[Language.CSharp] = new Persistence.ApplicableQualityProfile
            {
                ProfileKey       = "Profile",
                ProfileTimestamp = DateTime.Now
            };
            var sqService = new ConfigurableSonarQubeServiceWrapper();

            this.host.SonarQubeService = sqService;
            sqService.ReturnProfile[Language.CSharp] = new QualityProfile();

            // Act
            testSubject.ProcessSolutionBinding();

            // Verify
            Assert.IsNotNull(testSubject.CurrentBackgroundProcessor?.BackgroundTask, "Background task is expected");
            Assert.IsTrue(testSubject.CurrentBackgroundProcessor.BackgroundTask.Wait(TimeSpan.FromSeconds(2)), "Timeout waiting for the background task");
            this.infoBarManager.AssertHasNoAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid);

            // Act (refresh again and  let the blocked UI thread run to completion)
            testSubject.ProcessSolutionBinding();
            DispatcherHelper.DispatchFrame(DispatcherPriority.Normal);
            this.IsActiveSolutionBound = false;

            // Verify that no info bar was added (due to the last action in which the state will not cause the info bar to appear)
            this.infoBarManager.AssertHasNoAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid);
        }
Example #3
0
        public void ErrorListInfoBarController_CurrentBackgroundProcessorCancellation()
        {
            // Arrange
            this.SetBindingMode(SonarLintMode.LegacyConnected);
            var testSubject = new ErrorListInfoBarController(this.host, this.unboundProjectFinder);

            this.ConfigureLoadedSolution(hasUnboundProject: false);
            var projectSystem = new ConfigurableVsProjectSystemHelper(this.serviceProvider);

            this.serviceProvider.RegisterService(typeof(IProjectSystemHelper), projectSystem);
            var project = new ProjectMock("project.proj");

            project.SetCSProjectKind();
            projectSystem.FilteredProjects = new[] { project };
            this.configProvider.ProjectToReturn.Profiles = new Dictionary <Language, ApplicableQualityProfile>();
            this.configProvider.ProjectToReturn.Profiles[Language.CSharp] = new ApplicableQualityProfile
            {
                ProfileKey       = "Profile",
                ProfileTimestamp = DateTime.Now
            };
            this.configProvider.ModeToReturn = SonarLintMode.LegacyConnected;

            // Act
            testSubject.ProcessSolutionBinding();

            // Assert
            testSubject.CurrentBackgroundProcessor?.BackgroundTask.Should().NotBeNull("Background task is expected");
            testSubject.CurrentBackgroundProcessor.BackgroundTask.Wait(TimeSpan.FromSeconds(2)).Should().BeTrue("Timeout waiting for the background task");
            this.infoBarManager.AssertHasNoAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid);

            // Act (refresh again and  let the blocked UI thread run to completion)
            testSubject.ProcessSolutionBinding();
            DispatcherHelper.DispatchFrame(DispatcherPriority.Normal);
            this.SetBindingMode(SonarLintMode.Standalone);

            // Assert that no info bar was added (due to the last action in which the state will not cause the info bar to appear)
            this.infoBarManager.AssertHasNoAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid);
        }