public void should_branch_children() { //arrange var branch = 10; var child = 2; var definition = new WorkflowDefinition(); var pointer = new ExecutionPointer() { Active = true, StepId = 0, Status = PointerStatus.Running }; var childPointer = new ExecutionPointer(); var step = A.Fake <WorkflowStep>(); var workflowResult = new WorkflowExecutorResult(); var instance = GivenWorkflow(pointer); var result = ExecutionResult.Branch(new List <object>() { branch }, null); A.CallTo(() => step.Children).Returns(new List <int>() { child }); A.CallTo(() => PointerFactory.BuildChildPointer(definition, pointer, child, branch)).Returns(childPointer); //act Subject.ProcessExecutionResult(instance, definition, pointer, step, result, workflowResult); //assert A.CallTo(() => PointerFactory.BuildChildPointer(definition, pointer, child, branch)).MustHaveHappened(); instance.ExecutionPointers.Should().Contain(childPointer); }
public void ProcessExecutionResult(WorkflowInstance workflow, WorkflowDefinition def, ExecutionPointer pointer, WorkflowStep step, ExecutionResult result, WorkflowExecutorResult workflowResult) { pointer.PersistenceData = result.PersistenceData; pointer.Outcome = result.OutcomeValue; if (result.SleepFor.HasValue) { pointer.SleepUntil = _datetimeProvider.Now.ToUniversalTime().Add(result.SleepFor.Value); pointer.Status = PointerStatus.Sleeping; } if (!string.IsNullOrEmpty(result.EventName)) { pointer.EventName = result.EventName; pointer.EventKey = result.EventKey; pointer.Active = false; pointer.Status = PointerStatus.WaitingForEvent; workflowResult.Subscriptions.Add(new EventSubscription() { WorkflowId = workflow.Id, StepId = pointer.StepId, EventName = pointer.EventName, EventKey = pointer.EventKey, SubscribeAsOf = result.EventAsOf }); } if (result.Proceed) { pointer.Active = false; pointer.EndTime = _datetimeProvider.Now.ToUniversalTime(); pointer.Status = PointerStatus.Complete; foreach (var outcomeTarget in step.Outcomes.Where(x => object.Equals(x.GetValue(workflow.Data), result.OutcomeValue) || x.GetValue(workflow.Data) == null)) { workflow.ExecutionPointers.Add(_pointerFactory.BuildNextPointer(def, pointer, outcomeTarget)); } _eventPublisher.PublishNotification(new StepCompleted() { EventTimeUtc = _datetimeProvider.Now, Reference = workflow.Reference, ExecutionPointerId = pointer.Id, StepId = step.Id, WorkflowInstanceId = workflow.Id, WorkflowDefinitionId = workflow.WorkflowDefinitionId, Version = workflow.Version }); } else { foreach (var branch in result.BranchValues) { foreach (var childDefId in step.Children) { workflow.ExecutionPointers.Add(_pointerFactory.BuildChildPointer(def, pointer, childDefId, branch)); } } } }
public void ProcessExecutionResult(WorkflowInstance workflow, WorkflowDefinition def, ExecutionPointer pointer, WorkflowStep step, ExecutionResult result, WorkflowExecutorResult workflowResult) { pointer.PersistenceData = result.PersistenceData; pointer.Outcome = result.OutcomeValue; if (result.SleepFor.HasValue) { pointer.SleepUntil = _datetimeProvider.UtcNow.Add(result.SleepFor.Value); pointer.Status = PointerStatus.Sleeping; } if (!string.IsNullOrEmpty(result.EventName)) { pointer.EventName = result.EventName; pointer.EventKey = result.EventKey; pointer.Active = false; pointer.Status = PointerStatus.WaitingForEvent; workflowResult.Subscriptions.Add(new EventSubscription { WorkflowId = workflow.Id, StepId = pointer.StepId, ExecutionPointerId = pointer.Id, EventName = pointer.EventName, EventKey = pointer.EventKey, SubscribeAsOf = result.EventAsOf, SubscriptionData = result.SubscriptionData }); } if (result.Proceed) { pointer.Active = false; pointer.EndTime = _datetimeProvider.UtcNow; pointer.Status = PointerStatus.Complete; foreach (var outcomeTarget in step.Outcomes.Where(x => x.Matches(result, workflow.Data))) { workflow.ExecutionPointers.Add(_pointerFactory.BuildNextPointer(def, pointer, outcomeTarget)); } var pendingSubsequents = workflow.ExecutionPointers .FindByStatus(PointerStatus.PendingPredecessor) .Where(x => x.PredecessorId == pointer.Id); foreach (var subsequent in pendingSubsequents) { subsequent.Status = PointerStatus.Pending; subsequent.Active = true; } _eventPublisher.PublishNotification(new StepCompleted { EventTimeUtc = _datetimeProvider.UtcNow, Reference = workflow.Reference, ExecutionPointerId = pointer.Id, StepId = step.Id, WorkflowInstanceId = workflow.Id, WorkflowDefinitionId = workflow.WorkflowDefinitionId, Version = workflow.Version }); } else { foreach (var branch in result.BranchValues) { foreach (var childDefId in step.Children) { workflow.ExecutionPointers.Add(_pointerFactory.BuildChildPointer(def, pointer, childDefId, branch)); } } } }