public void FlowchartWithOnlyFlowConditionalWithoutStartEvent() { TestFlowchart flowchart = new TestFlowchart(); Variable <bool> flag = VariableHelper.CreateInitialized <bool>(true); flag.Name = "flag"; flowchart.Variables.Add(flag); TestFlowConditional decision = new TestFlowConditional { ConditionExpression = env => flag.Get(env) }; flowchart.AddConditionalLink(null, decision, new TestWriteLine("True", "True"), new TestWriteLine("False", "False")); TestRuntime.RunAndValidateWorkflow(flowchart); }
public void FlowDecisionAsStartElement() { TestFlowchart flowchart1 = new TestFlowchart("flowChart1"); TestWriteLine w2True = new TestWriteLine("True", "True will execute"); TestWriteLine w2False = new TestWriteLine("False", "False wont execute"); Variable <int> margin = VariableHelper.CreateInitialized <int>("Margin", 10); flowchart1.Variables.Add(margin); TestFlowConditional flowDecision = new TestFlowConditional(HintTrueFalse.True); flowDecision.ConditionExpression = (context => margin.Get(context) > 0); TestFlowElement tCond = flowchart1.AddConditionalLink(null, flowDecision, w2True, w2False); TestRuntime.RunAndValidateWorkflow(flowchart1); }
public void ExpressionSetToFalse() { TestFlowchart flowchart = new TestFlowchart("Flow1"); TestWriteLine writeLine1 = new TestWriteLine("hello1", "Hello1"); TestWriteLine writeLine2 = new TestWriteLine("hello2", "Hello2"); TestWriteLine writeLine3 = new TestWriteLine("hello3", "Hello3"); TestFlowConditional flowDecision = new TestFlowConditional(HintTrueFalse.False); flowDecision.Condition = false; flowchart.AddStartLink(writeLine1); flowchart.AddConditionalLink(writeLine1, flowDecision, writeLine2, writeLine3); TestRuntime.RunAndValidateWorkflow(flowchart); }
public void ConditionExpressionOnExistingVariable() { TestFlowchart flowchart = new TestFlowchart(); Variable <bool> flag = VariableHelper.CreateInitialized <bool>(true); flag.Name = "flag"; flowchart.Variables.Add(flag); TestFlowConditional decision = new TestFlowConditional { ConditionExpression = e => flag.Get(e) }; flowchart.AddConditionalLink(new TestWriteLine("Start", "Start"), decision, new TestWriteLine("True", "True"), new TestWriteLine("false", "false")); TestRuntime.RunAndValidateWorkflow(flowchart); }
public void DecisionWithConditionSetToExpressionActivity() { TestExpressionEvaluator <bool> myExpression = new TestExpressionEvaluator <bool>(true); TestFlowConditional flowConditinoal = new TestFlowConditional { ConditionValueExpression = (TestActivity)myExpression }; TestFlowchart flowchart = new TestFlowchart(); flowchart.AddConditionalLink(new TestWriteLine("Start", "FLowchart started"), flowConditinoal, new TestWriteLine("True Action", "True Action"), new TestWriteLine("False Action", "False Action")); TestRuntime.RunAndValidateWorkflow(flowchart); }
public void DecisionTruePinConnectedConditionEvaluationTrue() { TestFlowchart flowchart = new TestFlowchart("Flow1"); TestWriteLine writeLine1 = new TestWriteLine("hello1", "Hello1"); TestWriteLine writeLine2 = new TestWriteLine("hello2", "Hello2"); TestFlowConditional flowDecision = new TestFlowConditional { Condition = true }; flowchart.AddStartLink(writeLine1); flowchart.AddConditionalLink(writeLine1, flowDecision, writeLine2, (TestActivity)null); TestRuntime.RunAndValidateWorkflow(flowchart); }
public void AddSameElementToParentAndChild() { TestFlowchart flowchart1 = new TestFlowchart("flowChart1"); TestFlowchart flowchart2 = new TestFlowchart("flowChart2"); TestWriteLine w1 = new TestWriteLine("W1", "Executing W1"); TestFlowElement fStep = new TestFlowStep(w1); flowchart2.Elements.Add(fStep); Variable <int> margin = VariableHelper.CreateInitialized <int>("Margin", 10); flowchart1.Variables.Add(margin); TestFlowConditional flowDecision = new TestFlowConditional(HintTrueFalse.True); flowDecision.ConditionExpression = (context => margin.Get(context) > 0); TestFlowElement tCond = flowchart1.AddConditionalLink(null, flowDecision, fStep, flowchart2); TestRuntime.ValidateInstantiationException(flowchart1, string.Format(ErrorStrings.FlowNodeCannotBeShared, flowchart1.DisplayName, flowchart2.DisplayName)); }
public void DecisionTrueEvaluation() { TestFlowchart flowchart = new TestFlowchart("Flow1"); Variable <int> counter = VariableHelper.CreateInitialized <int>("counter", 3); flowchart.Variables.Add(counter); TestWriteLine writeLine1 = new TestWriteLine("hello1", "Hello1"); TestWriteLine writeLine2 = new TestWriteLine("hello2", "Hello2"); TestWriteLine writeLine3 = new TestWriteLine("hello3", "Hello3"); TestFlowConditional flowDecision = new TestFlowConditional(); flowDecision.ConditionExpression = ((env) => (counter.Get(env) == 3)); flowchart.AddConditionalLink(writeLine1, flowDecision, writeLine2, writeLine3); TestRuntime.RunAndValidateWorkflow(flowchart); }
public void FlowDecisionConnectedToFlowStep() { TestFlowchart flowchart = new TestFlowchart("Flow1"); Variable <int> counter = VariableHelper.CreateInitialized <int>("counter", 3); flowchart.Variables.Add(counter); TestWriteLine writeLine1 = new TestWriteLine("hello1", "Hello1"); TestWriteLine writeLine2 = new TestWriteLine("hello2", "Hello2"); TestWriteLine writeLine3 = new TestWriteLine("hello3", "Hello3"); TestFlowConditional flowDecision = new TestFlowConditional(HintTrueFalse.True); flowDecision.ConditionExpression = (context => counter.Get(context) > 0); flowchart.AddStartLink(writeLine1); flowchart.AddConditionalLink(writeLine1, flowDecision, writeLine2, writeLine3); TestRuntime.RunAndValidateWorkflow(flowchart); }
public void FlowDecisionWithTrueElementNullEvaluationTrue() { // This is a valid testcase and we don't expect error. TestFlowchart flowchart1 = new TestFlowchart("flowChart1"); TestWriteLine w2True = new TestWriteLine("True", "True will execute"); TestWriteLine w2False = new TestWriteLine("False", "False wont execute"); Variable <int> margin = new Variable <int> { Name = "margin", Default = 10 }; flowchart1.Variables.Add(margin); TestFlowConditional flowDecision = new TestFlowConditional((HintTrueFalse[])null); // null here means neither True or False will happen as the action is null flowDecision.ConditionExpression = (context => margin.Get(context) > 0); TestFlowElement tCond = flowchart1.AddConditionalLink(null, flowDecision, null, w2False); TestRuntime.RunAndValidateWorkflow(flowchart1); }
public void ExpressionSetToTrue() { TestFlowchart flowchart = new TestFlowchart("Flow1"); Variable <bool> trueVar = new Variable <bool>("trueVar", true); flowchart.Variables.Add(trueVar); TestWriteLine writeLine1 = new TestWriteLine("hello1", "Hello1"); TestWriteLine writeLine2 = new TestWriteLine("hello2", "Hello2"); TestWriteLine writeLine3 = new TestWriteLine("hello3", "Hello3"); TestFlowConditional flowDecision = new TestFlowConditional(); flowDecision.ConditionVariable = trueVar; flowchart.AddConditionalLink(writeLine1, flowDecision, writeLine2, writeLine3); TestRuntime.RunAndValidateWorkflow(flowchart); }
public void ConditionExpressionOnFlowchartVariable() { TestFlowchart flowchart = new TestFlowchart("Flow1"); Variable <int> counter = VariableHelper.CreateInitialized <int>("counter", 3); flowchart.Variables.Add(counter); TestWriteLine writeLine1 = new TestWriteLine("hello1", "Hello1"); TestWriteLine writeLine2 = new TestWriteLine("hello2", "Hello2"); TestWriteLine writeLine3 = new TestWriteLine("hello3", "Hello3"); TestFlowConditional flowDecision = new TestFlowConditional { ConditionExpression = (context => counter.Get(context) == 3) }; flowchart.AddStartLink(writeLine1); flowchart.AddConditionalLink(writeLine1, flowDecision, writeLine2, writeLine3); TestRuntime.RunAndValidateWorkflow(flowchart); }
public void UnloadFlowchartWhileExecutingFlowConditionalCondition() { TestFlowchart flowchart = new TestFlowchart(); TestExpressionEvaluatorWithBody <bool> expression = new TestExpressionEvaluatorWithBody <bool>(true) { Body = new TestBlockingActivity("Block"), WillBodyExecute = true }; TestFlowConditional conditional = new TestFlowConditional(HintTrueFalse.True) { ConditionValueExpression = expression }; flowchart.AddConditionalLink(new TestWriteLine("Start", "Flowchart started"), conditional, new TestWriteLine("True", "True Action"), new TestWriteLine("False", "False Action")); JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(System.Environment.CurrentDirectory); using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(flowchart, null, jsonStore, PersistableIdleAction.Unload)) { testWorkflowRuntime.ExecuteWorkflow(); testWorkflowRuntime.WaitForActivityStatusChange(expression.DisplayName, TestActivityInstanceState.Executing); //testWorkflowRuntime.PersistWorkflow(); testWorkflowRuntime.UnloadWorkflow(); testWorkflowRuntime.LoadWorkflow(); testWorkflowRuntime.ResumeBookMark("Block", null); testWorkflowRuntime.WaitForCompletion(true); } }
public void FlowSwitchConnectedToFlowDecision() { TestFlowchart flowchart = new TestFlowchart(); TestWriteLine wStart = new TestWriteLine("Start", "Flowchart started"); TestWriteLine wDefault = new TestWriteLine("Default", "Default"); TestWriteLine w1 = new TestWriteLine("One", "One wont execute"); TestWriteLine w3 = new TestWriteLine("Three", "Three wont execute"); TestWriteLine w2True = new TestWriteLine("True", "True will execute"); TestWriteLine w2False = new TestWriteLine("False", "False wont execute"); TestFlowStep fs1 = new TestFlowStep(w1); TestFlowStep fs3 = new TestFlowStep(w3); Variable <int> margin = VariableHelper.CreateInitialized <int>("Margin", 10); flowchart.Variables.Add(margin); TestFlowConditional flowDecision = new TestFlowConditional(HintTrueFalse.True) { ConditionExpression = (context => margin.Get(context) > 0) }; flowchart.AddConditionalLink(null, flowDecision, w2True, w2False); Dictionary <string, TestFlowElement> cases = new Dictionary <string, TestFlowElement>(); cases.Add("One", fs1); cases.Add("Two", flowDecision); cases.Add("Three", fs3); List <int> hints = new List <int>(); hints.Add(1); flowchart.AddStartLink(wStart); flowchart.AddSwitchLink <string>(wStart, cases, hints, "Two", wDefault); TestRuntime.RunAndValidateWorkflow(flowchart); }
public void CancelFlowchartWhileEvaluatingFlowConditionalCondition() { TestFlowchart flowchart = new TestFlowchart(); TestBlockingActivity blocking = new TestBlockingActivity("Block", "Blocked") { ExpectedOutcome = Outcome.Canceled }; TestExpressionEvaluatorWithBody <bool> expression = new TestExpressionEvaluatorWithBody <bool>(true) { Body = blocking, WillBodyExecute = true }; TestFlowConditional conditional = new TestFlowConditional { ConditionValueExpression = expression }; flowchart.AddConditionalLink(new TestWriteLine("Start", "Flowchart started"), conditional, new TestWriteLine("True", "True Action"), new TestWriteLine("False", "False Action")); expression.ExpectedOutcome = Outcome.Canceled; flowchart.ExpectedOutcome = Outcome.Canceled; using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(flowchart)) { testWorkflowRuntime.ExecuteWorkflow(); testWorkflowRuntime.WaitForActivityStatusChange(blocking.DisplayName, TestActivityInstanceState.Executing); testWorkflowRuntime.CancelWorkflow(); testWorkflowRuntime.WaitForCanceled(true); } }
/// <summary> /// Exception thrown during expression evaluation. /// </summary> /// This test is disabled in desktop and failing too. //[Fact] public void FaultWhileExpressionEvaluation() { const string exceptionString = "I am a faulty little expression's exception"; TestFlowchart flowchart = new TestFlowchart("Flow1"); TestExpressionEvaluatorWithBody <bool> faultyExpression = new TestExpressionEvaluatorWithBody <bool> { Body = new TestThrow <Exception>("Faulty Little Expression") { ExceptionExpression = (context => new Exception(exceptionString)) } }; TestWriteLine writeLine1 = new TestWriteLine("WriteStatus", "I will execute"); TestFlowConditional conditional = new TestFlowConditional() { ConditionValueExpression = faultyExpression }; flowchart.AddConditionalLink(writeLine1, conditional, new TestWriteLine("True", "True"), new TestWriteLine("False", "False")); TestRuntime.RunAndValidateAbortedException(flowchart, typeof(Exception), new Dictionary <string, string>()); }
public void FlowDecisionAndFlowSwitchNotConnected() { TestFlowchart flowchart1 = new TestFlowchart("flowChart1"); TestWriteLine start1 = new TestWriteLine("Start", "Executing Start"); TestWriteLine w1 = new TestWriteLine("W1", "Executing W1"); TestWriteLine w2 = new TestWriteLine("W2", "Executing W2"); TestWriteLine w3 = new TestWriteLine("W3", "Executing W3"); TestWriteLine wDefault = new TestWriteLine("wDefault", "Executing wDefault"); Dictionary <string, TestActivity> cases = new Dictionary <string, TestActivity>(); cases.Add("One", w1); cases.Add("Two", w2); List <int> hints = new List <int>(); hints.Add(1); flowchart1.AddSwitchLink <string>(null, cases, hints, "Two", wDefault); TestWriteLine w2True = new TestWriteLine("True", "True will execute"); TestWriteLine w2False = new TestWriteLine("False", "False wont execute"); Variable <int> margin = VariableHelper.CreateInitialized <int>("Margin", 10); flowchart1.Variables.Add(margin); TestFlowConditional flowDecision = new TestFlowConditional(HintTrueFalse.True) { ConditionExpression = (context => margin.Get(context) > 0) }; TestFlowElement tCond = flowchart1.AddConditionalLink(null, flowDecision, w2True, w2False); flowchart1.Elements.Add(tCond); TestRuntime.RunAndValidateWorkflow(flowchart1); }
public void NestedFlowchartInLoop() { TestFlowchart parentFlowchart = new TestFlowchart("ParentFlowchart"); TestFlowchart childFlowchart = new TestFlowchart("ChildFlowchart"); Variable <int> counter = VariableHelper.CreateInitialized <int>("counter", 0); parentFlowchart.Variables.Add(counter); TestAssign <int> assign = new TestAssign <int>("Assign1") { ValueExpression = (env => ((int)counter.Get(env)) + 1), ToVariable = counter }; List <HintTrueFalse> hints = new List <HintTrueFalse>(); for (int i = 0; i < 5; i++) { hints.Add(HintTrueFalse.True); } hints.Add(HintTrueFalse.False); TestFlowConditional flowDecision = new TestFlowConditional(hints.ToArray()) { ConditionExpression = (env => counter.Get(env) <= 5) }; parentFlowchart.AddLink(new TestWriteLine("Start", "Parent started"), childFlowchart); parentFlowchart.AddConditionalLink(childFlowchart, flowDecision, childFlowchart, new TestWriteLine("End", "Parent ended")); childFlowchart.AddStartLink(assign); TestRuntime.RunAndValidateWorkflow(parentFlowchart); }
public void Flowchart_ForEach() { TestFlowchart flowchart = new TestFlowchart("Flow1"); List <int> tenInts = new List <int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; Variable <List <int> > listOfInts = new Variable <List <int> >("listOfInts", (env) => new List <int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); flowchart.Variables.Add(listOfInts); Variable <int> counter = VariableHelper.CreateInitialized <int>("counter", 0); flowchart.Variables.Add(counter); Variable <bool> boolVar = VariableHelper.CreateInitialized <bool>("boolVar", true); flowchart.Variables.Add(boolVar); Variable <IEnumerator <int> > intEnumerator = VariableHelper.Create <IEnumerator <int> >("intEnumerator"); flowchart.Variables.Add(intEnumerator); TestAssign <IEnumerator <int> > assign1 = new TestAssign <IEnumerator <int> >("Assign1") { ValueExpression = ((env) => ((List <int>)listOfInts.Get(env)).GetEnumerator()), ToVariable = intEnumerator }; TestAssign <bool> assign2 = new TestAssign <bool>("Assign2") { ValueExpression = ((env) => ((IEnumerator <int>)intEnumerator.Get(env)).MoveNext()), ToVariable = boolVar }; List <HintTrueFalse> hints = new List <HintTrueFalse>(); for (int i = 0; i < 10; i++) { hints.Add(HintTrueFalse.True); } hints.Add(HintTrueFalse.False); TestFlowConditional flowDecision = new TestFlowConditional(hints.ToArray()) { ConditionExpression = (context => boolVar.Get(context) == true) }; flowchart.AddStartLink(assign1); flowchart.AddLink(assign1, assign2); flowchart.AddConditionalLink(assign2, flowDecision, assign2, new TestWriteLine("End", "Flowchart ended")); TestRuntime.RunAndValidateWorkflow(flowchart); }
public void NestedLoopsExecution() { TestFlowchart flowchart = new TestFlowchart("Flow1"); Variable <int> innerLoopcounter = VariableHelper.CreateInitialized <int>("InnerLoopCounter", 0); flowchart.Variables.Add(innerLoopcounter); Variable <int> outerLoopCounter = VariableHelper.CreateInitialized <int>("OuterLoopCounter", 0); flowchart.Variables.Add(outerLoopCounter); TestAssign <int> outerAssign = new TestAssign <int>("OuterAssign"); outerAssign.ValueExpression = ((env) => ((int)outerLoopCounter.Get(env)) + 1); outerAssign.ToVariable = outerLoopCounter; TestAssign <int> innerAssign = new TestAssign <int>("InnerAssign"); innerAssign.ValueExpression = (env) => ((int)innerLoopcounter.Get(env)) + 1; innerAssign.ToVariable = innerLoopcounter; TestAssign <int> resetInnerCounter = new TestAssign <int>("ResetInnerCounter"); resetInnerCounter.Value = 0; resetInnerCounter.ToVariable = innerLoopcounter; List <HintTrueFalse> outerHints = new List <HintTrueFalse>(); for (int i = 0; i < 9; i++) { outerHints.Add(HintTrueFalse.True); } outerHints.Add(HintTrueFalse.False); TestFlowConditional outerFlowDecision = new TestFlowConditional(outerHints.ToArray()); outerFlowDecision.ConditionExpression = (context => outerLoopCounter.Get(context) < 10); List <HintTrueFalse> innerHints = new List <HintTrueFalse>(); for (int i = 0; i < 4; i++) { innerHints.Add(HintTrueFalse.True); } innerHints.Add(HintTrueFalse.False); TestFlowConditional innerFlowDecision = new TestFlowConditional(innerHints.ToArray()); innerFlowDecision.ConditionExpression = (context => innerLoopcounter.Get(context) < 5); innerFlowDecision.ResetHints = true; flowchart.AddLink(new TestWriteLine("Start", "Flowchart started"), outerAssign); flowchart.AddLink(outerAssign, resetInnerCounter); flowchart.AddLink(resetInnerCounter, innerAssign); flowchart.AddConditionalLink(innerAssign, innerFlowDecision, innerAssign, outerFlowDecision); flowchart.AddConditionalLink(null, outerFlowDecision, outerAssign, new TestWriteLine("End", "Flowchart completed")); TestRuntime.RunAndValidateWorkflow(flowchart); }
public void ExecuteFiveLevelDeepNestedLoops() { TestFlowchart flowchart = new TestFlowchart("Flowchart1"); Variable <int> loop1Counter = VariableHelper.CreateInitialized <int>("Loop1Counter", 0); flowchart.Variables.Add(loop1Counter); Variable <int> loop2Counter = VariableHelper.CreateInitialized <int>("Loop2Counter", 0); flowchart.Variables.Add(loop2Counter); Variable <int> loop3Counter = VariableHelper.CreateInitialized <int>("Loop3Counter", 0); flowchart.Variables.Add(loop3Counter); Variable <int> loop4Counter = VariableHelper.CreateInitialized <int>("Loop4Counter", 0); flowchart.Variables.Add(loop4Counter); Variable <int> loop5Counter = VariableHelper.CreateInitialized <int>("Loop5Counter", 0); flowchart.Variables.Add(loop5Counter); TestAssign <int> assign1 = new TestAssign <int>("Assign1"); assign1.ValueExpression = ((env) => (int)loop1Counter.Get(env) + 1); assign1.ToVariable = loop1Counter; TestAssign <int> assign2 = new TestAssign <int>("Assign2"); assign2.ValueExpression = ((env) => (int)loop2Counter.Get(env) + 1); assign2.ToVariable = loop2Counter; TestAssign <int> assign3 = new TestAssign <int>("Assign3"); assign3.ValueExpression = ((env) => (int)loop3Counter.Get(env) + 1); assign3.ToVariable = loop3Counter; TestAssign <int> assign4 = new TestAssign <int>("Assign4"); assign4.ValueExpression = ((env) => (int)loop4Counter.Get(env) + 1); assign4.ToVariable = loop4Counter; TestAssign <int> assign5 = new TestAssign <int>("Assign5"); assign5.ValueExpression = ((env) => (int)loop5Counter.Get(env) + 1); assign5.ToVariable = loop5Counter; List <HintTrueFalse> hintsList = new List <HintTrueFalse>(); for (int i = 0; i < 5; i++) { hintsList.Add(HintTrueFalse.True); } hintsList.Add(HintTrueFalse.False); HintTrueFalse[] hints = hintsList.ToArray(); TestFlowConditional flowDecision1 = new TestFlowConditional(hints); flowDecision1.ConditionExpression = (env => loop1Counter.Get(env) <= 5); TestFlowConditional flowDecision2 = new TestFlowConditional(hints); flowDecision2.ConditionExpression = (env => loop2Counter.Get(env) <= 5); TestFlowConditional flowDecision3 = new TestFlowConditional(hints); flowDecision3.ConditionExpression = (env => loop3Counter.Get(env) <= 5); TestFlowConditional flowDecision4 = new TestFlowConditional(hints); flowDecision4.ConditionExpression = (env => loop4Counter.Get(env) <= 5); TestFlowConditional flowDecision5 = new TestFlowConditional(hints); flowDecision5.ConditionExpression = (env => loop5Counter.Get(env) <= 5); flowchart.AddLink(new TestWriteLine("Start", "Flowchart started"), assign1); flowchart.AddLink(assign1, assign2); flowchart.AddLink(assign2, assign3); flowchart.AddLink(assign3, assign4); flowchart.AddLink(assign4, assign5); flowchart.AddConditionalLink(assign5, flowDecision5, assign5, flowDecision4); flowchart.AddConditionalLink((TestActivity)null, flowDecision4, assign4, flowDecision3); flowchart.AddConditionalLink((TestActivity)null, flowDecision3, assign3, flowDecision2); flowchart.AddConditionalLink((TestActivity)null, flowDecision2, assign2, flowDecision1); flowchart.AddConditionalLink((TestActivity)null, flowDecision1, assign1, new TestWriteLine("End", "Flowchart ended")); TestRuntime.RunAndValidateWorkflow(flowchart); }