Test helper to verify general IProgressController and IProgressStepOperation execution and also verification of the event mechanism IProgressEvents
コード例 #1
0
        public void SequentialProgressController_ExecutionOrder()
        {
            // Arrange
            IProgressStep[] stepOperations    = null;
            int             expectedOperation = 0;
            Action <CancellationToken, IProgressStepExecutionEvents> operation = (c, e) =>
            {
                ((IProgressStep)e).Should().Be(stepOperations[expectedOperation], "Unexpected execution order");
                expectedOperation++;
            };

            ProgressStepDefinition[] definitions = new[]
            {
                new ProgressStepDefinition(null, StepAttributes.None, operation),
                new ProgressStepDefinition(null, StepAttributes.Hidden, operation),
                new ProgressStepDefinition(null, StepAttributes.BackgroundThread, operation),
                new ProgressStepDefinition(null, StepAttributes.Indeterminate, operation),
                new ProgressStepDefinition(null, StepAttributes.NonCancellable, operation)
            };

            ProgressEventsVerifier verifier = this.InitializeTestSubjectWithTestErrorHandling(definitions);

            stepOperations = this.testSubject.Steps.ToArray();

            // Act
            this.testSubject.StartAsync().Wait();

            // Assert
            definitions.Should().HaveCount(expectedOperation, "Executed unexpected number of times");
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        public void SequentialProgressController_ExecutionOrder()
        {
            // Setup
            IProgressStep[] stepOperations    = null;
            int             expectedOperation = 0;
            Action <CancellationToken, IProgressStepExecutionEvents> operation = (c, e) =>
            {
                Assert.AreSame(stepOperations[expectedOperation], (IProgressStep)e, "Unexpected execution order");
                expectedOperation++;
            };

            ProgressStepDefinition[] definitions = new[]
            {
                new ProgressStepDefinition(null, StepAttributes.None, operation),
                new ProgressStepDefinition(null, StepAttributes.Hidden, operation),
                new ProgressStepDefinition(null, StepAttributes.BackgroundThread, operation),
                new ProgressStepDefinition(null, StepAttributes.Indeterminate, operation),
                new ProgressStepDefinition(null, StepAttributes.NonCancellable, operation)
            };

            ProgressEventsVerifier verifier = this.InitializeTestSubjectWithTestErrorHandling(definitions);

            stepOperations = this.testSubject.Steps.ToArray();

            // Execute
            this.testSubject.Start().Wait();

            // Verify
            Assert.AreEqual(expectedOperation, definitions.Length, "Executed unexpected number of times");
        }
コード例 #4
0
        private ProgressEventsVerifier InitializeTestSubjectWithTestErrorHandling(params ProgressStepDefinition[] definitions)
        {
            // Replace the error handler
            this.errorNotifier = SequentialProgressControllerHelper.InitializeWithTestErrorHandling(this.testSubject, definitions);
            ProgressEventsVerifier verifier = null;

            this.threadingService.RunInUIContext(() => verifier = new ProgressEventsVerifier(this.testSubject));
            return(verifier);
        }
コード例 #5
0
        public void SequentialProgressController_IProgressEvents_StepCancelled()
        {
            // Arrange
            ProgressEventsVerifier verifier = this.InitializeTestSubjectWithTestErrorHandling(new ProgressStepDefinition(null, StepAttributes.Hidden, this.Cancel));

            // Act
            this.testSubject.StartAsync().Wait();

            // Assert
            verifier.AssertCorrectExecution(ProgressControllerResult.Cancelled);
            verifier.AssertStepCorrectExecution(this.testSubject.Steps.Single(), StepExecutionState.Cancelled);
            verifier.AssertCancellationChanges(2);
        }
コード例 #6
0
        public void SequentialProgressController_IProgressEvents_StepSucceeded()
        {
            // Setup
            ProgressEventsVerifier verifier = this.InitializeTestSubjectWithTestErrorHandling(new ProgressStepDefinition(null, StepAttributes.Hidden, this.DoNothing));

            // Execute
            this.testSubject.Start().Wait();

            // Verify
            verifier.AssertCorrectExecution(ProgressControllerResult.Succeeded);
            verifier.AssertStepCorrectExecution(this.testSubject.Steps.Single(), StepExecutionState.Succeeded);
            verifier.AssertCancellationChanges(1);
        }
コード例 #7
0
        public void SequentialProgressController_IProgressEvents_MultiStep_Succeeded()
        {
            // Arrange
            ProgressEventsVerifier verifier = this.InitializeTestSubjectWithTestErrorHandling(new ProgressStepDefinition(null, StepAttributes.Hidden, this.DoNothing),
                                                                                              new ProgressStepDefinition(null, StepAttributes.Hidden, this.DoNothing));

            // Act
            this.testSubject.StartAsync().Wait();

            // Assert
            verifier.AssertCorrectExecution(ProgressControllerResult.Succeeded);
            IProgressStep[] step = this.testSubject.Steps.ToArray();
            verifier.AssertStepCorrectExecution(step[0], StepExecutionState.Succeeded);
            verifier.AssertStepCorrectExecution(step[1], StepExecutionState.Succeeded);
            verifier.AssertCancellationChanges(1);
        }
コード例 #8
0
        public void SequentialProgressController_IProgressController_TryAbort_NonCancellable()
        {
            // Arrange
            ProgressEventsVerifier verifier = this.InitializeTestSubjectWithTestErrorHandling(
                new ProgressStepDefinition(null, StepAttributes.Hidden | StepAttributes.NonCancellable, this.RequestToCancelIgnored),
                new ProgressStepDefinition(null, StepAttributes.Hidden, this.DoNothing));

            // Act
            this.testSubject.StartAsync().Wait();

            // Assert
            IProgressStep[] stepOperations = this.testSubject.Steps.ToArray();
            verifier.AssertCorrectExecution(ProgressControllerResult.Succeeded);
            verifier.AssertStepCorrectExecution(stepOperations[0], StepExecutionState.Succeeded);
            verifier.AssertStepCorrectExecution(stepOperations[1], StepExecutionState.Succeeded);
            verifier.AssertCancellationChanges(3);
        }
コード例 #9
0
        public void SequentialProgressController_IProgressController_TryAbort_Cancellable()
        {
            // Arrange
            ProgressEventsVerifier verifier = this.InitializeTestSubjectWithTestErrorHandling(
                new ProgressStepDefinition(null, StepAttributes.Hidden, this.RequestToCancelAccepted),
                new ProgressStepDefinition(null, StepAttributes.Hidden, this.DoNothing));

            // Act
            this.testSubject.StartAsync().Wait();

            // Assert
            this.testSubject.CanAbort.Should().BeFalse("Should not be abortable any more, since already aborted");
            IProgressStep[] stepOperations = this.testSubject.Steps.ToArray();
            verifier.AssertCorrectExecution(ProgressControllerResult.Cancelled);
            verifier.AssertStepCorrectExecution(stepOperations[0], StepExecutionState.Succeeded);
            verifier.AssertStepCorrectExecution(stepOperations[1], StepExecutionState.NotStarted);
            verifier.AssertCancellationChanges(2);
        }
コード例 #10
0
        public void SequentialProgressController_IProgressEvents_ProgessChanges()
        {
            // Arrange
            ProgressEventsVerifier verifier = this.InitializeTestSubjectWithTestErrorHandling(new ProgressStepDefinition(null, StepAttributes.Hidden, this.NotifyProgress));

            this.notifyProgressSequence.Add(Tuple.Create("hello", 0.25));
            this.notifyProgressSequence.Add(Tuple.Create(string.Empty, 0.5));
            this.notifyProgressSequence.Add(Tuple.Create("world", 0.75));
            this.notifyProgressSequence.Add(Tuple.Create((string)null, 1.0));

            // Act
            this.testSubject.StartAsync().Wait();

            // Assert
            verifier.AssertCorrectExecution(ProgressControllerResult.Succeeded);
            verifier.AssertStepCorrectExecution(this.testSubject.Steps.Single(), StepExecutionState.Succeeded);
            verifier.AssertExecutionProgress(this.testSubject.Steps.Single(), this.notifyProgressSequence.ToArray());
            verifier.AssertCancellationChanges(1);
        }
コード例 #11
0
        public void SequentialProgressController_IProgressController_TryAbort_NonStarted()
        {
            // Setup
            ProgressEventsVerifier verifier = this.InitializeTestSubjectWithTestErrorHandling(
                new ProgressStepDefinition(null, StepAttributes.Hidden | StepAttributes.NonCancellable, this.DoNothing),
                new ProgressStepDefinition(null, StepAttributes.Hidden, this.DoNothing));

            Assert.IsFalse(this.testSubject.TryAbort(), "Should not be able to abort before started");

            // Execute
            this.testSubject.Start().Wait();

            // Verify
            IProgressStep[] stepOperations = this.testSubject.Steps.ToArray();
            verifier.AssertCorrectExecution(ProgressControllerResult.Succeeded);
            verifier.AssertStepCorrectExecution(stepOperations[0], StepExecutionState.Succeeded);
            verifier.AssertStepCorrectExecution(stepOperations[1], StepExecutionState.Succeeded);
            verifier.AssertCancellationChanges(3);
        }
 private ProgressEventsVerifier InitializeTestSubjectWithTestErrorHandling(params ProgressStepDefinition[] definitions)
 {
     // Replace the error handler
     this.errorNotifier = SequentialProgressControllerHelper.InitializeWithTestErrorHandling(this.testSubject, definitions);
     ProgressEventsVerifier verifier = null;
     this.threadingService.RunInUIContext(() => verifier = new ProgressEventsVerifier(this.testSubject));
     return verifier;
 }
        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);
        }