internal void RetryScheduled_GoodAttemptsTest() { WorkflowState wfState = new WorkflowState(0); SchedulableState state = new SchedulableState() { StepNumber = 0, StepKey = "testActivity", ActionNumber = 1, AttemptNumber = 1, MaxAttempts = 1, TotalActions = 1, DelayTimeoutInSeconds = 0, }; var context = Substitute.For <WorkflowDecisionContext>(); context.Control = SchedulableStateSerializer.Serialize(state); var workflow = Substitute.ForPartsOf <WorkflowBase>("domain", "workflowName", "version", "taskList", _amazonSwf); /*workflow.RetryScheduled(context, wfState); * * workflow.Received().FailWorkflow(context.Details, "State is undefined."); */ }
internal void NextStepParallelCollection(WorkflowDecisionContext decisionContext, WorkflowState wfState) { var state = new SchedulableState(); decisionContext.Control = SchedulableStateSerializer.Serialize(state); decisionContext.ResultRef = Utils.SerializeToJSON(new StepResult <string>()); var action = Substitute.For <ParallelActivityCollectionBase <string, string, string, string> >("name", "taskList"); var step = Substitute.For <WorkflowStep>(); step.Action = action; step.StepKey = "activity_ParallelCollection"; step.StepNumber = 0; var workflow = Substitute.For <WorkflowBase>("domain", "NextStepParallelCollection", "version", "taskList", _amazonSwf); workflow.Steps.Add(step); workflow.GetStep(Arg.Any <int>()).Returns(info => step); workflow.ProcessActionCollection(decisionContext, wfState, state, action, step) .Returns(info => new StepDecision()); workflow.ProcessIActivity(decisionContext, step, state) .Returns(info => new StepDecision()); workflow.NextStep(decisionContext, wfState); //check if these methods were called workflow.Received().ProcessActionCollection(decisionContext, wfState, state, action, step); workflow.DidNotReceiveWithAnyArgs().ProcessIActivity(null, null, null); }
internal void NextStepActivity(WorkflowDecisionContext decisionContext, WorkflowState wfState) { var state = new SchedulableState(); decisionContext.Control = SchedulableStateSerializer.Serialize(state); decisionContext.ResultRef = Utils.SerializeToJSON(new StepResult <string>()); var action = Substitute.For <ActivityBase <string, string> >("name", "taskList"); var step = Substitute.For <WorkflowStep>(); step.Action = action; step.StepKey = "activityActionName"; step.StepNumber = 0; _workflow.GetStep(Arg.Any <int>()).Returns(info => step); _workflow.ProcessIActivity(decisionContext, step, state) .Returns(info => new StepDecision()); _workflow.NextStep(decisionContext, wfState); //check if these methods were called _workflow.Received().ProcessIActivity(decisionContext, step, state); }
internal void ProcessIActivityNotSuccessTest(WorkflowState wfState, SchedulableState schedulableState) { var action = Substitute.For <ActivityBase <string, string> >("name", "taskList"); var step = Substitute.For <WorkflowStep>(); step.Action = action; step.StepKey = "activityActionName"; step.StepNumber = 0; var stepResult = new StepResult <string>(string.Empty, false, step.StepKey); var context = Substitute.For <WorkflowDecisionContext>(); context.Control = SchedulableStateSerializer.Serialize(schedulableState); context.ResultRef = Utils.SerializeToJSON(stepResult); var workflow = Substitute.ForPartsOf <WorkflowBase>("domain", "workflowName", "version", "taskList", _amazonSwf); workflow.WhenForAnyArgs(x => x.FailWorkflow(string.Empty, string.Empty)).DoNotCallBase(); workflow.FailWorkflow(string.Empty, string.Empty).ReturnsForAnyArgs(info => new Decision()); workflow.ProcessIActivity(context, step, schedulableState); //check if these methods were called workflow.ReceivedWithAnyArgs().FailWorkflow(string.Empty, string.Empty); }
internal void NextStepNullStep(WorkflowDecisionContext decisionContext, WorkflowState wfState) { decisionContext.Control = SchedulableStateSerializer.Serialize(new SchedulableState()); decisionContext.ResultRef = Utils.SerializeToJSON(new StepResult <string>()); _workflow.GetStep(Arg.Any <int>()).Returns(info => null); _workflow.CompleteWorkflow(Arg.Any <string>()) .Returns(info => new Decision()); _workflow.NextStep(decisionContext, wfState); //check if these methods were called _workflow.ReceivedWithAnyArgs().CompleteWorkflow(string.Empty); }
internal void ProcessISuspendableSuspendTest(WorkflowState wfState, SchedulableState schedulableState) { schedulableState.AttemptNumber = 3; var action = Substitute.For <SuspendableActivity <string, string> >("name", "taskList"); action.Input = string.Empty; action.Options.DelayTimeoutInSeconds = 30; var activityStep = Substitute.For <WorkflowStep>(); activityStep.Action = action; activityStep.StepKey = "activityActionName"; activityStep.StepNumber = 0; var stepResult = new StepResult <string>(string.Empty, false, activityStep.StepKey); var result = Utils.SerializeToJSON(stepResult); var context = Substitute.For <WorkflowDecisionContext>(); context.Control = SchedulableStateSerializer.Serialize(schedulableState); context.ResultRef = result; context.InputRef = stepResult.ReturnValue; var workflow = Substitute.ForPartsOf <WorkflowBase>("domain", "workflowName", "version", "taskList", _amazonSwf); workflow.WhenForAnyArgs(x => x.ScheduleActivity(schedulableState, string.Empty, action)).DoNotCallBase(); workflow.ScheduleActivity(schedulableState, string.Empty, action) .ReturnsForAnyArgs(info => new List <Decision>()); workflow.ProcessISuspendable(context, wfState, activityStep, schedulableState); Assert.True(schedulableState.DelayTimeoutInSeconds == action.Options.DelayTimeoutInSeconds, "SchedulableState.DelayTimeoutInSeconds has not been updated."); Assert.True(schedulableState.AttemptNumber == 0, "SchedulableState.AttemptNumber has not been reset."); //check if these methods were called workflow.Received().ScheduleActivity(schedulableState, stepResult.ReturnValue, action); }
internal void ProcessIActivitySuccessTest(WorkflowState wfState, SchedulableState schedulableState) { var action = Substitute.For <ActivityBase <string, string> >("name", "taskList"); var activityStep = Substitute.For <WorkflowStep>(); activityStep.Action = action; activityStep.StepKey = "activityActionName"; activityStep.StepNumber = 0; var stepResult = new StepResult <string>(string.Empty, true, activityStep.StepKey); var result = Utils.SerializeToJSON(stepResult); var context = Substitute.For <WorkflowDecisionContext>(); context.Control = SchedulableStateSerializer.Serialize(schedulableState); context.ResultRef = result; var workflow = Substitute.ForPartsOf <WorkflowBase>("domain", "workflowName", "version", "taskList", _amazonSwf); workflow.WhenForAnyArgs(x => x.ResolveStepNumber(activityStep, string.Empty, 0)).DoNotCallBase(); workflow.ResolveStepNumber(activityStep, string.Empty, 0) .ReturnsForAnyArgs(info => new StepResult { Input = string.Empty, StepNumber = activityStep.StepNumber + 1 }); workflow.WhenForAnyArgs(x => x.ScheduleStep(0, string.Empty, 3)).DoNotCallBase(); workflow.ScheduleStep(0, string.Empty, 3) .ReturnsForAnyArgs(info => new StepDecision()); workflow.ProcessIActivity(context, activityStep, schedulableState); //check if these methods were called workflow.Received().ResolveStepNumber(activityStep, string.Empty, activityStep.StepNumber + 1); workflow.Received().ScheduleStep(activityStep.StepNumber + 1, string.Empty, 0); }
internal void ProcessActionCollectionTest(WorkflowState state, SchedulableState schedulableState) { state.CurrentStepNumber = 0; state.Results.AddOrUpdate(1, "TestResult", (i, s) => $"{s}{i}"); schedulableState.StepNumber = 0; schedulableState.StepKey = "testActivity"; schedulableState.ActionNumber = 1; schedulableState.AttemptNumber = 1; schedulableState.MaxAttempts = 1; schedulableState.TotalActions = 1; schedulableState.DelayTimeoutInSeconds = 0; var action = Substitute.For <ParallelActivityCollectionBase <string, string, string, string> >("name", "taskList"); var step = Substitute.For <WorkflowStep>(); step.Action = action; step.StepKey = "activityActionName"; step.StepNumber = 0; //_workflow.Steps.Add(activityStep); //_workflow.GetStep(Arg.Any<int>()).Returns(info => activityStep); //_processor = new WorkflowEventsProcessor(_decisionTask, _workflow, _pollforDecisionTaskRequest, _amazonSwf); //_workflow.GetStep(1).ReturnsForAnyArgs(info => activityStep); var context = Substitute.For <WorkflowDecisionContext>(); context.Control = SchedulableStateSerializer.Serialize(schedulableState); Dictionary <int, string> results = state.Results.ToDictionary(kvp => kvp.Key, kvp => kvp.Value); context.Results[schedulableState.StepNumber] = results; var workflow = Substitute.ForPartsOf <WorkflowBase>("domain", "workflowName", "version", "taskList", _amazonSwf); workflow.WhenForAnyArgs(x => x.GetStep(Arg.Any <int>())).DoNotCallBase(); workflow.GetStep(Arg.Any <int>()).Returns(info => step); workflow.WhenForAnyArgs(x => x.CallReducer(action, results)).DoNotCallBase(); workflow.CallReducer(action, results).Returns(info => String.Empty); workflow.WhenForAnyArgs(x => x.ResolveStepNumber(step, String.Empty, 0)).DoNotCallBase(); workflow.ResolveStepNumber(step, String.Empty, 0) .ReturnsForAnyArgs(info => new StepResult { Input = String.Empty, StepNumber = 0 }); workflow.WhenForAnyArgs(x => x.ScheduleStep(0, String.Empty, 3)).DoNotCallBase(); workflow.ScheduleStep(0, String.Empty, 3) .ReturnsForAnyArgs(info => new StepDecision()); workflow.ProcessActionCollection(context, state, schedulableState, action, step); //check if these methods were called workflow.Received().CallReducer(action, results); workflow.Received().ResolveStepNumber(step, String.Empty, 1); //1 is expected from schedulableState.StepNumber = 0 + 1 workflow.Received().ScheduleStep(0, String.Empty, 0); // 0 is expected from schedulableState.AttemptNumber = 1 - 1; }