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 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_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 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); }
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 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); }
private void BindingWorkflow_DiscoverProjects_GenericPart(ConfigurableProgressController controller, ConfigurableProgressStepExecutionEvents progressEvents, int numberOfProjectsToCreate, int numberOfProjectsToInclude) { // Arrange List <Project> projects = new List <Project>(); for (int i = 0; i < numberOfProjectsToCreate; i++) { var project = new ProjectMock($"cs{i}.csproj"); project.SetCSProjectKind(); projects.Add(project); } this.projectSystemHelper.FilteredProjects = projects.Take(numberOfProjectsToInclude); this.projectSystemHelper.Projects = projects; var testSubject = this.CreateTestSubject(); this.host.SupportedPluginLanguages.UnionWith(new[] { Language.CSharp }); // Act testSubject.DiscoverProjects(controller, progressEvents); // Assert testSubject.BindingProjects.Should().HaveCount(numberOfProjectsToInclude, "Expected " + numberOfProjectsToInclude + " project(s) selected for binding"); progressEvents.AssertProgressMessages(Strings.DiscoveringSolutionProjectsProgressMessage); this.outputWindowPane.AssertOutputStrings(1); // Returns expected output message var expectedOutput = new StringBuilder(); expectedOutput.AppendFormat(Strings.SubTextPaddingFormat, Strings.DiscoveringSolutionIncludedProjectsHeader).AppendLine(); if (numberOfProjectsToInclude > 0) { this.projectSystemHelper.FilteredProjects.ToList().ForEach(p => expectedOutput.AppendFormat(" * {0}\r\n", p.Name)); } else { var msg = string.Format(Strings.DiscoveredIncludedOrExcludedProjectFormat, Strings.NoProjectsExcludedFromBinding); expectedOutput.AppendFormat(Strings.SubTextPaddingFormat, msg).AppendLine(); } expectedOutput.AppendFormat(Strings.SubTextPaddingFormat, Strings.DiscoveringSolutionExcludedProjectsHeader).AppendLine(); if (numberOfProjectsToCreate - numberOfProjectsToInclude > 0) { this.projectSystemHelper.Projects.Except(this.projectSystemHelper.FilteredProjects) .ToList() .ForEach(p => expectedOutput.AppendFormat(" * {0}\r\n", p.Name)); } else { var msg = string.Format(Strings.DiscoveredIncludedOrExcludedProjectFormat, Strings.NoProjectsExcludedFromBinding); expectedOutput.AppendFormat(Strings.SubTextPaddingFormat, msg).AppendLine(); } expectedOutput.AppendFormat(Strings.SubTextPaddingFormat, Strings.FilteredOutProjectFromBindingEnding); this.outputWindowPane.AssertOutputStrings(expectedOutput.ToString()); }
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_InitializeSolutionBindingOnUIThread_NoError() { // Arrange var progressEvents = new ConfigurableProgressStepExecutionEvents(); // Act testSubject.InitializeSolutionBindingOnUIThread(progressEvents); // Assert mockBindingProcess.Verify(x => x.InitializeSolutionBindingOnUIThread(), Times.Once); progressEvents.AssertProgressMessages(Strings.RuleSetGenerationProgressMessage); }
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); }
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); }
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 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); }
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); }
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); }
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_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_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_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); }