示例#1
0
        public void MakeDecision_ChildWorkflowExecutionFailedTest([Frozen] IDecider decider,
                                                                  [Frozen] RespondDecisionTaskCompletedRequest respondDecisionTask)
        {
            _processor = new SDK.Workflow.WorkflowEventsProcessor(_decisionTask, _workflowBase, _pollforDecisionTaskRequest, _amazonSwf);

            var decisionContext = new WorkflowDecisionContext()
            {
                DecisionType = EventType.ChildWorkflowExecutionFailed
            };

            decider.OnChildWorkflowExecutionFailed(decisionContext).Returns(info => respondDecisionTask);

            _decisionCompletedRequest = _processor.MakeDecision(decider, decisionContext);
            AssertObjectEquals.PropertyValuesAreEqual(_decisionCompletedRequest.Decisions.First(), respondDecisionTask.Decisions.First());
        }
        /// <summary>
        /// Creates an Amazon RespondDecisionTaskCompletedRequest to notify SWF that decison was made based on decision
        /// </summary>
        /// <param name="decider"></param>
        /// <returns></returns>
        internal RespondDecisionTaskCompletedRequest MakeDecision(IDecider decider, WorkflowDecisionContext decisionContext)
        {
            if (decider == null)
            {
                var attributes = new FailWorkflowExecutionDecisionAttributes
                {
                    Details = "WorkflowId: " + decisionContext.WorkflowId,
                    Reason  = "Decider not found."
                };

                var decisionRequest = new RespondDecisionTaskCompletedRequest
                {
                    Decisions = new List <Decision>
                    {
                        new Decision
                        {
                            DecisionType = DecisionType.FailWorkflowExecution,
                            FailWorkflowExecutionDecisionAttributes = attributes
                        }
                    }
                };
                return(decisionRequest);
            }

            RespondDecisionTaskCompletedRequest decisionCompletedRequest;

            // Match the context and call the right method to make a decision
            if (decisionContext.DecisionType == EventType.WorkflowExecutionStarted)
            {
                decisionCompletedRequest = decider.OnWorkflowExecutionStarted(decisionContext);
            }
            else if (decisionContext.DecisionType == DecisionType.ContinueAsNewWorkflowExecution)
            {
                decisionCompletedRequest = decider.OnWorkflowExecutionContinuedAsNew(decisionContext);
            }
            else if (decisionContext.DecisionType == EventType.WorkflowExecutionCancelRequested)
            {
                decisionCompletedRequest = decider.OnWorkflowExecutionCancelRequested(decisionContext);
            }
            else if (decisionContext.DecisionType == EventType.ActivityTaskCompleted)
            {
                decisionCompletedRequest = decider.OnActivityTaskCompleted(decisionContext);
            }
            else if (decisionContext.DecisionType == EventType.ActivityTaskFailed)
            {
                decisionCompletedRequest = decider.OnActivityTaskFailed(decisionContext);
            }
            else if (decisionContext.DecisionType == EventType.ActivityTaskTimedOut)
            {
                decisionCompletedRequest = decider.OnActivityTaskTimedOut(decisionContext);
            }
            else if (decisionContext.DecisionType == EventType.ScheduleActivityTaskFailed)
            {
                decisionCompletedRequest = decider.OnScheduleActivityTaskFailed(decisionContext);
            }
            else if (decisionContext.DecisionType == EventType.ChildWorkflowExecutionStarted)
            {
                decisionCompletedRequest = decider.OnChildWorkflowExecutionStarted(decisionContext);
            }
            else if (decisionContext.DecisionType == EventType.ChildWorkflowExecutionCompleted)
            {
                decisionCompletedRequest = decider.OnChildWorkflowExecutionCompleted(decisionContext);
            }
            else if (decisionContext.DecisionType == EventType.ChildWorkflowExecutionFailed)
            {
                decisionCompletedRequest = decider.OnChildWorkflowExecutionFailed(decisionContext);
            }
            else if (decisionContext.DecisionType == EventType.ChildWorkflowExecutionTerminated)
            {
                decisionCompletedRequest = decider.OnChildWorkflowExecutionTerminated(decisionContext);
            }
            else if (decisionContext.DecisionType == EventType.ChildWorkflowExecutionTimedOut)
            {
                decisionCompletedRequest = decider.OnChildWorkflowExecutionTimedOut(decisionContext);
            }
            else if (decisionContext.DecisionType == EventType.StartChildWorkflowExecutionFailed)
            {
                decisionCompletedRequest = decider.OnStartChildWorkflowExecutionFailed(decisionContext);
            }
            else if (decisionContext.DecisionType == EventType.TimerStarted)
            {
                decisionCompletedRequest = decider.OnTimerStarted(decisionContext);
            }
            else if (decisionContext.DecisionType == EventType.TimerFired)
            {
                decisionCompletedRequest = decider.OnTimerFired(decisionContext);
            }
            else if (decisionContext.DecisionType == EventType.TimerCanceled)
            {
                decisionCompletedRequest = decider.OnTimerCanceled(decisionContext);
            }
            else if (decisionContext.DecisionType == EventType.StartChildWorkflowExecutionInitiated)
            {
                decisionCompletedRequest = decider.OnStartChildWorkflowExecutionInitiated(decisionContext);
            }
            else if (decisionContext.DecisionType == EventType.WorkflowExecutionSignaled)
            {
                decisionCompletedRequest = decider.OnWorkflowExecutionSignaled(decisionContext);
            }
            else if (decisionContext.DecisionType == EventType.WorkflowExecutionCompleted)
            {
                decisionCompletedRequest = decider.OnWorkflowExecutionCompleted(decisionContext);
            }
            else
            {
                throw new InvalidOperationException("Unhandled event type.");
            }
            return(decisionCompletedRequest);
        }