Exemplo n.º 1
0
        public async void ShouldContinueWithCaughtContinueTest()
        {
            // Arrange
            const int iterations = 2;

            var step1       = new LoopStep("one");
            var step2       = new LoopStep("two");
            var controlStop = new StepThatThrowsContinue("three");

            var baseStepList = new List <Step <SimpleWorkflowState> > {
                step1, step2, controlStop
            };
            var nonControlStepCount = baseStepList.Count(x => x.GetType() != controlStop.GetType());

            bool ShouldContinue(SimpleWorkflowState simpleWorkflowState) => simpleWorkflowState.MyInteger < iterations * nonControlStepCount;

            var forLoop = new WhileLoop <SimpleWorkflowState>(ShouldContinue, name: "foo", steps: baseStepList);

            // Act
            var result = await forLoop.Execute(_workflowState);

            // Assert
            Assert.Equal(iterations * nonControlStepCount, result.State.MyInteger);
            Assert.Equal(iterations * baseStepList.Count + 1, result.WorkflowChain.Count);
            Assert.Equal(iterations, forLoop.CurrentIteration);
        }
Exemplo n.º 2
0
        public async void ShouldContinueAsyncTest()
        {
            // Arrange
            const int iterations = 2;

            var step1 = new LoopStep("one");
            var step2 = new LoopStep("two");
            var step3 = new LoopStep("three");

            var baseStepList = new List <Step <SimpleWorkflowState> > {
                step1, step2, step3
            };

            Task <bool> ShouldContinueAsync(SimpleWorkflowState simpleWorkflowState) => Task.FromResult(simpleWorkflowState.MyInteger < iterations * baseStepList.Count);

            var forLoop = new WhileLoop <SimpleWorkflowState>(ShouldContinueAsync, name: "foo", steps: baseStepList);

            // Act
            var result = await forLoop.Execute(_workflowState);

            // Assert
            Assert.Equal(iterations * baseStepList.Count, result.State.MyInteger);
            Assert.Equal(iterations * baseStepList.Count + 1, result.WorkflowChain.Count);
            Assert.Equal(iterations, forLoop.CurrentIteration);
        }
Exemplo n.º 3
0
        public async void DetermineIterationsTest()
        {
            // Arrange
            const int iterations = 2;

            int DetermineIterations(SimpleWorkflowState simpleWorkflowState) => iterations;

            var step1 = new LoopStep("one");
            var step2 = new LoopStep("two");
            var step3 = new LoopStep("three");

            var baseStepList = new List <Step <SimpleWorkflowState> > {
                step1, step2, step3
            };

            var forLoop = new ForLoop <SimpleWorkflowState>(DetermineIterations, name: "foo", steps: baseStepList);

            // Act
            var result = await forLoop.Execute(_workflowState);

            // Assert
            Assert.Equal(iterations * baseStepList.Count, result.State.MyInteger);
            Assert.Equal(iterations * baseStepList.Count + 1, result.WorkflowChain.Count);
            Assert.Equal(iterations, forLoop.CurrentIteration);
        }
Exemplo n.º 4
0
        public async void BreakForLoopTest()
        {
            // Arrange
            var iterations = 2;

            var step1     = new LoopStep("one");
            var step2     = new LoopStep("two");
            var breakStep = new StopThatThrowsBreak("break-step");

            var baseStepList = new List <Step <SimpleWorkflowState> > {
                step1, step2, breakStep
            };

            var forLoop = new ForLoop <SimpleWorkflowState>(iterations, name: "foo", steps: baseStepList);

            // Act
            var result = await forLoop.Execute(_workflowState);

            var nonBreakStepCount = baseStepList.Count(x => x.GetType() != breakStep.GetType());

            // Assert
            Assert.Equal(nonBreakStepCount, result.State.MyInteger);
            Assert.Equal(baseStepList.Count + 1, result.WorkflowChain.Count);
            Assert.Equal(0, forLoop.CurrentIteration);
        }
Exemplo n.º 5
0
        public async void ContinueForLoopTest()
        {
            // Arrange
            var iterations = 2;

            var step1        = new LoopStep("one");
            var continueStep = new StepThatThrowsContinue("break-step");
            var step3        = new LoopStep("three");

            var baseStepList = new List <Step <SimpleWorkflowState> > {
                step1, continueStep, step3
            };

            var forLoop = new ForLoop <SimpleWorkflowState>(iterations, name: "foo", steps: baseStepList);

            // Act
            var result = await forLoop.Execute(_workflowState);

            // Assert
            Assert.Equal(iterations, result.State.MyInteger);
            Assert.Equal(iterations * 2 + 1, result.WorkflowChain.Count);
            Assert.Equal(iterations, forLoop.CurrentIteration);
        }
Exemplo n.º 6
0
        /// <summary>
        /// The create loop step.
        /// </summary>
        /// <returns>
        /// The <see cref="LoopStep"/>.
        /// </returns>
        public LoopStep CreateLoopStep()
        {
            var myLoopStep = new LoopStep();

            return(myLoopStep);
        }
Exemplo n.º 7
0
        public void TestAllowChildren()
        {
            LoopStep step = new LoopStep();

            step.ChildTestSteps.Add(new AutomationStep());
        }