public void SequentialProgressController_IProgressController_TryAbort_ControllerDrivenCancellation() { // Arrange ConfigurableProgressStepFactory testFactory = new ConfigurableProgressStepFactory(); ConfigurableProgressTestOperation stepOperation = new ConfigurableProgressTestOperation(this.DoNothing) { CancellableAction = () => { // Using this opportunity to abort - the test assumes that Cancellable is called before the step is actually executed this.testSubject.TryAbort().Should().BeTrue("Should be able to abort"); return(true); } }; testFactory.CreateOpeartion = (d) => stepOperation; ProgressEventsVerifier verifier = new ProgressEventsVerifier(this.testSubject); this.testSubject.Initialize(testFactory, new[] { new StubProgressStepDefinition() }); // Act this.testSubject.StartAsync().Wait(); // Assert verifier.AssertCorrectExecution(ProgressControllerResult.Cancelled); verifier.AssertStepCorrectExecution(stepOperation, StepExecutionState.NotStarted); verifier.AssertCancellationChanges(3); }
public void ProgressObserver_EventMonitoringAndExecution_ViewModelOutOfSync() { ConfigurableProgressTestOperation step = new ConfigurableProgressTestOperation((c, e) => { }) { Progress = 0.0, Indeterminate = false, ExecutionState = StepExecutionState.NotStarted }; this.progressEvents.Steps = new IProgressStep[] { step }; this.CreateTestSubject(); // Create another step which is not observed ConfigurableProgressTestOperation anotherStep = new ConfigurableProgressTestOperation((c, e) => { }) { ExecutionState = StepExecutionState.Succeeded, Progress = 1.0, Indeterminate = false }; using (new AssertIgnoreScope()) { this.progressEvents.InvokeStepExecutionChanged(new StepExecutionChangedEventArgs(anotherStep)); } this.testVisualizer.Root.MainProgress.Value.Should().Be(0.0, "The main progress should not change"); }
private static ConfigurableProgressTestOperation[] CreateRandomSteps(int numberOfSteps, bool visible, bool indeterminate, bool impacting) { ConfigurableProgressTestOperation[] steps = new ConfigurableProgressTestOperation[numberOfSteps]; for (int i = 0; i < steps.Length; i++) { steps[i] = CreateRandomStep(visible, indeterminate, impacting); } return(steps); }
public void ProgressObserver_EventMonitoringAndExecution() { // Arrange - Create a determinate not started step int initialProgress = 0; string initialProgressDetails = null; ConfigurableProgressTestOperation step = new ConfigurableProgressTestOperation((c, e) => { }) { Progress = initialProgress, ProgressDetailText = initialProgressDetails, Indeterminate = false, ExecutionState = StepExecutionState.NotStarted, ImpactsProgress = true }; this.progressEvents.Steps = new IProgressStep[] { step }; this.CreateTestSubject(); this.threadService.SetCurrentThreadIsUIThread(false); // Show this.testVisualizer.IsShown.Should().BeFalse(); this.testSubject.IsFinished.Should().BeFalse("Not started"); this.progressEvents.InvokeStarted(); this.testSubject.IsFinished.Should().BeFalse("Just started"); this.testVisualizer.IsShown.Should().BeTrue(); // Cancellability change this.progressEvents.InvokeCancellationSupportChanged(false); this.testVisualizer.Root.Cancellable.Should().BeFalse("Unexpected cancellable state"); this.progressEvents.InvokeCancellationSupportChanged(true); this.testVisualizer.Root.Cancellable.Should().BeTrue("Unexpected cancellable state"); ProgressStepViewModel viewModelStep = this.testVisualizer.Root.Steps[0]; // Step execution changed viewModelStep.ExecutionState.Should().Be(StepExecutionState.NotStarted, "Inconclusive: unexpected initial state"); step.ExecutionState = StepExecutionState.Executing; this.progressEvents.InvokeStepExecutionChanged(new StepExecutionChangedEventArgs(step)); viewModelStep.ExecutionState.Should().Be(StepExecutionState.Executing, "Execution state wasn't changed as expected"); // Step progress reporting step.ProgressDetailText = "Hello world"; step.Progress = 1.0; viewModelStep.Progress.Value.Should().Be(initialProgress, "Inconclusive: unexpected initial Progress"); viewModelStep.ProgressDetailText.Should().Be(initialProgressDetails, "Inconclusive: unexpected initial ProgressDetailText"); this.progressEvents.InvokeStepExecutionChanged(new StepExecutionChangedEventArgs(step)); viewModelStep.Progress.Value.Should().Be(step.Progress, "Progress wasn't changed as expected"); viewModelStep.ProgressDetailText.Should().Be(step.ProgressDetailText, "ProgressDetailText wasn't changed as expected"); // Hide this.testSubject.IsFinished.Should().BeFalse("Not done yet"); this.progressEvents.InvokeFinished(ProgressControllerResult.Cancelled /*doesn't matter*/); this.testSubject.IsFinished.Should().BeTrue("Can celled - > Finished"); this.testVisualizer.IsShown.Should().BeFalse(); }
public void SequentialProgressController_IProgressController_Start() { // Arrange ConfigurableProgressStepFactory testFactory = new ConfigurableProgressStepFactory(); ConfigurableProgressTestOperation stepOperation = new ConfigurableProgressTestOperation(this.VerifyControllerExecuting); testFactory.CreateOpeartion = (d) => stepOperation; this.testSubject.Initialize(testFactory, new[] { new StubProgressStepDefinition() }); this.testSubject.IsStarted.Should().BeFalse("Wasn't started yet"); this.testSubject.IsFinished.Should().BeFalse("Wasn't started yet"); // Act this.testSubject.StartAsync().Wait(); this.testSubject.IsStarted.Should().BeTrue("Was started"); this.testSubject.IsFinished.Should().BeTrue("Was finished"); }
private static ConfigurableProgressTestOperation CreateRandomStep(bool visible, bool indeterminate, bool impacting) { Random random = new Random(); int maxFlag = ((int[])Enum.GetValues(typeof(StepExecutionState))).Max(); StepExecutionState executionState = (StepExecutionState)random.Next(0, maxFlag + 1); ConfigurableProgressTestOperation step; step = new ConfigurableProgressTestOperation((c, e) => { }); step.DisplayText = "DisplayText:" + Environment.TickCount.ToString(); step.ExecutionState = executionState; step.Progress = random.NextDouble(); step.ProgressDetailText = "ProgressDetailText:" + Environment.TickCount.ToString(); step.Indeterminate = indeterminate; step.Hidden = !visible; step.ImpactsProgress = impacting; return(step); }
private static ConfigurableProgressTestOperation CreateRandomStep(bool visible, bool indeterminate, bool impacting) { Random random = new Random(); int maxFlag = ((int[])Enum.GetValues(typeof(StepExecutionState))).Max(); StepExecutionState executionState = (StepExecutionState)random.Next(0, maxFlag + 1); ConfigurableProgressTestOperation step; step = new ConfigurableProgressTestOperation((c, e) => { }); step.DisplayText = "DisplayText:" + Environment.TickCount.ToString(); step.ExecutionState = executionState; step.Progress = random.NextDouble(); step.ProgressDetailText = "ProgressDetailText:" + Environment.TickCount.ToString(); step.Indeterminate = indeterminate; step.Hidden = !visible; step.ImpactsProgress = impacting; return step; }
private static ConfigurableProgressTestOperation[] CreateRandomSteps(int numberOfSteps, bool visible, bool indeterminate, bool impacting) { ConfigurableProgressTestOperation[] steps = new ConfigurableProgressTestOperation[numberOfSteps]; for (int i = 0; i < steps.Length; i++) { steps[i] = CreateRandomStep(visible, indeterminate, impacting); } return steps; }
public void ProgressObserver_EventMonitoringAndExecution() { // Setup - Create a determinate not started step int initialProgress = 0; string initialProgressDetails = null; ConfigurableProgressTestOperation step = new ConfigurableProgressTestOperation((c, e) => { }); step.Progress = initialProgress; step.ProgressDetailText = initialProgressDetails; step.Indeterminate = false; step.ExecutionState = StepExecutionState.NotStarted; step.ImpactsProgress = true; this.progressEvents.Steps = new IProgressStep[] { step }; this.CreateTestSubject(); this.threadService.SetCurrentThreadIsUIThread(false); // Show this.testVisualizer.AssertIsHidden(); Assert.IsFalse(this.testSubject.IsFinished, "Not started"); this.progressEvents.InvokeStarted(); Assert.IsFalse(this.testSubject.IsFinished, "Just started"); this.testVisualizer.AssertIsShown(); // Cancellability change this.progressEvents.InvokeCancellationSupportChanged(false); Assert.IsFalse(this.testVisualizer.Root.Cancellable, "Unexpected cancellable state"); this.progressEvents.InvokeCancellationSupportChanged(true); Assert.IsTrue(this.testVisualizer.Root.Cancellable, "Unexpected cancellable state"); ProgressStepViewModel viewModelStep = this.testVisualizer.Root.Steps[0]; // Step execution changed Assert.AreEqual(StepExecutionState.NotStarted, viewModelStep.ExecutionState, "Inconclusive: unexpected initial state"); step.ExecutionState = StepExecutionState.Executing; this.progressEvents.InvokeStepExecutionChanged(new StepExecutionChangedEventArgs(step)); Assert.AreEqual(StepExecutionState.Executing, viewModelStep.ExecutionState, "Execution state wasn't changed as expected"); // Step progress reporting step.ProgressDetailText = "Hello world"; step.Progress = 1.0; Assert.AreEqual(initialProgress, viewModelStep.Progress.Value, "Inconclusive: unexpected initial Progress"); Assert.AreEqual(initialProgressDetails, viewModelStep.ProgressDetailText, "Inconclusive: unexpected initial ProgressDetailText"); this.progressEvents.InvokeStepExecutionChanged(new StepExecutionChangedEventArgs(step)); Assert.AreEqual(step.Progress, viewModelStep.Progress.Value, "Progress wasn't changed as expected"); Assert.AreEqual(step.ProgressDetailText, viewModelStep.ProgressDetailText, "ProgressDetailText wasn't changed as expected"); // Hide Assert.IsFalse(this.testSubject.IsFinished, "Not done yet"); this.progressEvents.InvokeFinished(ProgressControllerResult.Cancelled/*doesn't matter*/); Assert.IsTrue(this.testSubject.IsFinished, "Can celled - > Finished"); this.testVisualizer.AssertIsHidden(); }
public void ProgressObserver_EventMonitoringAndExecution_ViewModelOutOfSync() { ConfigurableProgressTestOperation step = new ConfigurableProgressTestOperation((c, e) => { }); step.Progress = 0.0; step.Indeterminate = false; step.ExecutionState = StepExecutionState.NotStarted; this.progressEvents.Steps = new IProgressStep[] { step }; this.CreateTestSubject(); // Create another step which is not observed ConfigurableProgressTestOperation anotherStep = new ConfigurableProgressTestOperation((c, e) => { }); anotherStep.ExecutionState = StepExecutionState.Succeeded; anotherStep.Progress = 1.0; anotherStep.Indeterminate = false; using (new AssertIgnoreScope()) { this.progressEvents.InvokeStepExecutionChanged(new StepExecutionChangedEventArgs(anotherStep)); } Assert.AreEqual(0.0, this.testVisualizer.Root.MainProgress.Value, "The main progress should not change"); }
public void ProgressObserver_ProgressUpdate_VisibleHiddenNotImpacting() { // Setup bool randomIndeterminate = Environment.TickCount % 2 == 0; ConfigurableProgressTestOperation noImpacting1 = CreateRandomStep(visible: true, indeterminate: randomIndeterminate, impacting: false); noImpacting1.ExecutionState = StepExecutionState.NotStarted; noImpacting1.Progress = 0; ConfigurableProgressTestOperation hidden1 = CreateRandomStep(visible: false, indeterminate: false, impacting: true); hidden1.ExecutionState = StepExecutionState.NotStarted; hidden1.Progress = 0; ConfigurableProgressTestOperation noImpacting2 = CreateRandomStep(visible: true, indeterminate: randomIndeterminate, impacting: false); noImpacting2.ExecutionState = StepExecutionState.NotStarted; noImpacting2.Progress = 0; ConfigurableProgressTestOperation visible1 = CreateRandomStep(visible: true, indeterminate: false, impacting: true); visible1.ExecutionState = StepExecutionState.NotStarted; visible1.Progress = 0; ConfigurableProgressTestOperation visible2 = CreateRandomStep(visible: true, indeterminate: false, impacting: true); visible2.ExecutionState = StepExecutionState.NotStarted; visible2.Progress = 0; ConfigurableProgressTestOperation hidden2 = CreateRandomStep(visible: false, indeterminate: false, impacting: true); hidden2.ExecutionState = StepExecutionState.NotStarted; hidden2.Progress = 0; ConfigurableProgressTestOperation[] steps = new[] { noImpacting1, hidden1, noImpacting2, visible1, visible2, hidden2 }; this.progressEvents.Steps = steps; this.CreateTestSubject(); double mainProgressSections = steps.Count(s => s.ImpactsProgress); // Verify initial state VerifyProgress(this.testVisualizer, 0, null, 0); ExecutionVerifier verifier = new ExecutionVerifier(this.testVisualizer, this.testSubject); verifier.AppendStepToGroup(0, hidden1); verifier.AppendStepToGroup(0, visible1); verifier.AppendStepToGroup(1, visible2); verifier.AppendStepToGroup(1, hidden2); // Non-impacting started to execute noImpacting1.Progress = 0; noImpacting1.ExecutionState = StepExecutionState.Executing; verifier.RunAndVerifyExecutingStep(this.progressEvents, noImpacting1, null); // Non-impacting reports progress noImpacting1.Progress = 0.5; verifier.RunAndVerifyExecutingStep(this.progressEvents, noImpacting1, null); // Non-impacting completes noImpacting1.Progress = 1.0; noImpacting1.ExecutionState = StepExecutionState.Succeeded; verifier.RunAndVerifyExecutingStep(this.progressEvents, noImpacting1, null); // Hidden1 starts hidden1.ExecutionState = StepExecutionState.Executing; verifier.RunAndVerifyExecutingStep(this.progressEvents, hidden1, 0); // Hidden1 reports progress hidden1.Progress = 0.5; verifier.ExpectedSubProgress = hidden1.Progress / 2.0; // relative to the number of sub steps in group verifier.ExpectedMainProgress = hidden1.Progress / mainProgressSections; // relative to the number of impacting steps verifier.RunAndVerifyExecutingStep(this.progressEvents, hidden1, 0); // Hidden1 completes hidden1.ExecutionState = StepExecutionState.Cancelled; verifier.ExpectedSubProgress = 1.0 / 2.0; // relative to the number of sub steps in group verifier.ExpectedMainProgress = 1.0 / mainProgressSections; // relative to the number of impacting steps verifier.RunAndVerifyExecutingStep(this.progressEvents, hidden1, 0); // Non-impacting started to execute noImpacting2.Progress = 0; noImpacting2.ExecutionState = StepExecutionState.Executing; verifier.RunAndVerifyExecutingStep(this.progressEvents, noImpacting2, 0); // Non-impacting reports progress noImpacting2.Progress = 0.5; verifier.RunAndVerifyExecutingStep(this.progressEvents, noImpacting2, 0); // Non-impacting completes noImpacting2.Progress = 1.0; noImpacting2.ExecutionState = StepExecutionState.Succeeded; verifier.RunAndVerifyExecutingStep(this.progressEvents, noImpacting2, 0); // Visible1 starts visible1.ExecutionState = StepExecutionState.Executing; verifier.RunAndVerifyExecutingStep(this.progressEvents, visible1, 0); // Visible1 reports progress visible1.Progress = 1.0; verifier.ExpectedSubProgress = 2.0 / 2.0; // relative to the number of sub steps in group verifier.ExpectedMainProgress = 2.0 / mainProgressSections; // relative to the number of impacting steps verifier.RunAndVerifyExecutingStep(this.progressEvents, visible1, 0); // Visible1 completes visible1.ExecutionState = StepExecutionState.Failed; verifier.ExpectedSubProgress = 1.0; verifier.ExpectedMainProgress = 2.0 / mainProgressSections; // relative to the number of impacting steps verifier.RunAndVerifyExecutingStep(this.progressEvents, visible1, 0); // Visible2 completes visible2.ExecutionState = StepExecutionState.Succeeded; verifier.ExpectedSubProgress = 1.0 / 2.0; // relative to the number of sub steps in group verifier.ExpectedMainProgress = 3.0 / mainProgressSections; verifier.RunAndVerifyExecutingStep(this.progressEvents, visible2, 1); // Hidden2 completes hidden2.ExecutionState = StepExecutionState.Succeeded; verifier.ExpectedSubProgress = 2.0 / 2.0; // relative to the number of sub steps in group verifier.ExpectedMainProgress = 4.0 / mainProgressSections; verifier.RunAndVerifyExecutingStep(this.progressEvents, hidden2, 1); }
public void ProgressObserver_ProgressUpdate_DeterminateIndeterminate() { // Setup ConfigurableProgressTestOperation determinate1 = CreateRandomStep(visible: true, indeterminate: false, impacting: true); determinate1.Progress = 0; determinate1.ExecutionState = StepExecutionState.NotStarted; ConfigurableProgressTestOperation indeterminate1 = CreateRandomStep(visible: true, indeterminate: true, impacting: true); indeterminate1.Progress = ProgressControllerHelper.Indeterminate; indeterminate1.ExecutionState = StepExecutionState.NotStarted; ConfigurableProgressTestOperation determinate2 = CreateRandomStep(visible: true, indeterminate: false, impacting: true); determinate2.Progress = 0; determinate2.ExecutionState = StepExecutionState.NotStarted; ConfigurableProgressTestOperation indeterminate2 = CreateRandomStep(visible: true, indeterminate: true, impacting: true); indeterminate2.Progress = ProgressControllerHelper.Indeterminate; indeterminate2.ExecutionState = StepExecutionState.NotStarted; this.progressEvents.Steps = new[] { determinate1, indeterminate1, determinate2, indeterminate2 }; this.CreateTestSubject(); double mainProgressSections = this.progressEvents.Steps.Count(s => s.ImpactsProgress); // Verify initial state VerifyProgress(this.testVisualizer, 0, null, 0); ExecutionVerifier verifier = new ExecutionVerifier(this.testVisualizer, this.testSubject); verifier.AppendStepToGroup(0, determinate1); verifier.AppendStepToGroup(1, indeterminate1); verifier.AppendStepToGroup(2, determinate2); verifier.AppendStepToGroup(3, indeterminate2); // First started to execute determinate1.ExecutionState = StepExecutionState.Executing; verifier.RunAndVerifyExecutingStep(this.progressEvents, determinate1, 0); // First reports progress determinate1.Progress = 0.5; verifier.ExpectedSubProgress = 0.5; verifier.ExpectedMainProgress = 0.5 / mainProgressSections; verifier.RunAndVerifyExecutingStep(this.progressEvents, determinate1, 0); // First completes determinate1.ExecutionState = StepExecutionState.Succeeded; verifier.ExpectedSubProgress = 1.0; verifier.ExpectedMainProgress = 1.0 / mainProgressSections; verifier.RunAndVerifyExecutingStep(this.progressEvents, determinate1, 0); // Second starts indeterminate1.ExecutionState = StepExecutionState.Executing; verifier.ExpectedSubProgress = ProgressControllerHelper.Indeterminate; verifier.RunAndVerifyExecutingStep(this.progressEvents, indeterminate1, 1); // Second completes indeterminate1.ExecutionState = StepExecutionState.Succeeded; verifier.ExpectedSubProgress = ProgressControllerHelper.Indeterminate; verifier.ExpectedMainProgress = 2.0 / mainProgressSections; verifier.RunAndVerifyExecutingStep(this.progressEvents, indeterminate1, 1); // Third starts determinate2.ExecutionState = StepExecutionState.Executing; verifier.ExpectedSubProgress = 0.0; verifier.RunAndVerifyExecutingStep(this.progressEvents, determinate2, 2); // Third reports progress determinate2.Progress = 0.5; verifier.ExpectedSubProgress = 0.5; verifier.ExpectedMainProgress = 2.5 / mainProgressSections; verifier.RunAndVerifyExecutingStep(this.progressEvents, determinate2, 2); // Third reports progress determinate2.Progress = 1.0; verifier.ExpectedSubProgress = 1.0; verifier.ExpectedMainProgress = 3.0 / mainProgressSections; verifier.RunAndVerifyExecutingStep(this.progressEvents, determinate2, 2); // Third completes determinate2.ExecutionState = StepExecutionState.Succeeded; verifier.ExpectedSubProgress = 1.0; verifier.ExpectedMainProgress = 3.0 / mainProgressSections; verifier.RunAndVerifyExecutingStep(this.progressEvents, determinate2, 2); // Fourth completes indeterminate2.ExecutionState = StepExecutionState.Succeeded; verifier.ExpectedSubProgress = ProgressControllerHelper.Indeterminate; verifier.ExpectedMainProgress = 4.0 / mainProgressSections; verifier.RunAndVerifyExecutingStep(this.progressEvents, indeterminate2, 3); }
public void SequentialProgressController_IProgressController_TryAbort_ControllerDrivenCancellation() { // Setup ConfigurableProgressStepFactory testFactory = new ConfigurableProgressStepFactory(); ConfigurableProgressTestOperation stepOperation = new ConfigurableProgressTestOperation(this.DoNothing); stepOperation.CancellableAction = () => { // Using this opportunity to abort - the test assumes that Cancellable is called before the step is actually executed Assert.IsTrue(this.testSubject.TryAbort(), "Should be able to abort"); return true; }; testFactory.CreateOpeartion = (d) => stepOperation; ProgressEventsVerifier verifier = new ProgressEventsVerifier(this.testSubject); this.testSubject.Initialize(testFactory, new[] { new StubProgressStepDefinition() }); // Execute this.testSubject.Start().Wait(); // Verify verifier.AssertCorrectExecution(ProgressControllerResult.Cancelled); verifier.AssertStepCorrectExecution(stepOperation, StepExecutionState.NotStarted); verifier.AssertCancellationChanges(3); }
public void SequentialProgressController_IProgressController_Start() { // Setup ConfigurableProgressStepFactory testFactory = new ConfigurableProgressStepFactory(); ConfigurableProgressTestOperation stepOperation = new ConfigurableProgressTestOperation(this.VerifyControllerExecuting); testFactory.CreateOpeartion = (d) => stepOperation; this.testSubject.Initialize(testFactory, new[] { new StubProgressStepDefinition() }); Assert.IsFalse(this.testSubject.IsStarted, "Wasn't started yet"); Assert.IsFalse(this.testSubject.IsFinished, "Wasn't started yet"); // Execute this.testSubject.Start().Wait(); Assert.IsTrue(this.testSubject.IsStarted, "Was started"); Assert.IsTrue(this.testSubject.IsFinished, "Was finished"); }