/// <summary> /// Verifies that the <see cref="ProgressControllerStep"/> was initialized correctly /// </summary> /// <param name="testSubject">The step to verify</param> /// <param name="attributes">Step attributes</param> /// <param name="displayText">Step display text</param> public static void VerifyInitialized(ProgressControllerStep testSubject, StepAttributes attributes, string displayText = null) { StepExecution expectedExecution = (attributes & StepAttributes.BackgroundThread) != 0 ? StepExecution.BackgroundThread : StepExecution.ForegroundThread; bool expectedHidden = (attributes & StepAttributes.Hidden) != 0 ? true : false; bool expectedCancellable = (attributes & StepAttributes.NonCancellable) != 0 ? false : true; bool expectedImpactingProgress = (attributes & StepAttributes.NoProgressImpact) != 0 ? false : true; bool expectedIndeterminate = (attributes & StepAttributes.Indeterminate) != 0 ? true : false; CheckState(testSubject, StepExecutionState.NotStarted); Assert.AreEqual(displayText, testSubject.DisplayText, "Unexpected display text"); Assert.AreEqual(expectedCancellable, testSubject.Cancellable, "Cancellable: Unexpected post initialization value"); Assert.AreEqual(expectedIndeterminate, testSubject.Indeterminate, "Indeterminate: Unexpected post initialization value"); Assert.AreEqual(expectedExecution, testSubject.Execution, "Execution: Unexpected post initialization value"); Assert.AreEqual(expectedHidden, testSubject.Hidden, "Hidden: Unexpected post initialization value"); Assert.AreEqual(expectedImpactingProgress, testSubject.ImpactsProgress, "ImpactingProgress: Unexpected post initialization value"); if (expectedIndeterminate) { Assert.IsTrue(ProgressControllerHelper.IsIndeterminate(testSubject.Progress), "Progess: Should be Indeterminate"); } else { Assert.AreEqual(0, testSubject.Progress, "Progress: Unexpected post initialization value"); } }
private void InitializeAndExecuteTestSubject(string text, StepAttributes attributes, Action <CancellationToken, IProgressStepExecutionEvents> operation) { // Arrange this.testSubject = new ProgressControllerStep(this.testController, new ProgressStepDefinition(text, attributes, operation)); // Assert initialized state VerificationHelper.VerifyInitialized(this.testSubject, attributes, text); // Act by the controller this.testController.Execute(this.testSubject); }
public ProgressStepDefinition(string displayText, StepAttributes attributes, Action <CancellationToken, IProgressStepExecutionEvents> operation) { if (operation == null) { throw new ArgumentNullException(nameof(operation)); } this.DisplayText = displayText; this.Attributes = attributes; this.Operation = operation; }
public ProgressStepDefinition(string displayText, StepAttributes attributes, Action<CancellationToken, IProgressStepExecutionEvents> operation) { if (operation == null) { throw new ArgumentNullException(nameof(operation)); } this.DisplayText = displayText; this.Attributes = attributes; this.Operation = operation; }
public void ProgressControllerStep_States() { int maxFlag = ((int[])Enum.GetValues(typeof(StepAttributes))).Max(); for (int i = 0; i <= maxFlag; i++) { StepAttributes attributes = (StepAttributes)i; string text = (attributes & StepAttributes.Hidden) != 0 ? null : Environment.TickCount.ToString(); this.InitializeAndExecuteTestSubject(text, attributes, this.ExecuteAndVerify); // Assert VerificationHelper.CheckState(this.testSubject, StepExecutionState.Succeeded); this.testController.progressChanges.Should().BeEmpty(); } }
private ProgressStepDefinition[] CreateWorkflowSteps(IProgressController controller) { StepAttributes IndeterminateNonCancellableUIStep = StepAttributes.Indeterminate | StepAttributes.NonCancellable; StepAttributes HiddenIndeterminateNonImpactingNonCancellableUIStep = IndeterminateNonCancellableUIStep | StepAttributes.Hidden | StepAttributes.NoProgressImpact; StepAttributes HiddenNonImpactingBackgroundStep = StepAttributes.BackgroundThread | StepAttributes.Hidden | StepAttributes.NoProgressImpact; return(new ProgressStepDefinition[] { new ProgressStepDefinition(null, HiddenNonImpactingBackgroundStep, (token, notifications) => notifications.ProgressChanged(Strings.StartedSolutionBindingWorkflow)), new ProgressStepDefinition(null, StepAttributes.Indeterminate | StepAttributes.Hidden, (token, notifications) => this.PromptSaveSolutionIfDirty(controller, token)), new ProgressStepDefinition(Strings.BindingProjectsDisplayMessage, StepAttributes.Indeterminate, (token, notifications) => this.DiscoverProjects(controller, notifications)), new ProgressStepDefinition(Strings.BindingProjectsDisplayMessage, StepAttributes.BackgroundThread, (token, notifications) => this.DownloadQualityProfileAsync(controller, notifications, this.GetBindingLanguages(), token).GetAwaiter().GetResult()), new ProgressStepDefinition(null, HiddenIndeterminateNonImpactingNonCancellableUIStep, (token, notifications) => { NuGetHelper.LoadService(this.host); /*The service needs to be loaded on UI thread*/ }), new ProgressStepDefinition(Strings.BindingProjectsDisplayMessage, StepAttributes.BackgroundThread, (token, notifications) => this.InstallPackages(controller, token, notifications)), new ProgressStepDefinition(Strings.BindingProjectsDisplayMessage, IndeterminateNonCancellableUIStep, (token, notifications) => this.InitializeSolutionBindingOnUIThread(notifications)), new ProgressStepDefinition(Strings.BindingProjectsDisplayMessage, StepAttributes.BackgroundThread | StepAttributes.Indeterminate, (token, notifications) => this.PrepareSolutionBinding(token)), new ProgressStepDefinition(null, StepAttributes.Hidden | StepAttributes.Indeterminate, (token, notifications) => this.FinishSolutionBindingOnUIThread(controller, token)), new ProgressStepDefinition(null, HiddenIndeterminateNonImpactingNonCancellableUIStep, (token, notifications) => this.SilentSaveSolutionIfDirty()), new ProgressStepDefinition(null, HiddenNonImpactingBackgroundStep, (token, notifications) => this.EmitBindingCompleteMessage(notifications)) }); }
private ProgressStepDefinition[] CreateWorkflowSteps(IProgressController controller) { const StepAttributes IndeterminateNonCancellableUIStep = StepAttributes.Indeterminate | StepAttributes.NonCancellable; const StepAttributes HiddenIndeterminateNonImpactingNonCancellableUIStep = IndeterminateNonCancellableUIStep | StepAttributes.Hidden | StepAttributes.NoProgressImpact; const StepAttributes HiddenNonImpactingBackgroundStep = StepAttributes.BackgroundThread | StepAttributes.Hidden | StepAttributes.NoProgressImpact; return(new ProgressStepDefinition[] { // Some of the steps are broken into multiple sub-steps, either // because the work needs to be done on a different thread or // to report progress separate. //***************************************************************** // Initialization //***************************************************************** // Show an initial message and check the solution isn't dirty new ProgressStepDefinition(null, HiddenNonImpactingBackgroundStep, (token, notifications) => notifications.ProgressChanged(Strings.StartedSolutionBindingWorkflow)), new ProgressStepDefinition(null, StepAttributes.Indeterminate | StepAttributes.Hidden, (token, notifications) => this.PromptSaveSolutionIfDirty(controller, token)), //***************************************************************** // Preparation //***************************************************************** // Check for eligible projects in the solution new ProgressStepDefinition(Strings.BindingProjectsDisplayMessage, StepAttributes.Indeterminate, (token, notifications) => this.DiscoverProjects(controller, notifications)), // Fetch data from Sonar server and write shared ruleset file(s) to temporary location on disk new ProgressStepDefinition(Strings.BindingProjectsDisplayMessage, StepAttributes.BackgroundThread, (token, notifications) => this.DownloadQualityProfileAsync(controller, notifications, this.GetBindingLanguages(), token).GetAwaiter().GetResult()), //***************************************************************** // NuGet package handling //***************************************************************** // Initialize the VS NuGet installer service new ProgressStepDefinition(null, HiddenIndeterminateNonImpactingNonCancellableUIStep, (token, notifications) => { this.PrepareToInstallPackages(); }), // Install the appropriate package for each project new ProgressStepDefinition(Strings.BindingProjectsDisplayMessage, StepAttributes.BackgroundThread, (token, notifications) => this.InstallPackages(controller, notifications, token)), //***************************************************************** // Solution update phase //***************************************************************** // * copy shared ruleset to shared location // * add files to solution // * create/update per-project ruleset // * set project-level properties // Most of the work is delegated to SolutionBindingOperation new ProgressStepDefinition(Strings.BindingProjectsDisplayMessage, IndeterminateNonCancellableUIStep, (token, notifications) => this.InitializeSolutionBindingOnUIThread(notifications)), new ProgressStepDefinition(Strings.BindingProjectsDisplayMessage, StepAttributes.BackgroundThread | StepAttributes.Indeterminate, (token, notifications) => this.PrepareSolutionBinding(token)), new ProgressStepDefinition(null, StepAttributes.Hidden | StepAttributes.Indeterminate, (token, notifications) => this.FinishSolutionBindingOnUIThread(controller, token)), //***************************************************************** // Finalization //***************************************************************** // Save solution and show message new ProgressStepDefinition(null, HiddenIndeterminateNonImpactingNonCancellableUIStep, (token, notifications) => this.SilentSaveSolutionIfDirty()), new ProgressStepDefinition(null, HiddenNonImpactingBackgroundStep, (token, notifications) => this.EmitBindingCompleteMessage(notifications)) }); }
private void InitializeAndExecuteTestSubject(string text, StepAttributes attributes, Action<CancellationToken, IProgressStepExecutionEvents> operation) { // Setup this.testSubject = new ProgressControllerStep(this.testController, new ProgressStepDefinition(text, attributes, operation)); // Verify initialized state VerificationHelper.VerifyInitialized(this.testSubject, attributes, text); // Execute by the controller this.testController.Execute(this.testSubject); }