Ejemplo n.º 1
0
        public void should_trigger_step_hooks()
        {
            //arrange
            var step1Body = A.Fake <IStepBody>();

            A.CallTo(() => step1Body.RunAsync(A <IStepExecutionContext> .Ignored)).Returns(ExecutionResult.Next());
            WorkflowStep step1 = BuildFakeStep(step1Body);

            Given1StepWorkflow(step1, "Workflow", 1);

            var instance = new WorkflowInstance
            {
                WorkflowDefinitionId = "Workflow",
                Version           = 1,
                Status            = WorkflowStatus.Runnable,
                NextExecution     = 0,
                Id                = "001",
                ExecutionPointers = new List <ExecutionPointer>()
                {
                    new ExecutionPointer()
                    {
                        Active = true, StepId = 0
                    }
                }
            };

            //act
            Subject.Execute(instance);

            //assert
            A.CallTo(() => step1.InitForExecution(A <WorkflowExecutorResult> .Ignored, A <WorkflowDefinition> .Ignored, A <WorkflowInstance> .Ignored, A <ExecutionPointer> .Ignored)).MustHaveHappened();
            A.CallTo(() => step1.BeforeExecute(A <WorkflowExecutorResult> .Ignored, A <IStepExecutionContext> .Ignored, A <ExecutionPointer> .Ignored, A <IStepBody> .Ignored)).MustHaveHappened();
            A.CallTo(() => step1.AfterExecute(A <WorkflowExecutorResult> .Ignored, A <IStepExecutionContext> .Ignored, A <ExecutionResult> .Ignored, A <ExecutionPointer> .Ignored)).MustHaveHappened();
        }
Ejemplo n.º 2
0
        private bool InitializeStep(WorkflowInstance workflow, WorkflowStep step, WorkflowExecutorResult wfResult, WorkflowDefinition def, ExecutionPointer pointer)
        {
            switch (step.InitForExecution(wfResult, def, workflow, pointer))
            {
            case ExecutionPipelineDirective.Defer:
                return(false);

            case ExecutionPipelineDirective.EndWorkflow:
                workflow.Status       = WorkflowStatus.Complete;
                workflow.CompleteTime = _datetimeProvider.Now.ToUniversalTime();
                return(false);
            }

            if (pointer.Status != PointerStatus.Running)
            {
                pointer.Status = PointerStatus.Running;
                _publisher.PublishNotification(new StepStarted()
                {
                    EventTimeUtc         = _datetimeProvider.Now,
                    Reference            = workflow.Reference,
                    ExecutionPointerId   = pointer.Id,
                    StepId               = step.Id,
                    WorkflowInstanceId   = workflow.Id,
                    WorkflowDefinitionId = workflow.WorkflowDefinitionId,
                    Version              = workflow.Version
                });
            }

            if (!pointer.StartTime.HasValue)
            {
                pointer.StartTime = _datetimeProvider.Now.ToUniversalTime();
            }

            return(true);
        }