public void WhileCancelled() { Variable <int> count = new Variable <int> { Name = "Counter", Default = 0 }; TestBlockingActivity blocking = new TestBlockingActivity("Bookmark") { ExpectedOutcome = Outcome.Canceled }; TestWhile whileAct = new TestWhile { Variables = { count }, Body = blocking, ConditionExpression = (e => count.Get(e) < 5), HintIterationCount = 1, ExpectedOutcome = Outcome.Canceled }; using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(whileAct)) { testWorkflowRuntime.ExecuteWorkflow(); testWorkflowRuntime.WaitForActivityStatusChange(blocking.DisplayName, TestActivityInstanceState.Executing); testWorkflowRuntime.CancelWorkflow(); testWorkflowRuntime.WaitForCanceled(); } }
public void SimpleWhileConditionTrue() { // Test case description: // Set condition to a valid rule and run with an activity in it. Condition is true - IMPLEMENTED IN BASIC WHILETEST TestSequence outerSequence = new TestSequence("sequence1"); TestSequence innerSequence = new TestSequence("Seq"); TestIncrement increment = new TestIncrement("test increment"); Variable <int> counter = VariableHelper.CreateInitialized <int>("counter", 0); TestWhile whileAct = new TestWhile("while act") { ConditionExpression = ((env) => ((int)counter.Get(env)) < 10), Body = innerSequence, HintIterationCount = 10, }; TestWriteLine writeLine = new TestWriteLine("write hello") { Message = "Its a small world after all" }; increment.CounterVariable = counter; innerSequence.Activities.Add(writeLine); innerSequence.Activities.Add(increment); outerSequence.Variables.Add(counter); outerSequence.Activities.Add(whileAct); TestRuntime.RunAndValidateWorkflow(outerSequence); }
public void FlowchartInProceduralWhile() { TestSequence s = new TestSequence("seq1"); Variable <int> counter = VariableHelper.CreateInitialized <int>("counter", 0); s.Variables.Add(counter); TestWhile w = new TestWhile("While1"); s.Activities.Add(w); TestFlowchart f = new TestFlowchart("Flow1"); TestAssign <int> assign = new TestAssign <int>("Assign1"); assign.ValueExpression = (env => ((int)counter.Get(env)) + 1); assign.ToVariable = counter; w.ConditionExpression = (env => counter.Get(env) < 5); w.HintIterationCount = 5; f.AddStartLink(assign); w.Body = f; TestRuntime.RunAndValidateWorkflow(s); }
public void BasicWhileNotRunTest() { TestSequence outerSequence = new TestSequence("sequence1"); TestSequence innerSequence = new TestSequence("innerseq"); TestAssign <int> increment = new TestAssign <int>("Increment COunter"); Variable <int> counter = VariableHelper.CreateInitialized <int>("counter", 0); TestWhile whileAct = new TestWhile("while act") { ConditionExpression = ((env) => ((int)counter.Get(env)) < 0), Body = innerSequence, HintIterationCount = 0, }; TestWriteLine writeLine = new TestWriteLine("write hello") { Message = "Its a small world after all" }; increment.ToVariable = counter; increment.ValueExpression = ((env) => (((int)counter.Get(env))) + 1); innerSequence.Activities.Add(writeLine); innerSequence.Activities.Add(increment); outerSequence.Variables.Add(counter); outerSequence.Activities.Add(whileAct); TestRuntime.RunAndValidateWorkflow(outerSequence); }
public void WhileWithNullBody() { TestWhile whileAct = new TestWhile(); whileAct.Body = null; whileAct.Condition = false; whileAct.HintIterationCount = -1; TestRuntime.RunAndValidateWorkflow(whileAct); }
public void WhileWithWorkFlowInvoker() { TestWhile whileAct = new TestWhile(); whileAct.Body = new TestWriteLine("w1", "This should not be written"); whileAct.Condition = false; whileAct.HintIterationCount = -1; TestRuntime.RunAndValidateUsingWorkflowInvoker(whileAct, null, null, null); }
public void WhileWithNullBody() { TestWhile whileAct = new TestWhile { Body = null, Condition = false, HintIterationCount = -1 }; TestRuntime.RunAndValidateWorkflow(whileAct); }
public void WhileWithExceptionFromCondition() { // Test case description: // Throw exception in while and in while condition TestSequence outerSequence = new TestSequence("sequence1"); TestSequence innerSequence = new TestSequence("Seq"); TestAssign <int> increment = new TestAssign <int>("Increment Counter"); Variable <int> counter = VariableHelper.CreateInitialized <int>("counter", 0); TestWhile whileAct = new TestWhile("while act") { Body = innerSequence, HintIterationCount = 10, }; ExceptionThrowingActivitiy <bool> throwFromCondition = new ExceptionThrowingActivitiy <bool>(); ((Microsoft.CoreWf.Statements.While)whileAct.ProductActivity).Condition = throwFromCondition; increment.ToVariable = counter; increment.ValueExpression = ((env) => (((int)counter.Get(env))) + 1); innerSequence.Activities.Add(increment); outerSequence.Variables.Add(counter); outerSequence.Activities.Add(whileAct); OrderedTraces trace = new OrderedTraces(); trace.Steps.Add(new ActivityTrace(outerSequence.DisplayName, ActivityInstanceState.Executing)); trace.Steps.Add(new ActivityTrace(whileAct.DisplayName, ActivityInstanceState.Executing)); OrderedTraces ordered = new OrderedTraces(); UnorderedTraces unordered = new UnorderedTraces(); unordered.Steps.Add(ordered); unordered.Steps.Add(new ActivityTrace(throwFromCondition.DisplayName, ActivityInstanceState.Executing)); unordered.Steps.Add(new ActivityTrace(throwFromCondition.DisplayName, ActivityInstanceState.Faulted)); trace.Steps.Add(unordered); ExpectedTrace expected = new ExpectedTrace(trace); expected.AddIgnoreTypes(typeof(WorkflowAbortedTrace)); expected.AddIgnoreTypes(typeof(SynchronizeTrace)); Exception exc; TestWorkflowRuntime tr = TestRuntime.CreateTestWorkflowRuntime(outerSequence); tr.CreateWorkflow(); tr.ResumeWorkflow(); tr.WaitForAborted(out exc, expected); Assert.True((exc.GetType() == typeof(DataMisalignedException)) && exc.Message == "I am Miss.Aligned!"); }
//[HostWorkflowAsWebService] public void IfInWhileSometimesIfThenTrueSometimesElseTrue() { Variable <int> counter = VariableHelper.CreateInitialized <int>("counter", 0); TestWriteLine writeTrue = new TestWriteLine("writeTrue") { Message = "I say you are RIGHT!" }; TestWriteLine writeFalse = new TestWriteLine("writeFalse") { Message = "I say you are WRONG!" }; TestIf ifAct = new TestIf("if act", HintThenOrElse.Then, HintThenOrElse.Else, HintThenOrElse.Then, HintThenOrElse.Else) { ConditionExpression = ((env) => ((int)counter.Get(env)) % 2 == 0), ThenActivity = writeTrue, ElseActivity = writeFalse, }; TestAssign <int> increment = new TestAssign <int>("Add One") { ToVariable = counter, ValueExpression = (env) => (((int)counter.Get(env))) + 1 }; TestSequence sequence = new TestSequence("innerSequence"); sequence.Activities.Add(ifAct); sequence.Activities.Add(increment); TestWhile whileAct = new TestWhile("while act") { ConditionExpression = (env) => ((int)counter.Get(env)) < 4, Body = sequence, HintIterationCount = 4, }; TestSequence rootSequence = new TestSequence("rootSequence"); rootSequence.Activities.Add(whileAct); rootSequence.Variables.Add(counter); TestRuntime.RunAndValidateWorkflow(rootSequence); }
public void WhileConditionNull() { // Test case description: // Set condition to null TestWhile whileAct = new TestWhile("while act") { Body = new TestSequence("innerseq"), HintIterationCount = 0, }; ((System.Activities.Statements.While)whileAct.ProductActivity).Condition = null; TestRuntime.ValidateInstantiationException(whileAct, String.Format(ErrorStrings.WhileRequiresCondition, whileAct.DisplayName)); }
public void WhileConditionInConstructor() { TestExpressionEvaluator <bool> condition = new TestExpressionEvaluator <bool> { ExpressionResult = false }; TestWhile whileAct = new TestWhile(condition) { Body = new TestWriteLine("Hello", "Hello"), HintIterationCount = 0 }; TestRuntime.RunAndValidateWorkflow(whileAct); }
public void WhileInfiniteLoopFaultAfterHundredLoops() { TestSequence outerSequence = new TestSequence("sequence1"); TestSequence innerSequence = new TestSequence("Seq"); TestIncrement increment = new TestIncrement("test increment"); TestSequence inNestedSequence = new TestSequence("Sequence in Nested while"); TestThrow <ArithmeticException> throwTestActivity = new TestThrow <ArithmeticException>(); Variable <int> counter = VariableHelper.CreateInitialized <int>("counter", 0); TestWhile whileAct = new TestWhile("while act") { ConditionExpression = ((env) => ((int)counter.Get(env)) < 200), Body = innerSequence, HintIterationCount = 200, }; inNestedSequence.Activities.Add(whileAct); inNestedSequence.Activities.Add(throwTestActivity); TestWhile whileActNested = new TestWhile("while act") { ConditionExpression = ((env) => (true)), Body = inNestedSequence, HintIterationCount = 200, }; TestWriteLine writeLine = new TestWriteLine("write hello") { Message = "Its a small world after all" }; increment.CounterVariable = counter; innerSequence.Activities.Add(writeLine); innerSequence.Activities.Add(increment); outerSequence.Variables.Add(counter); outerSequence.Activities.Add(whileActNested); TestRuntime.RunAndValidateAbortedException(outerSequence, typeof(ArithmeticException), new Dictionary <string, string>()); }
public void GetChildrenModifyChildrenExecute() { Variable <int> counter = VariableHelper.CreateInitialized <int>("counter", 0); TestWhile whileAct = new TestWhile("while act") { ConditionExpression = ((env) => false), Body = new TestSequence("Seq"), }; TestSequence outerSequence = new TestSequence("sequence1") { Variables = { counter }, Activities = { whileAct, }, }; WorkflowInspectionServices.GetActivities(whileAct.ProductActivity); whileAct.ConditionExpression = (env) => ((int)counter.Get(env)) < 1; whileAct.Body = new TestSequence("Inner Seq") { Activities = { new TestWriteLine("write hello") { Message = "Its a small world after all", }, new TestAssign <int>("Increment Counter") { ValueExpression = ((env) => (((int)counter.Get(env))) + 1), ToVariable = counter, }, }, }; whileAct.HintIterationCount = 1; // Now that we've changed the tree we need to recache WorkflowInspectionServices.CacheMetadata(outerSequence.ProductActivity); TestRuntime.RunAndValidateWorkflow(outerSequence); }
public void IfInWhileWithPersistence() { // Test case description: // Above scenario with persistence to see if there will be any change in the behavior and if we are able // tp preserve the state and the rules fine. Variable <int> count = new Variable <int> { Name = "Counter", Default = 0 }; TestWhile whileAct = new TestWhile { Variables = { count }, Body = new TestSequence { Activities = { new TestIf(HintThenOrElse.Then) { Condition = true, ThenActivity = new TestBlockingActivity("Bookmark"), }, new TestIncrement { CounterVariable = count, IncrementCount = 1 } } }, ConditionExpression = (e => count.Get(e) < 1), HintIterationCount = 1 }; JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~"); using (TestWorkflowRuntime runtime = TestRuntime.CreateTestWorkflowRuntime(whileAct, null, jsonStore, PersistableIdleAction.None)) { runtime.ExecuteWorkflow(); runtime.WaitForIdle(); runtime.PersistWorkflow(); runtime.ResumeBookMark("Bookmark", null); runtime.WaitForCompletion(); } }
public void WhileCancelledDuringConditionExecution() { TestWhile whileActivity = new TestWhile("While") { HintIterationCount = 0, ExpectedOutcome = Outcome.Canceled, ConditionActivity = new TestBlockingActivity <bool>("Blocking") { ExpectedOutcome = Outcome.Canceled, }, Body = new TestWriteLine("WriteLine", "WriteLine - Body"), }; using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(whileActivity)) { testWorkflowRuntime.ExecuteWorkflow(); testWorkflowRuntime.WaitForActivityStatusChange("Blocking", TestActivityInstanceState.Executing); testWorkflowRuntime.CancelWorkflow(); testWorkflowRuntime.WaitForCanceled(); } }
public void WhilePersisted() { Variable <int> count = new Variable <int> { Name = "Counter", Default = 0 }; TestWhile whileAct = new TestWhile { Variables = { count }, Body = new TestSequence { Activities = { new TestBlockingActivity("Bookmark"), new TestIncrement { CounterVariable = count, IncrementCount= 1 } } }, ConditionExpression = (e => count.Get(e) < 1), HintIterationCount = 1 }; JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~"); using (TestWorkflowRuntime runtime = TestRuntime.CreateTestWorkflowRuntime(whileAct, null, jsonStore, PersistableIdleAction.None)) { runtime.ExecuteWorkflow(); runtime.WaitForIdle(); runtime.PersistWorkflow(); runtime.ResumeBookMark("Bookmark", null); runtime.WaitForCompletion(); } }
public void WhileVariableNotInScope() { Variable <int> counter = VariableHelper.CreateInitialized <int>("counter", 0); TestWhile whileAct = new TestWhile("while act") { Condition = false, Body = new TestAssign <int> { Value = 12, ToVariable = counter, }, HintIterationCount = 10, }; string constraint1 = string.Format(ErrorStrings.VariableShouldBeOpen, counter.Name); string constraint2 = string.Format(ErrorStrings.VariableNotVisible, counter.Name); List <TestConstraintViolation> constraints = new List <TestConstraintViolation>(2); constraints.Add(new TestConstraintViolation(constraint1, "VariableReference<Int32>")); constraints.Add(new TestConstraintViolation(constraint2, "VariableReference<Int32>")); TestRuntime.ValidateWorkflowErrors(whileAct, constraints, constraint1); }
public void SimpleEmptyWhile() { // Test case description: // Set condition to a valid rule and run 5-6 iterations without any activities in. Variable <int> counter = VariableHelper.CreateInitialized <int>("counter", 0); TestSequence rootSequence = new TestSequence("rootSequence"); rootSequence.Variables.Add(counter); TestWhile whileAct = new TestWhile("while act") { ConditionExpression = ((env) => ((int)counter.Get(env)) < 0), Body = new TestSequence("innerseq"), HintIterationCount = 10, }; rootSequence.Activities.Add(whileAct); whileAct.Body = null; TestRuntime.RunAndValidateWorkflow(rootSequence); }
public void TryCatchFinallyInLoops() { Variable <int> count = new Variable <int>("Counter", 0); TestWhile whileAct = new TestWhile { Variables = { count }, ConditionExpression = e => count.Get(e) < 5, Body = new TestSequence { Activities = { new TestTryCatch { Try = new TestThrow <ArgumentException>() { ExpectedOutcome = Outcome.CaughtException() }, Catches = { { new TestCatch <ArgumentException>() { Body = new TestWriteLine("Caught", "Caught") } } }, Finally = new TestSequence{ Activities ={ new TestWriteLine("Finally", "Finally") } } }, new TestIncrement { CounterVariable = count, IncrementCount = 1 } } }, HintIterationCount = 5 }; TestRuntime.RunAndValidateWorkflow(whileAct); }
public void WhileWithException() { TestSequence outerSequence = new TestSequence("sequence1"); TestSequence innerSequence = new TestSequence("Seq"); TestIncrement increment = new TestIncrement("test increment"); TestThrow <ArithmeticException> throwArt = new TestThrow <ArithmeticException>("throw"); Variable <int> counter = VariableHelper.CreateInitialized <int>("counter", 0); TestWhile whileAct = new TestWhile("while act") { ConditionExpression = ((env) => ((int)counter.Get(env)) < 10), Body = innerSequence, HintIterationCount = 10, }; increment.CounterVariable = counter; innerSequence.Activities.Add(throwArt); innerSequence.Activities.Add(increment); outerSequence.Variables.Add(counter); outerSequence.Activities.Add(whileAct); TestRuntime.RunAndValidateAbortedException(outerSequence, typeof(ArithmeticException), new Dictionary <string, string>()); }
private static (Complex[] zeroRoots, Complex[] remaining) RemoveZeroRoots(Complex[] input) { var length = input.Length; return(TestWhile(() => 0, e => e + 1, e => input[length - 1 - e] == new Complex(0, 0), e => (((Complex)0).MakeArrayFor(e), input.Take(length - e).ToArray()))); }
public void NestedWhilesAndOtherLoops() { // Test case description: // Nested whiles deep up to 3-5 levels. Set valid conditions trace the order to be likewhile1 loop1 while2 // loop 1 while 3 loop1 while1 loop1 while2 loop1 whle3 loop2while1 loop1 while2 loop2 while3 loop1whlie1 // loop1 while2 loop2 while3 loop2…while1 loop2 while2 loop2 while3 loop2 TestSequence outerSequence = new TestSequence("sequence1"); TestSequence innerSequence = new TestSequence("inner seq"); TestAssign <int> increment = new TestAssign <int>("increase count"); Variable <int> doWhileCounter = VariableHelper.CreateInitialized <int>("counter", 0); Variable <int> loopCounter = VariableHelper.CreateInitialized <int>("loopcounter", 0); TestAssign <int> loopCounterIncrement = new TestAssign <int>("increase loop counter") { ToVariable = loopCounter, ValueExpression = ((env) => ((int)loopCounter.Get(env)) + 1) }; increment.ToVariable = doWhileCounter; increment.ValueExpression = ((env) => ((int)doWhileCounter.Get(env)) + 1); TestForEach <string> foreachAct = new TestForEach <string>("ForEach") { Body = innerSequence, ValuesExpression = (context => new List <string>() { "var1", "var2", "var3" }), HintIterationCount = 3, }; TestDoWhile doWhile = new TestDoWhile("do while") { ConditionExpression = ((env) => ((int)doWhileCounter.Get(env)) < 9), Body = foreachAct, HintIterationCount = 3, }; TestSequence whileSequence = new TestSequence("sequence1"); TestSequence innerIfSequence = new TestSequence("inner if sequence"); TestAssign <int> whileIncrement = new TestAssign <int>("increase count2"); Variable <int> whileCounter = VariableHelper.CreateInitialized <int>("counter2", 0); TestSequence ifSequence = new TestSequence("ifSequence"); TestWhile whileAct = new TestWhile("while") { ConditionExpression = ((env) => ((int)whileCounter.Get(env)) < 10), Body = ifSequence, HintIterationCount = 10, }; TestWriteLine writeLine = new TestWriteLine("write hello") { Message = "Its a small world after all" }; TestWriteLine writeLine2 = new TestWriteLine("write hello") { Message = "Its a small world after all" }; whileIncrement.ToVariable = whileCounter; whileIncrement.ValueExpression = ((env) => ((int)whileCounter.Get(env)) + 1); TestIf ifAct = new TestIf("ifact 1", HintThenOrElse.Else) { ConditionExpression = ((env) => ((int)whileCounter.Get(env)) > 10), ThenActivity = new TestWriteLine("w1", "I'm a non-executing funny writeLine"), ElseActivity = writeLine2, }; TestIf ifAct2 = new TestIf("if act 2", HintThenOrElse.Then) { ConditionExpression = ((env) => ((int)whileCounter.Get(env)) < 10), ThenActivity = innerIfSequence, }; TestIf checkLoopCount = new TestIf("check loop count", HintThenOrElse.Then) { ConditionExpression = ((env) => ((int)loopCounter.Get(env)) == 90), ThenActivity = writeLine, }; ifSequence.Activities.Add(ifAct); ifSequence.Activities.Add(ifAct2); innerIfSequence.Activities.Add(whileIncrement); innerIfSequence.Activities.Add(loopCounterIncrement); whileSequence.Variables.Add(whileCounter); whileSequence.Activities.Add(whileAct); innerSequence.Activities.Add(increment); innerSequence.Activities.Add(whileSequence); outerSequence.Activities.Add(doWhile); outerSequence.Activities.Add(checkLoopCount); outerSequence.Variables.Add(doWhileCounter); outerSequence.Variables.Add(loopCounter); TestRuntime.RunAndValidateWorkflow(outerSequence); }