Inheritance: IProgressStepExecutionEvents
示例#1
0
        public void BindingWorkflow_DownloadQualityProfile_Failure()
        {
            // Setup
            BindingWorkflow testSubject = this.CreateTestSubject();
            ConfigurableProgressController controller = new ConfigurableProgressController();
            var notifications = new ConfigurableProgressStepExecutionEvents();

            var language = Language.CSharp;

            this.ConfigureProfileExport(null, language);

            // Act
            testSubject.DownloadQualityProfile(controller, CancellationToken.None, notifications, new[] { language });

            // Verify
            Assert.IsFalse(testSubject.Rulesets.ContainsKey(Language.VBNET), "Not expecting any rules for this language");
            Assert.IsFalse(testSubject.Rulesets.ContainsKey(language), "Not expecting any rules");
            controller.AssertNumberOfAbortRequests(1);

            notifications.AssertProgressMessages(Strings.DownloadingQualityProfileProgressMessage);

            this.outputWindowPane.AssertOutputStrings(1);
            var expectedOutput = string.Format(Strings.SubTextPaddingFormat,
                                               string.Format(Strings.QualityProfileDownloadFailedMessageFormat, string.Empty, string.Empty, language.Name));

            this.outputWindowPane.AssertOutputStrings(expectedOutput);
        }
        public async Task DownloadQualityProfile_WhenQualityProfileIsNotAvailable_Fails()
        {
            // Arrange
            var testSubject     = this.CreateTestSubject();
            var notifications   = new ConfigurableProgressStepExecutionEvents();
            var progressAdapter = new FixedStepsProgressAdapter(notifications);

            var language = Language.CSharp;

            ConfigureSupportedBindingProject(testSubject.InternalState, language);
            this.ConfigureQualityProfile(Language.VBNET, "");

            // Act
            var result = await testSubject.DownloadQualityProfileAsync(progressAdapter, CancellationToken.None);

            // Assert
            result.Should().BeFalse();
            testSubject.InternalState.BindingConfigs.Should().NotContainKey(Language.VBNET, "Not expecting any rules for this language");
            testSubject.InternalState.BindingConfigs.Should().NotContainKey(language, "Not expecting any rules");

            notifications.AssertProgressMessages(Strings.DownloadingQualityProfileProgressMessage);

            this.outputWindowPane.AssertOutputStrings(1);
            var expectedOutput = string.Format(Strings.SubTextPaddingFormat,
                                               string.Format(Strings.CannotDownloadQualityProfileForLanguage, language.Name));

            this.outputWindowPane.AssertOutputStrings(expectedOutput);
        }
        public async Task BindingWorkflow_DownloadQualityProfile_WhenProfileExportIsNotAvailable_Fails()
        {
            // Arrange
            BindingWorkflow testSubject = this.CreateTestSubject();
            ConfigurableProgressController controller = new ConfigurableProgressController();
            var notifications = new ConfigurableProgressStepExecutionEvents();

            var language = Language.CSharp;

            this.ConfigureProfileExport(null, language, "");

            // Act
            await testSubject.DownloadQualityProfileAsync(controller, notifications, new[] { language }, CancellationToken.None);

            // Assert
            testSubject.Rulesets.Should().NotContainKey(Language.VBNET, "Not expecting any rules for this language");
            testSubject.Rulesets.Should().NotContainKey(language, "Not expecting any rules");
            controller.NumberOfAbortRequests.Should().Be(1);

            notifications.AssertProgressMessages(Strings.DownloadingQualityProfileProgressMessage);

            this.outputWindowPane.AssertOutputStrings(1);
            var expectedOutput = string.Format(Strings.SubTextPaddingFormat,
                                               string.Format(Strings.QualityProfileDownloadFailedMessageFormat, string.Empty, string.Empty, language.Name));

            this.outputWindowPane.AssertOutputStrings(expectedOutput);
        }
        public void BindingWorkflow_InstallPackages_MoreNugetPackagesThanLanguageCount()
        {
            // Arrange
            var testSubject    = this.CreateTestSubject();
            var progressEvents = new ConfigurableProgressStepExecutionEvents();

            ProjectMock project1 = new ProjectMock("project1")
            {
                ProjectKind = ProjectSystemHelper.CSharpProjectKind
            };

            var nugetPackage1 = new PackageName("mypackage1", new SemanticVersion("1.1.0"));
            var nugetPackage2 = new PackageName("mypackage2", new SemanticVersion("1.1.1"));
            var nugetPackages = new[] { nugetPackage1, nugetPackage2 };
            var packages      = new Dictionary <Language, IEnumerable <PackageName> >();

            packages.Add(Language.CSharp, nugetPackages);

            ConfigurablePackageInstaller packageInstaller = this.PrepareInstallPackagesTest(testSubject, packages, project1);

            // Act
            testSubject.InstallPackages(new ConfigurableProgressController(), CancellationToken.None, progressEvents);

            // Assert
            packageInstaller.AssertInstalledPackages(project1, nugetPackages);
            this.outputWindowPane.AssertOutputStrings(4);
            this.outputWindowPane.AssertOutputStrings(
                string.Format(Strings.SubTextPaddingFormat, string.Format(Strings.EnsuringNugetPackagesProgressMessage, nugetPackages[0].Id, ((Project)project1).Name)),
                string.Format(Strings.SubTextPaddingFormat, string.Format(Strings.SuccessfullyInstalledNugetPackageForProject, nugetPackages[0].Id, ((Project)project1).Name)),
                string.Format(Strings.SubTextPaddingFormat, string.Format(Strings.EnsuringNugetPackagesProgressMessage, nugetPackages[1].Id, ((Project)project1).Name)),
                string.Format(Strings.SubTextPaddingFormat, string.Format(Strings.SuccessfullyInstalledNugetPackageForProject, nugetPackages[1].Id, ((Project)project1).Name))
                );
            progressEvents.AssertProgress(.5, 1.0);
        }
        public void BindingWorkflow_InstallPackages_Succeeds_SuccessPropertyIsFalse()
        {
            // Arrange
            var bindingArgs = new BindCommandArgs("projectKey", "projectName", new ConnectionInformation(new Uri("http://connected")));

            var slnBindOpMock = new Mock <ISolutionBindingOperation>();
            var nugetMock     = new Mock <INuGetBindingOperation>();

            nugetMock.Setup(x => x.InstallPackages(It.IsAny <ISet <Project> >(),
                                                   It.IsAny <IProgressController>(),
                                                   It.IsAny <IProgressStepExecutionEvents>(),
                                                   It.IsAny <CancellationToken>())).Returns(false);

            var testSubject = new BindingWorkflow(this.host, bindingArgs, slnBindOpMock.Object, nugetMock.Object);

            ProjectMock project1 = new ProjectMock("project1")
            {
                ProjectKind = ProjectSystemHelper.CSharpProjectKind
            };

            testSubject.BindingProjects.Clear();
            testSubject.BindingProjects.Add(project1);

            var progressEvents = new ConfigurableProgressStepExecutionEvents();
            var cts            = new CancellationTokenSource();

            testSubject.BindingOperationSucceeded = true;

            // Act
            testSubject.InstallPackages(new ConfigurableProgressController(), progressEvents, cts.Token);

            // Assert
            testSubject.BindingOperationSucceeded.Should().BeFalse();
        }
        public async Task BindingWorkflow_DownloadQualityProfile_WithNoRules_Fails()
        {
            // Arrange
            const string    QualityProfileName        = "SQQualityProfileName";
            const string    ProjectName               = "SQProjectName";
            BindingWorkflow testSubject               = this.CreateTestSubject("key", ProjectName);
            ConfigurableProgressController controller = new ConfigurableProgressController();
            var notifications = new ConfigurableProgressStepExecutionEvents();

            RuleSet ruleSet         = TestRuleSetHelper.CreateTestRuleSetWithRuleIds(Enumerable.Empty <string>());
            var     nugetPackages   = new[] { new PackageName("myPackageId", new SemanticVersion("1.0.0")) };
            var     additionalFiles = new[] { new AdditionalFileResponse {
                                                  FileName = "abc.xml", Content = new byte[] { 1, 2, 3 }
                                              } };
            RoslynExportProfileResponse export = RoslynExportProfileHelper.CreateExport(ruleSet, nugetPackages, additionalFiles);

            var language = Language.VBNET;
            SonarQubeQualityProfile profile = this.ConfigureProfileExport(export, language, QualityProfileName);

            // Act
            await testSubject.DownloadQualityProfileAsync(controller, notifications, new[] { language }, CancellationToken.None);

            // Assert
            testSubject.Rulesets.Should().NotContainKey(Language.VBNET, "Not expecting any rules for this language");
            testSubject.Rulesets.Should().NotContainKey(language, "Not expecting any rules");
            controller.NumberOfAbortRequests.Should().Be(1);

            notifications.AssertProgressMessages(Strings.DownloadingQualityProfileProgressMessage);

            this.outputWindowPane.AssertOutputStrings(1);
            var expectedOutput = string.Format(Strings.SubTextPaddingFormat,
                                               string.Format(Strings.NoSonarAnalyzerActiveRulesForQualityProfile, QualityProfileName, language.Name));

            this.outputWindowPane.AssertOutputStrings(expectedOutput);
        }
        public void BindingWorkflow_EmitBindingCompleteMessage()
        {
            // Arrange
            var testSubject = this.CreateTestSubject();

            // Test case 1: Default state is 'true'
            testSubject.BindingOperationSucceeded.Should().BeTrue($"Initial state of {nameof(BindingWorkflow.BindingOperationSucceeded)} should be true");

            // Test case 2: All packages installed
            // Arrange
            var notificationsOk = new ConfigurableProgressStepExecutionEvents();

            testSubject.BindingOperationSucceeded = true;

            // Act
            testSubject.EmitBindingCompleteMessage(notificationsOk);

            // Assert
            notificationsOk.AssertProgressMessages(string.Format(CultureInfo.CurrentCulture, Strings.FinishedSolutionBindingWorkflowSuccessful));

            // Test case 3: Not all packages installed
            // Arrange
            var notificationsFail = new ConfigurableProgressStepExecutionEvents();

            testSubject.BindingOperationSucceeded = false;

            // Act
            testSubject.EmitBindingCompleteMessage(notificationsFail);

            // Assert
            notificationsFail.AssertProgressMessages(string.Format(CultureInfo.CurrentCulture, Strings.FinishedSolutionBindingWorkflowNotAllPackagesInstalled));
        }
        public void BindingWorkflow_DiscoverProjects_AddsMatchingProjectsToBinding()
        {
            // Arrange
            ThreadHelper.SetCurrentThreadAsUIThread();
            var controller     = new ConfigurableProgressController();
            var progressEvents = new ConfigurableProgressStepExecutionEvents();

            var csProject1 = new ProjectMock("cs1.csproj");
            var csProject2 = new ProjectMock("cs2.csproj");

            csProject1.SetCSProjectKind();
            csProject2.SetCSProjectKind();

            var matchingProjects = new[] { csProject1, csProject2 };

            this.projectSystemHelper.FilteredProjects = matchingProjects;

            var testSubject = this.CreateTestSubject();

            this.host.SupportedPluginLanguages.UnionWith(new[] { Language.CSharp });

            // Act
            testSubject.DiscoverProjects(controller, progressEvents);

            // Assert
            CollectionAssert.AreEqual(matchingProjects, testSubject.BindingProjects.ToArray(), "Unexpected projects selected for binding");
            progressEvents.AssertProgressMessages(Strings.DiscoveringSolutionProjectsProgressMessage);
        }
示例#9
0
        public void BindingWorkflow_EmitBindingCompleteMessage()
        {
            // Arrange

            // Test case 1: process succeeded
            mockBindingProcess.Setup(x => x.BindOperationSucceeded).Returns(true);
            var notificationsOk = new ConfigurableProgressStepExecutionEvents();

            // Act
            testSubject.EmitBindingCompleteMessage(notificationsOk);

            // Assert
            notificationsOk.AssertProgressMessages(string.Format(CultureInfo.CurrentCulture, Strings.FinishedSolutionBindingWorkflowSuccessful));

            // Test case 2: process failed
            // Arrange
            mockBindingProcess.Setup(x => x.BindOperationSucceeded).Returns(false);
            var notificationsFail = new ConfigurableProgressStepExecutionEvents();

            // Act
            testSubject.EmitBindingCompleteMessage(notificationsFail);

            // Assert
            notificationsFail.AssertProgressMessages(string.Format(CultureInfo.CurrentCulture, Strings.FinishedSolutionBindingWorkflowNotAllPackagesInstalled));
        }
        public void BindingWorkflow_DownloadQualityProfile_Success()
        {
            // Setup
            BindingWorkflow testSubject = this.CreateTestSubject();
            ConfigurableProgressController controller = new ConfigurableProgressController();
            var notifications = new ConfigurableProgressStepExecutionEvents();

            RuleSet ruleSet = TestRuleSetHelper.CreateTestRuleSetWithRuleIds(new[] { "Key1", "Key2" });
            var nugetPackages = new[] { new PackageName("myPackageId", new SemanticVersion("1.0.0")) };
            var additionalFiles = new[] { new AdditionalFile { FileName = "abc.xml", Content = new byte[] { 1, 2, 3 } } };
            RoslynExportProfile export = RoslynExportProfileHelper.CreateExport(ruleSet, nugetPackages, additionalFiles);

            var language = Language.VBNET;
            QualityProfile profile = this.ConfigureProfileExport(export, language);

            // Act
            testSubject.DownloadQualityProfile(controller, CancellationToken.None, notifications, new[] { language });

            // Verify
            RuleSetAssert.AreEqual(ruleSet, testSubject.Rulesets[language], "Unexpected rule set");
            Assert.AreSame(profile, testSubject.QualityProfiles[language]);
            VerifyNuGetPackgesDownloaded(nugetPackages, testSubject);
            this.outputWindowPane.AssertOutputStrings(0);
            controller.AssertNumberOfAbortRequests(0);
            notifications.AssertProgress(
                0.0,
                1.0,
                1.0);
            notifications.AssertProgressMessages(
                string.Format(CultureInfo.CurrentCulture, Strings.DownloadingQualityProfileProgressMessage, language.Name),
                string.Empty,
                Strings.QualityProfileDownloadedSuccessfulMessage);
        }
        public async Task DownloadQualityProfile_WhenBindingConfigIsNull_Fails()
        {
            // Arrange
            const string QualityProfileName = "SQQualityProfileName";
            const string ProjectName        = "SQProjectName";

            Mock <INuGetBindingOperation> nuGetOpMock = new Mock <INuGetBindingOperation>();

            var notifications   = new ConfigurableProgressStepExecutionEvents();
            var progressAdapter = new FixedStepsProgressAdapter(notifications);

            var language = Language.VBNET;
            SonarQubeQualityProfile profile = this.ConfigureQualityProfile(language, QualityProfileName);

            var configProviderMock = new Mock <IBindingConfigProvider>();
            var testSubject        = this.CreateTestSubject("key", ProjectName, nuGetOpMock.Object, configProviderMock.Object);

            ConfigureSupportedBindingProject(testSubject.InternalState, language);

            // Act
            var result = await testSubject.DownloadQualityProfileAsync(progressAdapter, CancellationToken.None);

            // Assert
            result.Should().BeFalse();
            testSubject.InternalState.QualityProfiles[language].Should().Be(profile);

            notifications.AssertProgress(0.0);
            notifications.AssertProgressMessages(Strings.DownloadingQualityProfileProgressMessage);

            this.outputWindowPane.AssertOutputStrings(1);
            var expectedOutput = string.Format(Strings.SubTextPaddingFormat,
                                               string.Format(Strings.FailedToCreateBindingConfigForLanguage, language.Name));

            this.outputWindowPane.AssertOutputStrings(expectedOutput);
        }
        public void BindingWorkflow_DiscoverProjects_OutputsIncludedAndExcludedProjects()
        {
            // Arrange
            ThreadHelper.SetCurrentThreadAsUIThread();
            var controller     = new ConfigurableProgressController();
            var progressEvents = new ConfigurableProgressStepExecutionEvents();

            // Act & Common Assert
            BindingWorkflow_DiscoverProjects_GenericPart(controller, progressEvents, 4, 2);
        }
        public void InstallPackages_FailureOnOneProject_Continues()
        {
            // Arrange
            const string failureMessage = "Failure for project1";
            const string project1Name   = "project1";
            const string project2Name   = "project2";

            var testSubject     = this.CreateTestSubject();
            var progressEvents  = new ConfigurableProgressStepExecutionEvents();
            var progressAdapter = new FixedStepsProgressAdapter(progressEvents);
            var cts             = new CancellationTokenSource();

            ProjectMock project1 = new ProjectMock(project1Name)
            {
                ProjectKind = ProjectSystemHelper.CSharpProjectKind
            };
            ProjectMock project2 = new ProjectMock(project2Name)
            {
                ProjectKind = ProjectSystemHelper.CSharpProjectKind
            };
            var projectsToBind = new HashSet <Project> {
                project1, project2
            };

            var nugetPackage  = new PackageName("mypackage", new SemanticVersion("1.1.0"));
            var packages      = new[] { nugetPackage };
            var nugetPackages = new Dictionary <Language, IEnumerable <PackageName> >();

            nugetPackages.Add(Language.CSharp, packages);

            ConfigurablePackageInstaller packageInstaller = this.PrepareInstallPackagesTest(testSubject, nugetPackages);

            packageInstaller.InstallPackageAction = (p) =>
            {
                packageInstaller.InstallPackageAction = null;
                throw new Exception(failureMessage);
            };

            // Act
            testSubject.InstallPackages(projectsToBind, progressAdapter, cts.Token);

            // Assert
            packageInstaller.AssertNoInstalledPackages(project1);
            packageInstaller.AssertInstalledPackages(project2, packages);
            this.logger.AssertOutputStrings(4);
            this.logger.AssertOutputStrings(
                string.Format(Strings.SubTextPaddingFormat, string.Format(Strings.EnsuringNugetPackagesProgressMessage, nugetPackage.Id, project1Name)),
                string.Format(Strings.SubTextPaddingFormat, string.Format(Strings.FailedDuringNuGetPackageInstall, nugetPackage.Id, project1Name, failureMessage)),
                string.Format(Strings.SubTextPaddingFormat, string.Format(Strings.EnsuringNugetPackagesProgressMessage, nugetPackage.Id, project2Name)),
                string.Format(Strings.SubTextPaddingFormat, string.Format(Strings.SuccessfullyInstalledNugetPackageForProject, nugetPackage.Id, project2Name))
                );

            progressEvents.AssertProgress(.5, 1.0);
        }
示例#14
0
        public void BindingWorkflow_InstallPackages_NoError()
        {
            // Arrange
            var progressEvents = new ConfigurableProgressStepExecutionEvents();
            var cts            = new CancellationTokenSource();

            // Act
            testSubject.InstallPackages(progressEvents, cts.Token);

            // Assert
            mockBindingProcess.Verify(x => x.InstallPackages(It.IsAny <IProgress <FixedStepsProgress> >(), cts.Token), Times.Once);
        }
示例#15
0
        public void BindingWorkflow_InitializeSolutionBindingOnUIThread_NoError()
        {
            // Arrange
            var progressEvents = new ConfigurableProgressStepExecutionEvents();

            // Act
            testSubject.InitializeSolutionBindingOnUIThread(progressEvents);

            // Assert
            mockBindingProcess.Verify(x => x.InitializeSolutionBindingOnUIThread(), Times.Once);
            progressEvents.AssertProgressMessages(Strings.RuleSetGenerationProgressMessage);
        }
        public async Task BindingWorkflow_DownloadQualityProfile_Success()
        {
            // Arrange
            const string QualityProfileName = "SQQualityProfileName";
            const string ProjectName        = "SQProjectName";

            // Record all of the calls to NuGetBindingOperation.ProcessExport
            var actualProfiles = new List <Tuple <Language, RoslynExportProfileResponse> >();
            Mock <INuGetBindingOperation> nuGetOpMock = new Mock <INuGetBindingOperation>();

            nuGetOpMock.Setup(x => x.ProcessExport(It.IsAny <Language>(), It.IsAny <RoslynExportProfileResponse>()))
            .Callback <Language, RoslynExportProfileResponse>((l, r) => actualProfiles.Add(new Tuple <Language, RoslynExportProfileResponse>(l, r)))
            .Returns(true);

            BindingWorkflow testSubject = this.CreateTestSubject("key", ProjectName, nuGetOpMock.Object);


            ConfigurableProgressController controller = new ConfigurableProgressController();
            var notifications = new ConfigurableProgressStepExecutionEvents();

            RuleSet ruleSet         = TestRuleSetHelper.CreateTestRuleSetWithRuleIds(new[] { "Key1", "Key2" });
            var     expectedRuleSet = new RuleSet(ruleSet)
            {
                NonLocalizedDisplayName = string.Format(Strings.SonarQubeRuleSetNameFormat, ProjectName, QualityProfileName),
                NonLocalizedDescription = "\r\nhttp://connected/profiles/show?key="
            };
            var nugetPackages   = new[] { new PackageName("myPackageId", new SemanticVersion("1.0.0")) };
            var additionalFiles = new[] { new AdditionalFileResponse {
                                              FileName = "abc.xml", Content = new byte[] { 1, 2, 3 }
                                          } };
            RoslynExportProfileResponse export = RoslynExportProfileHelper.CreateExport(ruleSet, nugetPackages, additionalFiles);

            var language = Language.VBNET;
            SonarQubeQualityProfile profile = this.ConfigureProfileExport(export, language, QualityProfileName);

            // Act
            await testSubject.DownloadQualityProfileAsync(controller, notifications, new[] { language }, CancellationToken.None);

            // Assert
            RuleSetAssert.AreEqual(expectedRuleSet, testSubject.Rulesets[language], "Unexpected rule set");
            testSubject.QualityProfiles[language].Should().Be(profile);
            VerifyNuGetPackgesDownloaded(nugetPackages, language, actualProfiles);

            controller.NumberOfAbortRequests.Should().Be(0);
            notifications.AssertProgress(0.0, 1.0);
            notifications.AssertProgressMessages(Strings.DownloadingQualityProfileProgressMessage, string.Empty);

            this.outputWindowPane.AssertOutputStrings(1);
            var expectedOutput = string.Format(Strings.SubTextPaddingFormat,
                                               string.Format(Strings.QualityProfileDownloadSuccessfulMessageFormat, QualityProfileName, string.Empty, language.Name));

            this.outputWindowPane.AssertOutputStrings(expectedOutput);
        }
        public void BindingWorkflow_DiscoverProjects_NoMatchingProjects_AbortsWorkflow()
        {
            // Arrange
            ThreadHelper.SetCurrentThreadAsUIThread();
            var controller     = new ConfigurableProgressController();
            var progressEvents = new ConfigurableProgressStepExecutionEvents();

            // Act & Common Assert
            BindingWorkflow_DiscoverProjects_GenericPart(controller, progressEvents, 0, 0);

            // Assert
            controller.NumberOfAbortRequests.Should().Be(1);
        }
        public void BindingWorkflow_DownloadQualityProfile_WithNoActiveRules_Fails()
        {
            // Arrange
            const string QualityProfileName   = "SQQualityProfileName";
            const string SonarQubeProjectName = "SQProjectName";
            var          projectInfo          = new ProjectInformation {
                Key = "key", Name = SonarQubeProjectName
            };
            BindingWorkflow testSubject = this.CreateTestSubject(projectInfo);
            ConfigurableProgressController controller = new ConfigurableProgressController();
            var notifications = new ConfigurableProgressStepExecutionEvents();

            RuleSet ruleSet = TestRuleSetHelper.CreateTestRuleSetWithRuleIds(new[] { "Key1", "Key2" });

            foreach (var rule in ruleSet.Rules)
            {
                rule.Action = RuleAction.None;
            }
            var expectedRuleSet = new RuleSet(ruleSet)
            {
                NonLocalizedDisplayName = string.Format(Strings.SonarQubeRuleSetNameFormat, SonarQubeProjectName, QualityProfileName),
                NonLocalizedDescription = "\r\nhttp://connected/profiles/show?key="
            };
            var nugetPackages   = new[] { new PackageName("myPackageId", new SemanticVersion("1.0.0")) };
            var additionalFiles = new[] { new AdditionalFile {
                                              FileName = "abc.xml", Content = new byte[] { 1, 2, 3 }
                                          } };
            RoslynExportProfile export = RoslynExportProfileHelper.CreateExport(ruleSet, nugetPackages, additionalFiles);

            var            language = Language.VBNET;
            QualityProfile profile  = this.ConfigureProfileExport(export, language);

            profile.Name = QualityProfileName;

            // Act
            testSubject.DownloadQualityProfile(controller, CancellationToken.None, notifications, new[] { language });

            // Assert
            testSubject.Rulesets.Should().NotContainKey(Language.VBNET, "Not expecting any rules for this language");
            testSubject.Rulesets.Should().NotContainKey(language, "Not expecting any rules");
            controller.NumberOfAbortRequests.Should().Be(1);

            notifications.AssertProgressMessages(Strings.DownloadingQualityProfileProgressMessage);

            this.outputWindowPane.AssertOutputStrings(1);
            var expectedOutput = string.Format(Strings.SubTextPaddingFormat,
                                               string.Format(Strings.NoSonarAnalyzerActiveRulesForQualityProfile, QualityProfileName, language.Name));

            this.outputWindowPane.AssertOutputStrings(expectedOutput);
        }
        public async Task DownloadQualityProfile_Success()
        {
            var configPersister = new ConfigurableConfigurationProvider();

            this.serviceProvider.RegisterService(typeof(IConfigurationPersister), configPersister);

            // Arrange
            const string QualityProfileName = "SQQualityProfileName";
            const string ProjectName        = "SQProjectName";

            Mock <INuGetBindingOperation> nuGetOpMock = new Mock <INuGetBindingOperation>();

            var notifications   = new ConfigurableProgressStepExecutionEvents();
            var progressAdapter = new FixedStepsProgressAdapter(notifications);

            var bindingConfig = new Mock <IBindingConfig>().Object;

            var language = Language.VBNET;
            SonarQubeQualityProfile profile = this.ConfigureQualityProfile(language, QualityProfileName);

            var configProviderMock = new Mock <IBindingConfigProvider>();

            configProviderMock.Setup(x => x.GetConfigurationAsync(profile, language, BindingConfiguration.Standalone, CancellationToken.None))
            .ReturnsAsync(bindingConfig);

            var bindingArgs = new BindCommandArgs("key", ProjectName, new ConnectionInformation(new Uri("http://connected")));
            var testSubject = this.CreateTestSubject(bindingArgs, nuGetOpMock.Object, configProviderMock.Object);

            ConfigureSupportedBindingProject(testSubject.InternalState, language);

            // Act
            var result = await testSubject.DownloadQualityProfileAsync(progressAdapter, CancellationToken.None);

            // Assert
            result.Should().BeTrue();
            testSubject.InternalState.BindingConfigs.Should().ContainKey(language);
            testSubject.InternalState.BindingConfigs[language].Should().Be(bindingConfig);
            testSubject.InternalState.BindingConfigs.Count().Should().Be(1);

            testSubject.InternalState.QualityProfiles[language].Should().Be(profile);

            notifications.AssertProgress(0.0, 1.0);
            notifications.AssertProgressMessages(Strings.DownloadingQualityProfileProgressMessage, string.Empty);

            this.outputWindowPane.AssertOutputStrings(1);
            var expectedOutput = string.Format(Strings.SubTextPaddingFormat,
                                               string.Format(Strings.QualityProfileDownloadSuccessfulMessageFormat, QualityProfileName, string.Empty, language.Name));

            this.outputWindowPane.AssertOutputStrings(expectedOutput);
        }
示例#20
0
        public async Task BindingWorkflow_DownloadQualityProfile_Fails_WorkflowAborted()
        {
            // Arrange
            ConfigurableProgressController controller = new ConfigurableProgressController();
            var notifications = new ConfigurableProgressStepExecutionEvents();

            SetDownloadQPResult(false);

            // Act
            await testSubject.DownloadQualityProfileAsync(controller, notifications, CancellationToken.None)
            .ConfigureAwait(false);

            // Assert
            controller.NumberOfAbortRequests.Should().Be(1);
        }
示例#21
0
        public void BindingWorkflow_DownloadQualityProfile_Success()
        {
            // Setup
            const string QualityProfileName   = "SQQualityProfileName";
            const string SonarQubeProjectName = "SQProjectName";
            var          projectInfo          = new ProjectInformation {
                Key = "key", Name = SonarQubeProjectName
            };
            BindingWorkflow testSubject = this.CreateTestSubject(projectInfo);
            ConfigurableProgressController controller = new ConfigurableProgressController();
            var notifications = new ConfigurableProgressStepExecutionEvents();

            RuleSet ruleSet         = TestRuleSetHelper.CreateTestRuleSetWithRuleIds(new[] { "Key1", "Key2" });
            var     expectedRuleSet = new RuleSet(ruleSet)
            {
                NonLocalizedDisplayName = string.Format(Strings.SonarQubeRuleSetNameFormat, SonarQubeProjectName, QualityProfileName),
                NonLocalizedDescription = "\r\nhttp://connected/profiles/show?key="
            };
            var nugetPackages   = new[] { new PackageName("myPackageId", new SemanticVersion("1.0.0")) };
            var additionalFiles = new[] { new AdditionalFile {
                                              FileName = "abc.xml", Content = new byte[] { 1, 2, 3 }
                                          } };
            RoslynExportProfile export = RoslynExportProfileHelper.CreateExport(ruleSet, nugetPackages, additionalFiles);

            var            language = Language.VBNET;
            QualityProfile profile  = this.ConfigureProfileExport(export, language);

            profile.Name = QualityProfileName;

            // Act
            testSubject.DownloadQualityProfile(controller, CancellationToken.None, notifications, new[] { language });

            // Verify
            RuleSetAssert.AreEqual(expectedRuleSet, testSubject.Rulesets[language], "Unexpected rule set");
            Assert.AreSame(profile, testSubject.QualityProfiles[language]);
            VerifyNuGetPackgesDownloaded(nugetPackages, testSubject, language);
            controller.AssertNumberOfAbortRequests(0);
            notifications.AssertProgress(
                0.0,
                1.0);
            notifications.AssertProgressMessages(Strings.DownloadingQualityProfileProgressMessage, string.Empty);

            this.outputWindowPane.AssertOutputStrings(1);
            var expectedOutput = string.Format(Strings.SubTextPaddingFormat,
                                               string.Format(Strings.QualityProfileDownloadSuccessfulMessageFormat, QualityProfileName, string.Empty, language.Name));

            this.outputWindowPane.AssertOutputStrings(expectedOutput);
        }
示例#22
0
        public void BindingWorkflow_DiscoverProjects_Fails_WorkflowAborted()
        {
            // Arrange
            ThreadHelper.SetCurrentThreadAsUIThread();
            var controller     = new ConfigurableProgressController();
            var progressEvents = new ConfigurableProgressStepExecutionEvents();

            mockBindingProcess.Setup(x => x.DiscoverProjects()).Returns(false);

            // Act
            testSubject.DiscoverProjects(controller, progressEvents);

            // Assert
            controller.NumberOfAbortRequests.Should().Be(1);
            progressEvents.AssertProgressMessages(Strings.DiscoveringSolutionProjectsProgressMessage);
        }
        public async Task DownloadQualityProfile_Success()
        {
            // Arrange
            const string QualityProfileName = "SQQualityProfileName";
            const string ProjectName        = "SQProjectName";

            Mock <INuGetBindingOperation> nuGetOpMock = new Mock <INuGetBindingOperation>();

            var notifications   = new ConfigurableProgressStepExecutionEvents();
            var progressAdapter = new FixedStepsProgressAdapter(notifications);

            RuleSet expectedRuleSet = TestRuleSetHelper.CreateTestRuleSetWithRuleIds(new[] { "Key1", "Key2" });
            var     configFile      = new Mock <IBindingConfigFile>().Object;

            var language = Language.VBNET;
            SonarQubeQualityProfile profile = this.ConfigureQualityProfile(language, QualityProfileName);

            var configProviderMock = new Mock <IBindingConfigProvider>();

            configProviderMock.Setup(x => x.GetConfigurationAsync(profile, null, language, CancellationToken.None))
            .ReturnsAsync(configFile);

            var testSubject = this.CreateTestSubject("key", ProjectName, nuGetOpMock.Object, configProviderMock.Object);

            ConfigureSupportedBindingProject(testSubject.InternalState, language);

            // Act
            var result = await testSubject.DownloadQualityProfileAsync(progressAdapter, CancellationToken.None);

            // Assert
            result.Should().BeTrue();
            testSubject.InternalState.BindingConfigFiles.Should().ContainKey(language);
            testSubject.InternalState.BindingConfigFiles[language].Should().Be(configFile);
            testSubject.InternalState.BindingConfigFiles.Count().Should().Be(1);

            testSubject.InternalState.QualityProfiles[language].Should().Be(profile);

            notifications.AssertProgress(0.0, 1.0);
            notifications.AssertProgressMessages(Strings.DownloadingQualityProfileProgressMessage, string.Empty);

            this.outputWindowPane.AssertOutputStrings(1);
            var expectedOutput = string.Format(Strings.SubTextPaddingFormat,
                                               string.Format(Strings.QualityProfileDownloadSuccessfulMessageFormat, QualityProfileName, string.Empty, language.Name));

            this.outputWindowPane.AssertOutputStrings(expectedOutput);
        }
        public async Task DownloadQualityProfile_SavesConfiguration()
        {
            var configPersister = new ConfigurableConfigurationProvider();

            this.serviceProvider.RegisterService(typeof(IConfigurationPersister), configPersister);

            // Arrange
            const string QualityProfileName = "SQQualityProfileName";
            const string ProjectName        = "SQProjectName";

            Mock <INuGetBindingOperation> nuGetOpMock = new Mock <INuGetBindingOperation>();

            var notifications   = new ConfigurableProgressStepExecutionEvents();
            var progressAdapter = new FixedStepsProgressAdapter(notifications);

            var bindingConfig = new Mock <IBindingConfig>().Object;

            var language = Language.VBNET;
            SonarQubeQualityProfile profile = this.ConfigureQualityProfile(language, QualityProfileName);

            var configProviderMock = new Mock <IBindingConfigProvider>();

            configProviderMock.Setup(x => x.GetConfigurationAsync(profile, language, It.IsAny <BindingConfiguration>(), CancellationToken.None))
            .ReturnsAsync(bindingConfig);

            var bindingArgs = new BindCommandArgs("key", ProjectName, new ConnectionInformation(new Uri("http://connected")));
            var testSubject = this.CreateTestSubject(bindingArgs, nuGetOpMock.Object, configProviderMock.Object);

            ConfigureSupportedBindingProject(testSubject.InternalState, language);

            // Act
            await testSubject.DownloadQualityProfileAsync(progressAdapter, CancellationToken.None);

            // Assert
            configPersister.SavedProject.Should().NotBeNull();
            configPersister.SavedMode.Should().Be(SonarLintMode.Connected);

            var savedProject = configPersister.SavedProject;

            savedProject.ServerUri.Should().Be(bindingArgs.Connection.ServerUri);
            savedProject.Profiles.Should().HaveCount(1);
            savedProject.Profiles[Language.VBNET].ProfileKey.Should().Be(profile.Key);
            savedProject.Profiles[Language.VBNET].ProfileTimestamp.Should().Be(profile.TimeStamp);
        }
        public void InstallPackages_Cancellation()
        {
            // Arrange
            var testSubject     = this.CreateTestSubject();
            var progressEvents  = new ConfigurableProgressStepExecutionEvents();
            var progressAdapter = new FixedStepsProgressAdapter(progressEvents);
            var cts             = new CancellationTokenSource();

            var project1 = new ProjectMock("project1")
            {
                ProjectKind = ProjectSystemHelper.CSharpProjectKind
            };
            var project2 = new ProjectMock("project2")
            {
                ProjectKind = ProjectSystemHelper.CSharpProjectKind
            };
            var projectsToBind = new HashSet <Project> {
                project1, project2
            };

            var nugetPackage            = new PackageName("mypackage", new SemanticVersion("1.1.0"));
            var packages                = new[] { nugetPackage };
            var nugetPackagesByLanguage = new Dictionary <Language, IEnumerable <PackageName> >();

            nugetPackagesByLanguage.Add(Language.CSharp, packages);

            ConfigurablePackageInstaller packageInstaller = this.PrepareInstallPackagesTest(testSubject, nugetPackagesByLanguage);

            packageInstaller.InstallPackageAction = (p) =>
            {
                cts.Cancel(); // Cancel the next one (should complete the first one)
            };

            // Acts
            testSubject.InstallPackages(projectsToBind, progressAdapter, cts.Token);

            // Assert
            packageInstaller.AssertInstalledPackages(project1, packages);
            packageInstaller.AssertNoInstalledPackages(project2);

            progressEvents.AssertProgress(.5);
        }
示例#26
0
        public void Run_SaveSucceeds_WorkflowContinues()
        {
            // Arrange
            configWriter.WriteResultToReturn = true;

            var controller    = new ConfigurableProgressController();
            var notifications = new ConfigurableProgressStepExecutionEvents();

            var testSubject = CreateTestSubject();

            // Act
            testSubject.SaveBindingInfo(controller, notifications, CancellationToken.None);

            // Assert
            controller.NumberOfAbortRequests.Should().Be(0);
            notifications.AssertProgressMessages(
                Strings.StartedSolutionBindingWorkflow,
                Strings.Bind_SavingBindingConfiguration,
                Strings.FinishedSolutionBindingWorkflowSuccessful);
        }
示例#27
0
        public void Run_SaveFails_WorkflowIsAborted()
        {
            // Arrange
            configWriter.WriteResultToReturn = false;

            var controller    = new ConfigurableProgressController();
            var notifications = new ConfigurableProgressStepExecutionEvents();

            var testSubject = CreateTestSubject();

            // Act
            testSubject.SaveBindingInfo(controller, notifications, CancellationToken.None);

            // Assert
            controller.NumberOfAbortRequests.Should().Be(1);
            notifications.AssertProgressMessages(
                Strings.StartedSolutionBindingWorkflow,
                Strings.Bind_SavingBindingConfiguration);
            this.outputWindowPane.AssertOutputStrings(Strings.Bind_FailedToSaveConfiguration);
        }
        private void InstallPackages_Succeed(string projectKind, Language language)
        {
            // Arrange
            var testSubject     = this.CreateTestSubject();
            var progressEvents  = new ConfigurableProgressStepExecutionEvents();
            var progressAdapter = new FixedStepsProgressAdapter(progressEvents);

            ProjectMock project1 = new ProjectMock("project1")
            {
                ProjectKind = projectKind
            };
            ProjectMock project2 = new ProjectMock("project2")
            {
                ProjectKind = projectKind
            };
            var projectsToBind = new HashSet <Project> {
                project1, project2
            };

            var nugetPackage = new PackageName("mypackage", new SemanticVersion("1.1.0"));
            var packages     = new Dictionary <Language, IEnumerable <PackageName> >();

            packages.Add(language, new[] { nugetPackage });

            ConfigurablePackageInstaller packageInstaller = this.PrepareInstallPackagesTest(testSubject, packages);

            // Act
            testSubject.InstallPackages(projectsToBind, progressAdapter, CancellationToken.None);

            // Assert
            packageInstaller.AssertInstalledPackages(project1, new[] { nugetPackage });
            packageInstaller.AssertInstalledPackages(project2, new[] { nugetPackage });
            this.logger.AssertOutputStrings(4);
            this.logger.AssertOutputStrings(
                string.Format(Strings.SubTextPaddingFormat, string.Format(Strings.EnsuringNugetPackagesProgressMessage, nugetPackage.Id, ((Project)project1).Name)),
                string.Format(Strings.SubTextPaddingFormat, string.Format(Strings.SuccessfullyInstalledNugetPackageForProject, nugetPackage.Id, ((Project)project1).Name)),
                string.Format(Strings.SubTextPaddingFormat, string.Format(Strings.EnsuringNugetPackagesProgressMessage, nugetPackage.Id, ((Project)project2).Name)),
                string.Format(Strings.SubTextPaddingFormat, string.Format(Strings.SuccessfullyInstalledNugetPackageForProject, nugetPackage.Id, ((Project)project2).Name))
                );
            progressEvents.AssertProgress(.5, 1.0);
        }
        public void InstallPackages_WhenProjectLanguageDoesNotExist_PrintMessageAndContinue()
        {
            // Arrange
            const string project1Name = "project1";
            const string project2Name = "project2";

            var testSubject     = this.CreateTestSubject();
            var progressEvents  = new ConfigurableProgressStepExecutionEvents();
            var progressAdapter = new FixedStepsProgressAdapter(progressEvents);

            ProjectMock project1 = new ProjectMock(project1Name); // No project kind so no nuget package will be installed
            ProjectMock project2 = new ProjectMock(project2Name)
            {
                ProjectKind = ProjectSystemHelper.CSharpProjectKind
            };
            var projectsToBind = new HashSet <Project> {
                project1, project2
            };

            var nugetPackage  = new PackageName("mypackage", new SemanticVersion("1.1.0"));
            var packages      = new[] { nugetPackage };
            var nugetPackages = new Dictionary <Language, IEnumerable <PackageName> >();

            nugetPackages.Add(Language.CSharp, packages);

            ConfigurablePackageInstaller packageInstaller = this.PrepareInstallPackagesTest(testSubject, nugetPackages);

            // Act
            testSubject.InstallPackages(projectsToBind, progressAdapter, CancellationToken.None);

            // Assert
            packageInstaller.AssertNoInstalledPackages(project1);
            packageInstaller.AssertInstalledPackages(project2, packages);
            this.logger.AssertOutputStrings(3);
            this.logger.AssertOutputStrings(
                string.Format(Strings.SubTextPaddingFormat, string.Format(Strings.BindingProjectLanguageNotMatchingAnyQualityProfileLanguage, project1Name)),
                string.Format(Strings.SubTextPaddingFormat, string.Format(Strings.EnsuringNugetPackagesProgressMessage, nugetPackage.Id, project2Name)),
                string.Format(Strings.SubTextPaddingFormat, string.Format(Strings.SuccessfullyInstalledNugetPackageForProject, nugetPackage.Id, project2Name))
                );
        }
        public async Task BindingWorkflow_DownloadQualityProfile_LegacyMode_WithNoNugetPackage_Fails()
        {
            // Arrange
            const string    QualityProfileName        = "SQQualityProfileName";
            const string    ProjectName               = "SQProjectName";
            var             legacyNuGetBinding        = new NuGetBindingOperation(this.host, this.host.Logger);
            BindingWorkflow testSubject               = this.CreateTestSubject("key", ProjectName, legacyNuGetBinding);
            ConfigurableProgressController controller = new ConfigurableProgressController();
            var notifications = new ConfigurableProgressStepExecutionEvents();

            RuleSet ruleSet         = TestRuleSetHelper.CreateTestRuleSetWithRuleIds(new[] { "Key1", "Key2" });
            var     expectedRuleSet = new RuleSet(ruleSet)
            {
                NonLocalizedDisplayName = string.Format(Strings.SonarQubeRuleSetNameFormat, ProjectName, QualityProfileName),
                NonLocalizedDescription = "\r\nhttp://connected/profiles/show?key="
            };
            var additionalFiles = new[] { new AdditionalFileResponse {
                                              FileName = "abc.xml", Content = new byte[] { 1, 2, 3 }
                                          } };
            RoslynExportProfileResponse export = RoslynExportProfileHelper.CreateExport(ruleSet, Enumerable.Empty <PackageName>(), additionalFiles);

            var language = Language.VBNET;
            SonarQubeQualityProfile profile = this.ConfigureProfileExport(export, language, QualityProfileName);

            // Act
            await testSubject.DownloadQualityProfileAsync(controller, notifications, new[] { language }, CancellationToken.None);

            // Assert
            testSubject.Rulesets.Should().NotContainKey(Language.VBNET, "Not expecting any rules for this language");
            testSubject.Rulesets.Should().NotContainKey(language, "Not expecting any rules");
            controller.NumberOfAbortRequests.Should().Be(1);

            notifications.AssertProgressMessages(Strings.DownloadingQualityProfileProgressMessage);

            this.outputWindowPane.AssertOutputStrings(1);
            var expectedOutput = string.Format(Strings.SubTextPaddingFormat,
                                               string.Format(Strings.NoNuGetPackageForQualityProfile, language.Name));

            this.outputWindowPane.AssertOutputStrings(expectedOutput);
        }
示例#31
0
        private void BindingWorkflow_InstallPackages_Succeed(string projectKind, Language language)
        {
            // Setup
            var testSubject    = this.CreateTestSubject();
            var progressEvents = new ConfigurableProgressStepExecutionEvents();

            ProjectMock project1 = new ProjectMock("project1")
            {
                ProjectKind = projectKind
            };
            ProjectMock project2 = new ProjectMock("project2")
            {
                ProjectKind = projectKind
            };

            var nugetPackage = new PackageName("mypackage", new SemanticVersion("1.1.0"));
            var packages     = new Dictionary <Language, IEnumerable <PackageName> >();

            packages.Add(language, new[] { nugetPackage });

            ConfigurablePackageInstaller packageInstaller = this.PrepareInstallPackagesTest(testSubject, packages, project1, project2);

            // Act
            testSubject.InstallPackages(new ConfigurableProgressController(), CancellationToken.None, progressEvents);

            // Verify
            packageInstaller.AssertInstalledPackages(project1, new[] { nugetPackage });
            packageInstaller.AssertInstalledPackages(project2, new[] { nugetPackage });
            this.outputWindowPane.AssertOutputStrings(4);
            this.outputWindowPane.AssertOutputStrings(
                string.Format(Strings.SubTextPaddingFormat, string.Format(Strings.EnsuringNugetPackagesProgressMessage, nugetPackage.Id, ((Project)project1).Name)),
                string.Format(Strings.SubTextPaddingFormat, string.Format(Strings.SuccessfullyInstalledNugetPackageForProject, nugetPackage.Id, ((Project)project1).Name)),
                string.Format(Strings.SubTextPaddingFormat, string.Format(Strings.EnsuringNugetPackagesProgressMessage, nugetPackage.Id, ((Project)project2).Name)),
                string.Format(Strings.SubTextPaddingFormat, string.Format(Strings.SuccessfullyInstalledNugetPackageForProject, nugetPackage.Id, ((Project)project2).Name))
                );
            progressEvents.AssertProgress(
                .5,
                1.0);
        }
        public void BindingWorkflow_DiscoverProjects_AddsMatchingProjectsToBinding()
        {
            // Setup
            ThreadHelper.SetCurrentThreadAsUIThread();
            var controller = new ConfigurableProgressController();
            var progressEvents = new ConfigurableProgressStepExecutionEvents();

            var csProject1 = new ProjectMock("cs1.csproj");
            var csProject2 = new ProjectMock("cs2.csproj");
            csProject1.SetCSProjectKind();
            csProject2.SetCSProjectKind();

            var matchingProjects = new[] { csProject1, csProject2 };
            this.projectSystemHelper.FilteredProjects = matchingProjects;

            var testSubject = this.CreateTestSubject();

            // Act
            testSubject.DiscoverProjects(controller, progressEvents);

            // Verify
            CollectionAssert.AreEqual(matchingProjects, testSubject.BindingProjects.ToArray(), "Unexpected projects selected for binding");
            progressEvents.AssertProgressMessages(Strings.DiscoveringSolutionProjectsProgressMessage);
        }
        public void BindingWorkflow_DiscoverProjects_NoMatchingProjects_AbortsWorkflow()
        {
            // Setup
            ThreadHelper.SetCurrentThreadAsUIThread();
            var controller = new ConfigurableProgressController();
            var progressEvents = new ConfigurableProgressStepExecutionEvents();
            this.projectSystemHelper.FilteredProjects = null;

            var testSubject = this.CreateTestSubject();

            // Act
            testSubject.DiscoverProjects(controller, progressEvents);

            // Verify
            Assert.AreEqual(0, testSubject.BindingProjects.Count, "Expected no projects selected for binding");
            progressEvents.AssertProgressMessages(Strings.DiscoveringSolutionProjectsProgressMessage);
            this.outputWindowPane.AssertOutputStrings(Strings.NoProjectsApplicableForBinding);
            controller.AssertNumberOfAbortRequests(1);
        }
        public void BindingWorkflow_EmitBindingCompleteMessage()
        {
            // Setup
            var testSubject = this.CreateTestSubject();

            // Test case 1: Default state is 'true'
            Assert.IsTrue(testSubject.AllNuGetPackagesInstalled, $"Initial state of {nameof(BindingWorkflow.AllNuGetPackagesInstalled)} should be true");

            // Test case 2: All packages installed
            // Setup
            var notificationsOk = new ConfigurableProgressStepExecutionEvents();
            testSubject.AllNuGetPackagesInstalled = true;

            // Act
            testSubject.EmitBindingCompleteMessage(notificationsOk);

            // Verify
            notificationsOk.AssertProgressMessages(string.Format(CultureInfo.CurrentCulture, Strings.FinishedSolutionBindingWorkflowSuccessful));

            // Test case 3: Not all packages installed
            // Setup
            var notificationsFail = new ConfigurableProgressStepExecutionEvents();
            testSubject.AllNuGetPackagesInstalled = false;

            // Act
            testSubject.EmitBindingCompleteMessage(notificationsFail);

            // Verify
            notificationsFail.AssertProgressMessages(string.Format(CultureInfo.CurrentCulture, Strings.FinishedSolutionBindingWorkflowNotAllPackagesInstalled));
        }
        public void BindingWorkflow_InstallPackages_FailureOnOneProject_Continues()
        {
            // Setup
            const string failureMessage = "Failure for project1";
            const string project1Name = "project1";
            const string project2Name = "project2";

            var testSubject = this.CreateTestSubject();
            var progressEvents = new ConfigurableProgressStepExecutionEvents();
            var cts = new CancellationTokenSource();

            ProjectMock project1 = new ProjectMock(project1Name);
            ProjectMock project2 = new ProjectMock(project2Name);

            var nugetPackage = new PackageName("mypackage", new SemanticVersion("1.1.0"));
            var packages = new[] { nugetPackage };

            ConfigurablePackageInstaller packageInstaller = this.PrepareInstallPackagesTest(testSubject, packages, project1, project2);
            packageInstaller.InstallPackageAction = (p) =>
            {
                packageInstaller.InstallPackageAction = null;
                throw new Exception(failureMessage);
            };

            // Act
            testSubject.InstallPackages(new ConfigurableProgressController(), cts.Token, progressEvents);

            // Verify
            packageInstaller.AssertNoInstalledPackages(project1);
            packageInstaller.AssertInstalledPackages(project2, packages);
            outputWindowPane.AssertOutputStrings(string.Format(CultureInfo.CurrentCulture, Strings.FailedDuringNuGetPackageInstall, nugetPackage.Id, project1Name, failureMessage));
        }
        public void BindingWorkflow_InstallPackages_Cancellation()
        {
            // Setup
            var testSubject = this.CreateTestSubject();
            var progressEvents = new ConfigurableProgressStepExecutionEvents();
            var cts = new CancellationTokenSource();

            ProjectMock project1 = new ProjectMock("project1");
            ProjectMock project2 = new ProjectMock("project2");

            var nugetPackage = new PackageName("mypackage", new SemanticVersion("1.1.0"));
            var packages = new[] { nugetPackage };

            ConfigurablePackageInstaller packageInstaller = this.PrepareInstallPackagesTest(testSubject, packages, project1, project2);
            packageInstaller.InstallPackageAction = (p) =>
            {
                cts.Cancel(); // Cancel the next one (should complete the first one)
            };

            // Act
            testSubject.InstallPackages(new ConfigurableProgressController(), cts.Token, progressEvents);

            // Verify
            packageInstaller.AssertInstalledPackages(project1, packages);
            packageInstaller.AssertNoInstalledPackages(project2);
        }
        public void BindingWorkflow_InstallPackages()
        {
            // Setup
            var testSubject = this.CreateTestSubject();
            var progressEvents = new ConfigurableProgressStepExecutionEvents();

            ProjectMock project1 = new ProjectMock("project1");
            ProjectMock project2 = new ProjectMock("project2");

            var nugetPackage = new PackageName("mypackage", new SemanticVersion("1.1.0"));
            var packages = new[] { nugetPackage };

            ConfigurablePackageInstaller packageInstaller = this.PrepareInstallPackagesTest(testSubject, packages, project1, project2);

            // Act
            testSubject.InstallPackages(new ConfigurableProgressController(), CancellationToken.None, progressEvents);

            // Verify
            packageInstaller.AssertInstalledPackages(project1, packages);
            packageInstaller.AssertInstalledPackages(project2, packages);
            progressEvents.AssertProgressMessages(
                string.Format(CultureInfo.CurrentCulture, Strings.EnsuringNugetPackagesProgressMessage, nugetPackage.Id, ((Project)project1).Name),
                string.Empty,
                string.Format(CultureInfo.CurrentCulture, Strings.EnsuringNugetPackagesProgressMessage, nugetPackage.Id, ((Project)project2).Name),
                string.Empty);
            progressEvents.AssertProgress(
                0,
                .5,
                .5,
                1.0);
        }
        public void BindingWorkflow_DiscoverProjects_OutputsExcludedProjects()
        {
            // Setup
            ThreadHelper.SetCurrentThreadAsUIThread();
            var controller = new ConfigurableProgressController();
            var progressEvents = new ConfigurableProgressStepExecutionEvents();

            List<Project> projects = new List<Project>();
            for (int i = 0; i < 4; i++)
            {
                projects.Add(new ProjectMock($"cs{i}.csproj"));
            }

            this.projectSystemHelper.FilteredProjects = projects.Take(2);
            this.projectSystemHelper.Projects = projects;

            var testSubject = this.CreateTestSubject();

            // Act
            testSubject.DiscoverProjects(controller, progressEvents);

            // Verify
            this.outputWindowPane.AssertOutputStrings(1);
            this.outputWindowPane.AssertMessageContainsAllWordsCaseSensitive(0, new[] { projects[2].UniqueName, projects[3].UniqueName });
        }