예제 #1
0
        public void CancelParallelForEach()
        {
            TestParallelForEach <string> parallelForEach = new TestParallelForEach <string>()
            {
                HintValues = new List <string>()
                {
                    "Hi", "There"
                },
                ValuesExpression = (context => new List <string>()
                {
                    "Hi", "There"
                }),
                Body             = new TestBlockingActivityUnique("Blocking activity")
                {
                    ExpectedOutcome = Outcome.Canceled
                }
            };

            using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(parallelForEach))
            {
                testWorkflowRuntime.ExecuteWorkflow();
                testWorkflowRuntime.WaitForActivityStatusChange("Blocking activity", TestActivityInstanceState.Executing);
                testWorkflowRuntime.CancelWorkflow();
                testWorkflowRuntime.WaitForCanceled();
            }
        }
예제 #2
0
        /// <summary>
        /// Five level deep nested flowchart with blocking activity
        /// </summary>
        /// Disabled and failed in desktop
        //[Fact]
        public void FiveLevelDeepNestedFlowchartWithBlockingActivity()
        {
            TestFlowchart        parent   = new TestFlowchart();
            TestFlowchart        child1   = new TestFlowchart();
            TestFlowchart        child2   = new TestFlowchart();
            TestFlowchart        child3   = new TestFlowchart();
            TestFlowchart        child4   = new TestFlowchart();
            TestBlockingActivity blocking = new TestBlockingActivity("Blocked");

            parent.AddStartLink(child1);
            child1.AddStartLink(child2);
            child2.AddStartLink(child3);
            child3.AddStartLink(child4);
            child4.AddStartLink(blocking);

            using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(parent))
            {
                testWorkflowRuntime.ExecuteWorkflow();

                testWorkflowRuntime.WaitForActivityStatusChange(blocking.DisplayName, TestActivityInstanceState.Executing);

                testWorkflowRuntime.ResumeBookMark("Blocked", null);

                testWorkflowRuntime.WaitForCompletion();
            }
        }
예제 #3
0
        private static WorkflowApplicationInstance GetADummyWorkflowApplicationInstance()
        {
            WorkflowIdentity wfIdentity   = new WorkflowIdentity("GetAWorkflowApplicationInstanceParameter", new Version(1, 0), null);
            TestSequence     wfDefinition = new TestSequence()
            {
                Activities =
                {
                    new TestWriteLine("testWriteLine1",    "In TestWriteLine1"),
                    new TestReadLine <string>("ReadLine1", "testReadLine1"),
                    new TestWriteLine("testWriteLine2",    "In TestWriteLine2")
                },
            };

            WorkflowApplicationInstance waInstance;

            JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~");

            using (TestWorkflowRuntime workflowRuntime = TestRuntime.CreateTestWorkflowRuntime(wfDefinition, null, jsonStore, PersistableIdleAction.Unload))
            {
                //PersistenceProviderHelper pphelper = new PersistenceProviderHelper(workflowRuntime.PersistenceProviderFactoryType);
                //InstanceStore store = pphelper.CreateWorkflowInstanceStore();

                workflowRuntime.ExecuteWorkflow();
                workflowRuntime.WaitForIdle();
                workflowRuntime.UnloadWorkflow();
                workflowRuntime.WaitForUnloaded();

                Guid worklfowInstanceId = workflowRuntime.CurrentWorkflowInstanceId;
                waInstance = WorkflowApplication.GetInstance(worklfowInstanceId, jsonStore);
                waInstance.Abandon();
            }

            return(waInstance);
        }
예제 #4
0
        public void RethrowExceptionFromInvokeMethodWithAllExceptionPropertiesSet()
        {
            TestInvokeMethod im = new TestInvokeMethod
            {
                TargetObject    = new TestArgument <CustomClassForRethrow>(Direction.In, "TargetObject", (context => new CustomClassForRethrow())),
                MethodName      = "M1",
                ExpectedOutcome = Outcome.CaughtException(typeof(TestCaseException)),
            };
            TestTryCatch tc = new TestTryCatch();
            TestCatch <TestCaseException> tcCatch = new TestCatch <TestCaseException>
            {
                Body = new TestRethrow
                {
                    ExpectedOutcome = Outcome.UncaughtException(typeof(TestCaseException))
                }
            };

            tc.Try = im;
            tc.Catches.Add(tcCatch);

            using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(tc))
            {
                testWorkflowRuntime.ExecuteWorkflow();
                testWorkflowRuntime.WaitForAborted(out Exception outEx);
                Dictionary <string, string> errorProperty = new Dictionary <string, string>();
                errorProperty.Add("Message", "this should be caught");
                ExceptionHelpers.ValidateException(outEx, typeof(TestCaseException), errorProperty);
            }
        }
예제 #5
0
        public void TerminateActivityWithExceptionWithoutReason()
        {
            s_exceptionType     = typeof(TAC.ApplicationException);
            s_exceptionMsg      = "I am throwing this Exception";
            s_terminationReason = null;

            TestSequence seq = new TestSequence("TerminateSeq")
            {
                Activities =
                {
                    new TestTerminateWorkflow("Terminating")
                    {
                        ExceptionExpression = ((env) => new TAC.ApplicationException("I am throwing this Exception"))
                    }
                },
            };

            using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(seq))
            {
                testWorkflowRuntime.OnWorkflowCompleted += new EventHandler <TestWorkflowCompletedEventArgs>(VerifyUnsetValue);
                testWorkflowRuntime.ExecuteWorkflow();

                WaitForTerminationHelper(testWorkflowRuntime);
            }
        }
예제 #6
0
        public void FlowSwitchHavingCaseWithNullKeyEvaluateNull()
        {
            TestFlowchart flowchart = new TestFlowchart();

            Variable <Complex> complexVar = VariableHelper.CreateInitialized <Complex>("complexVar", (Complex)null);

            flowchart.Variables.Add(complexVar);

            Dictionary <Complex, TestActivity> cases = new Dictionary <Complex, TestActivity>();

            cases.Add(new Complex(0, 0), new TestWriteLine("One", "One"));
            cases.Add(new Complex(1, 0), new TestWriteLine("Two", "Two"));
            cases.Add(new Complex(2, 0), new TestWriteLine("Three", "Three"));

            List <int> hints = new List <int>()
            {
                -1
            };

            TestFlowSwitch <Complex> flowSwitch = flowchart.AddSwitchLink <Complex>(new TestWriteLine("Start", "Flowchart started"), cases, hints, e => complexVar.Get(e)) as TestFlowSwitch <Complex>;

            ((FlowSwitch <Complex>)flowSwitch.GetProductElement()).Cases.Add(null, new FlowStep {
                Action = new BlockingActivity("Blocking")
            });

            using (TestWorkflowRuntime runtime = TestRuntime.CreateTestWorkflowRuntime(flowchart))
            {
                runtime.ExecuteWorkflow();
                runtime.WaitForActivityStatusChange("Blocking", TestActivityInstanceState.Executing);
                runtime.ResumeBookMark("Blocking", null);

                runtime.WaitForCompletion(false);
            }
        }
예제 #7
0
        public void TerminateActivityWithReasonWithoutException()
        {
            s_exceptionType     = null;
            s_exceptionMsg      = null;
            s_terminationReason = "Just cus!";

            TestSequence seq = new TestSequence("TerminateSeq")
            {
                Activities =
                {
                    new TestSequence("Second")
                    {
                        Activities =
                        {
                            new TestTerminateWorkflow("Terminating")
                            {
                                Reason = s_terminationReason,
                            }
                        }
                    }
                },
            };

            using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(seq))
            {
                testWorkflowRuntime.OnWorkflowCompleted += new EventHandler <TestWorkflowCompletedEventArgs>(VerifyUnsetValue);
                testWorkflowRuntime.ExecuteWorkflow();

                WaitForTerminationHelper(testWorkflowRuntime);
            }
        }
예제 #8
0
        private void RunTestWithWorkflowRuntime(TestActivity activity)
        {
            using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(activity))
            {
                testWorkflowRuntime.OnWorkflowCompleted += new EventHandler <TestWorkflowCompletedEventArgs>(workflowInstance_Completed);
                testWorkflowRuntime.ExecuteWorkflow();

                WorkflowTrackingWatcher watcher = testWorkflowRuntime.GetWatcher();
                OrderedTraces           orderedExpectedTrace = new OrderedTraces
                {
                    Steps =
                    {
                        new WorkflowInstanceTrace(testWorkflowRuntime.CurrentWorkflowInstanceId, WorkflowInstanceState.Started),
                        new WorkflowInstanceTrace(testWorkflowRuntime.CurrentWorkflowInstanceId, WorkflowInstanceState.Terminated),
                        new WorkflowInstanceTrace(testWorkflowRuntime.CurrentWorkflowInstanceId, WorkflowInstanceState.Deleted)
                        {
                            Optional = true
                        }
                    }
                };

                ExpectedTrace expectedWorkflowInstacneTrace = new ExpectedTrace(orderedExpectedTrace);

                Exception exp = new Exception();
                testWorkflowRuntime.WaitForTerminated(1, out exp, watcher.ExpectedTraces, expectedWorkflowInstacneTrace);
            }
        }
예제 #9
0
        public void AddTextWriterExtensionToRuntimeAndUseWriteLineWithTextWriter()
        {
            string stringToWrite = "Writing text to  a file with StreamWriter object";

            using (StreamWriter streamWriter1 = new StreamWriter(new MemoryStream()))
            {
                using (StreamWriter streamWriter2 = new StreamWriter(new FileStream(_tempFilePath, FileMode.Create, FileAccess.Write)))
                {
                    TestProductWriteline writeline = new TestProductWriteline("Write with StreamWriter")
                    {
                        Text = stringToWrite,
                        TextWriterExpression = context => streamWriter2,
                    };

                    using (TestWorkflowRuntime runtime = TestRuntime.CreateTestWorkflowRuntime(writeline))
                    {
                        runtime.CreateWorkflow();
                        runtime.Extensions.Add(streamWriter1);
                        runtime.ResumeWorkflow();
                        runtime.WaitForCompletion();
                    }
                }
            }

            VerifyTextOfWriteLine(_tempFilePath, stringToWrite);
        }
예제 #10
0
        public void OnAbortedThrowException()
        {
            TestSequence sequence = new TestSequence()
            {
                Activities =
                {
                    new TestReadLine <string>("Read1", "Read1")
                    {
                    }
                }
            };

            TestWorkflowRuntime runtime = TestRuntime.CreateTestWorkflowRuntime(sequence);

            runtime.OnWorkflowAborted += new EventHandler <TestWorkflowAbortedEventArgs>(OnWorkflowInstanceAborted_ThrowException);
            runtime.ExecuteWorkflow();
            runtime.WaitForIdle();

            runtime.AbortWorkflow("Abort Workflow");
            TestTraceManager.Instance.WaitForTrace(runtime.CurrentWorkflowInstanceId, new SynchronizeTrace(TraceMessage_ThrowExceptionFromAborted), 1);

            //Verify that the product can continue to function
            runtime = TestRuntime.CreateTestWorkflowRuntime(sequence);
            runtime.ExecuteWorkflow();
            runtime.ResumeBookMark("Read1", "Continue workflow");
            runtime.WaitForCompletion();
        }
예제 #11
0
        public void CancelExecutingChildActivities()
        {
            TestFlowchart parent = new TestFlowchart("Parent");

            TestBlockingActivity blocking   = new TestBlockingActivity("BlockingActivity", "B1");
            TestWriteLine        writeLine1 = new TestWriteLine("w1", "w1");
            TestWriteLine        writeLine2 = new TestWriteLine("w2", "w2");

            parent.AddLink(writeLine1, blocking);
            TestFlowElement element = parent.AddLink(blocking, writeLine2);

            element.IsCancelling = true;

            blocking.ExpectedOutcome = Outcome.Canceled;
            parent.ExpectedOutcome   = Outcome.Canceled;

            using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(parent))
            {
                testWorkflowRuntime.ExecuteWorkflow();
                testWorkflowRuntime.WaitForActivityStatusChange("BlockingActivity", TestActivityInstanceState.Executing);
                testWorkflowRuntime.CancelWorkflow();
                System.Threading.Thread.Sleep(2000);
                testWorkflowRuntime.WaitForCanceled();
            }
        }
예제 #12
0
        public void UnloadFlowchartWhileExecutingFlowStep()
        {
            TestFlowchart flowchart = new TestFlowchart();

            TestBlockingActivity blocking = new TestBlockingActivity("Block");

            flowchart.AddStartLink(blocking);

            JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~");

            using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(flowchart, null, jsonStore, PersistableIdleAction.Unload))
            {
                testWorkflowRuntime.ExecuteWorkflow();

                testWorkflowRuntime.WaitForActivityStatusChange(blocking.DisplayName, TestActivityInstanceState.Executing);

                testWorkflowRuntime.UnloadWorkflow();

                testWorkflowRuntime.LoadWorkflow();


                testWorkflowRuntime.ResumeBookMark("Block", null);

                testWorkflowRuntime.WaitForCompletion();
            }
        }
예제 #13
0
 public static void RunAndValidateUsingWorkflowInvoker(TestActivity testActivity, Dictionary <string, object> inputs, Dictionary <string, object> expectedOutputs, ICollection <object> extensions, TimeSpan invokeTimeout)
 {
     using (TestWorkflowRuntime testWorkflowRuntime = new TestWorkflowRuntime(testActivity))
     {
         testWorkflowRuntime.ExecuteWorkflowInvoker(inputs, expectedOutputs, extensions, invokeTimeout);
     }
 }
예제 #14
0
        public void DoWhileCancelled()
        {
            TestDoWhile doWhile = new TestDoWhile("Do while")
            {
                Condition = true,
                Body      = new TestSequence("Do While Body")
                {
                    Activities =
                    {
                        new TestBlockingActivity("BlockingActivity", "Bookmark")
                        {
                            ExpectedOutcome = Outcome.Canceled
                        },

                        new TestWriteLine("Writeline")
                        {
                            Message = "Hello"
                        }
                    }
                },

                HintIterationCount = 1,
            };

            using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(doWhile))
            {
                testWorkflowRuntime.ExecuteWorkflow();
                testWorkflowRuntime.WaitForActivityStatusChange("BlockingActivity", TestActivityInstanceState.Executing);
                testWorkflowRuntime.CancelWorkflow();
                // This test is not run on desktop and I don't think it would pass there if it did run.
                //testWorkflowRuntime.WaitForCompletion();
                testWorkflowRuntime.WaitForCanceled();
            }
        }
예제 #15
0
파일: TryCatch.cs 프로젝트: codeex/corewf
        public void PersistInCatch()
        {
            TestBlockingActivity blocking = new TestBlockingActivity("Bookmark");
            TestTryCatch         tcf      = new TestTryCatch
            {
                Try = new TestThrow <Exception>()
                {
                    ExpectedOutcome = Outcome.CaughtException()
                },
                Catches = { { new TestCatch <Exception> {
                                  Body = blocking
                              } } }
            };

            JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~");

            using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(tcf, null, jsonStore, PersistableIdleAction.None))
            {
                testWorkflowRuntime.ExecuteWorkflow();

                testWorkflowRuntime.WaitForActivityStatusChange(blocking.DisplayName, TestActivityInstanceState.Executing);

                testWorkflowRuntime.PersistWorkflow();

                testWorkflowRuntime.ResumeBookMark("Bookmark", null);

                testWorkflowRuntime.WaitForCompletion();
            }
        }
예제 #16
0
        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();
            }
        }
예제 #17
0
        private static string ExecuteWorkflowAndGetResult(Activity we, out Exception ex)
        {
            ex = null;

            using (StreamWriter streamWriter = ConsoleSetOut())
            {
                using (TestWorkflowRuntime twr = new TestWorkflowRuntime(new TestWrapActivity(we)))
                {
                    twr.ExecuteWorkflow();
                    try
                    {
                        twr.WaitForCompletion(false);
                    }
                    // Capture ApplicationException only, which is thrown by TestWorkflowRuntime
                    catch (Exception e) // jasonv - approved; specific, commented, returns exception
                    {
                        ex = e.InnerException;
                    }
                }
            }

            if (!File.Exists(s_path))
            {
                throw new FileNotFoundException();
            }

            string[] texts = File.ReadAllLines(s_path);

            return(string.Concat(texts));
        }
예제 #18
0
        public void PersistenceToWriteLineActivity()
        {
            TestProductWriteline writeLine1 = new TestProductWriteline("writeLine1")
            {
                TextExpressionActivity = new TestExpressionEvaluatorWithBody <string>()
                {
                    Body             = (new TestBlockingActivity("BlockingActivity")),
                    ExpressionResult = "This should be displayed after the bookmark"
                }
            };

            using (StreamWriter writer = new StreamWriter(new FileStream(_tempFilePath, FileMode.Create, FileAccess.Write)))
            {
                Console.SetOut(writer);

                TestBlockingActivity blocking = new TestBlockingActivity("BlockingActivity");

                JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~");

                using (TestWorkflowRuntime workflow = TestRuntime.CreateTestWorkflowRuntime(writeLine1, null, jsonStore, PersistableIdleAction.None))
                {
                    workflow.ExecuteWorkflow();
                    workflow.WaitForActivityStatusChange("BlockingActivity", TestActivityInstanceState.Executing);
                    workflow.PersistWorkflow();
                    workflow.ResumeBookMark("BlockingActivity", null);
                    workflow.WaitForCompletion();
                }
            }
        }
예제 #19
0
        public void PersistFlowchart()
        {
            TestFlowchart flowchart = new TestFlowchart();

            TestWriteLine writeLine1 = new TestWriteLine("hello1", "Hello1");
            TestWriteLine writeLine2 = new TestWriteLine("hello2", "Hello2");

            TestBlockingActivity blocking = new TestBlockingActivity("BlockingActivity");

            flowchart.AddStartLink(writeLine1);
            flowchart.AddLink(writeLine1, blocking);
            flowchart.AddLink(blocking, writeLine2);

            JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~");

            using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(flowchart, null, jsonStore, PersistableIdleAction.None))
            {
                testWorkflowRuntime.ExecuteWorkflow();
                testWorkflowRuntime.WaitForActivityStatusChange("BlockingActivity", TestActivityInstanceState.Executing);
                testWorkflowRuntime.PersistWorkflow();
                System.Threading.Thread.Sleep(2000);
                testWorkflowRuntime.ResumeBookMark("BlockingActivity", null);
                testWorkflowRuntime.WaitForCompletion();
            }
        }
예제 #20
0
 public static void ValidateWorkflowErrors(TestActivity testActivity, List <TestConstraintViolation> constraints, Type onOpenExceptionType, string onOpenExceptionString, ValidationSettings validatorSettings)
 {
     using (TestWorkflowRuntime testWorkflowRuntime = new TestWorkflowRuntime(testActivity))
     {
         ValidateConstraints(testActivity, constraints, validatorSettings);
         ValidateInstantiationException(testActivity, onOpenExceptionType, onOpenExceptionString);
     }
 }
예제 #21
0
 private static void RunAndValidateWorkflow(TestActivity testActivity, ExpectedTrace expectedTrace, List <TestConstraintViolation> constraints, ValidationSettings validatorSettings, bool runValidations, WorkflowIdentity definitionIdentity = null)
 {
     using (TestWorkflowRuntime testWorkflowRuntime = new TestWorkflowRuntime(testActivity, definitionIdentity))
     {
         testWorkflowRuntime.ExecuteWorkflow();
         testWorkflowRuntime.WaitForCompletion(expectedTrace);
     }
 }
예제 #22
0
        public void CustomActivityOverridesBranchCancelStateWithThrow()
        {
            const string triggerMessage = "Trigger branch's trigger is executing.";

            TestPick pick = new TestPick()
            {
                DisplayName = "PickActivity",
                Branches    =
                {
                    new TestPickBranch()
                    {
                        DisplayName = "TriggeredBranch_Branch",
                        Trigger     = new TestWriteLine("TriggeredBranch_Trigger")
                        {
                            Message     = triggerMessage,
                            HintMessage = triggerMessage,
                        },
                    },
                    new TestPickBranch()
                    {
                        DisplayName = "FaultedCustomActivity_Branch",
                        Trigger     = new TestBlockingActivityWithWriteLineInCancel("FaultedCustomActivity_Trigger", OutcomeState.Faulted)
                        {
                            ExpectedOutcome = Outcome.UncaughtException(),
                        },
                        Action = new TestWriteLine("FaultedCustomActivity_Action")
                        {
                            Message = "FaultedCustomActivity_Action - not supposed to show",
                        },
                    },
                }
            };

            // wrapping the custom activity with a try-catch doesn't work here
            // try-catch doesn't catch an exception that comes from a Cancel
            // by design in Beta2, any exception thrown from Cancel will Abort the workflow immediately
            // Note: for this test case (and similar ones e.g. Parallel), we can only compare the Exception type
            //       because this is a special case, we cannot validate the traces as exception is thrown from
            //       Cancel and by design runtime doesn't catch it. As a result, there is no chance to validate.
            using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(pick))
            {
                testWorkflowRuntime.ExecuteWorkflow();
                Exception outException = null;
                testWorkflowRuntime.WaitForAborted(out outException, false);
                // Due to how we get the tracking information, the exception is not the original exception and
                // we cannot check the InnerException property.
                Assert.NotNull(outException);
                //if (outException == null || outException.InnerException == null || !outException.InnerException.GetType().Equals(typeof(TestCaseException)))
                //{
                //    throw new TestCaseException(String.Format("Workflow was supposed to Abort with a TestCaseException, but this is the exception: {0}", outException.ToString()));
                //}
                //else
                //{
                //    //Log.Info("Workflow aborted as excpected");
                //}
            }
        }
예제 #23
0
        public void PersistWithinBranch()
        {
            TestParallel parallel = new TestParallel("Parallel Act")
            {
                Branches =
                {
                    new TestSequence("seq1")
                    {
                        Activities =
                        {
                            new TestBlockingActivity("Blocking activity 1")
                        }
                    },

                    new TestSequence("seq2")
                    {
                        Activities =
                        {
                            new TestBlockingActivity("Blocking activity 2")
                        }
                    },
                    new TestSequence("seq3")
                    {
                        Activities =
                        {
                            new TestBlockingActivity("Blocking activity 3")
                        }
                    },

                    new TestWriteLine("writeline after seq3")
                    {
                        Message = "HI"
                    }
                }
            };

            JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~");

            using (TestWorkflowRuntime runtime = TestRuntime.CreateTestWorkflowRuntime(parallel, null, jsonStore, PersistableIdleAction.None))
            {
                runtime.ExecuteWorkflow();
                runtime.WaitForActivityStatusChange("Blocking activity 1", TestActivityInstanceState.Executing);
                runtime.PersistWorkflow();
                runtime.ResumeBookMark("Blocking activity 1", null);

                runtime.WaitForActivityStatusChange("Blocking activity 2", TestActivityInstanceState.Executing);
                runtime.PersistWorkflow();
                runtime.ResumeBookMark("Blocking activity 2", null);

                runtime.WaitForActivityStatusChange("Blocking activity 3", TestActivityInstanceState.Executing);
                runtime.PersistWorkflow();
                runtime.ResumeBookMark("Blocking activity 3", null);

                runtime.WaitForCompletion();
            }
        }
예제 #24
0
        public void ParallelForEachWithAChildThatThrowsInCancelWhileCompletionConditionIsTrue()
        {
            Variable <bool> cancelIt = new Variable <bool> {
                Name = "cancelIt", Default = false
            };
            DelegateInArgument <bool> arg = new DelegateInArgument <bool>("arg");

            TestParallelForEach <bool> pfeAct = new TestParallelForEach <bool>
            {
                HintIterationCount          = 2,
                HintValues                  = new bool[] { true, false },
                ValuesExpression            = (e => new bool[] { true, false }),
                CurrentVariable             = arg,
                CompletionConditionVariable = cancelIt,
                Body = new TestIf(HintThenOrElse.Then, HintThenOrElse.Else)
                {
                    ConditionExpression = e => arg.Get(e),
                    ThenActivity        = new TestBlockingActivityWithWriteLineInCancel("writeLineInCancel", OutcomeState.Faulted)
                    {
                        ExpectedOutcome = Outcome.UncaughtException(typeof(TestCaseException)),
                    },
                    ElseActivity = new TestSequence
                    {
                        Activities =
                        {
                            new TestDelay("d1", new TimeSpan(1)),
                            new TestAssign <bool> {
                                Value = true,   ToVariable = cancelIt
                            }
                        }
                    }
                }
            };

            TestSequence root = new TestSequence
            {
                Activities = { pfeAct },
                Variables  = { cancelIt },
            };

            using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(root))
            {
                testWorkflowRuntime.ExecuteWorkflow();
                Exception outException = null;
                testWorkflowRuntime.WaitForAborted(out outException, false);
                if (outException == null || outException.InnerException == null || !outException.InnerException.GetType().Equals(typeof(TestCaseException)))
                {
                    throw new TestCaseException(String.Format("Workflow was suuposed to Abort with a TestCaseException, but this is the exception: {0}", outException.ToString()));
                }
                else
                {
                    //Log.Info("Workflow aborted as excpected");
                }
            }
        }
예제 #25
0
        public void PersistAfterCatchBeforeRethrow()
        {
            TestTryCatch root = new TestTryCatch("parent TryCatch")
            {
                Try = new TestSequence
                {
                    Activities =
                    {
                        new TestProductWriteline("W1"),
                        new TestThrow <TAC.ApplicationException>
                        {
                            ExceptionExpression = (context => new TAC.ApplicationException("abcd")),
                            ExpectedOutcome     = Outcome.CaughtException(typeof(TAC.ApplicationException)),
                        }
                    }
                },
                Catches =
                {
                    new TestCatch <TAC.ApplicationException>
                    {
                        Body = new TestSequence
                        {
                            Activities =
                            {
                                new TestBlockingActivity("Blocking1", "B1"),
                                new TestRethrow
                                {
                                    ExpectedOutcome = Outcome.UncaughtException(typeof(TAC.ApplicationException)),
                                }
                            }
                        }
                    }
                }
            };

            JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~");

            using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(root, null, jsonStore, CoreWf.PersistableIdleAction.None))
            {
                testWorkflowRuntime.ExecuteWorkflow();
                testWorkflowRuntime.WaitForActivityStatusChange("Blocking1", TestActivityInstanceState.Executing);
                testWorkflowRuntime.PersistWorkflow();
                testWorkflowRuntime.ResumeBookMark("Blocking1", null);

                Exception resultedException;
                testWorkflowRuntime.WaitForAborted(out resultedException);

                if (!(resultedException is TAC.ApplicationException))
                {
                    throw resultedException;
                }
            }
        }
예제 #26
0
        public static void RunAndValidateAbortedException(TestActivity activity, Type exceptionType, Dictionary <string, string> exceptionProperties)
        {
            using (TestWorkflowRuntime testWorkflowRuntime = new TestWorkflowRuntime(activity))
            {
                testWorkflowRuntime.ExecuteWorkflow();


                testWorkflowRuntime.WaitForAborted(out Exception exception, true);

                ExceptionHelpers.ValidateException(exception, exceptionType, exceptionProperties);
            }
        }
예제 #27
0
        public void ThreeBranchsOneTriggered()
        {
            TestPick pick = new TestPick()
            {
                DisplayName = "PickActivity",
                Branches    =
                {
                    new TestPickBranch()
                    {
                        DisplayName = "NoTriggeredBranch1",
                        Trigger     = new TestBlockingActivity("Block1")
                        {
                            ExpectedOutcome = Outcome.Canceled,
                        },
                        Action = new TestWriteLine("Action1")
                        {
                            Message = "Action1",
                        },
                    },
                    new TestPickBranch()
                    {
                        DisplayName = "TriggeredBranch",
                        Trigger     = new TestBlockingActivity("Block2"),
                        Action      = new TestWriteLine("Action2")
                        {
                            Message = "Action2",
                        },
                    },
                    new TestPickBranch()
                    {
                        DisplayName = "NoTriggeredBranch2",
                        Trigger     = new TestBlockingActivity("Block3")
                        {
                            ExpectedOutcome = Outcome.Canceled,
                        },
                        Action = new TestWriteLine("Action3")
                        {
                            Message = "Action3",
                        },
                    },
                }
            };

            using (TestWorkflowRuntime runtime = TestRuntime.CreateTestWorkflowRuntime(pick))
            {
                runtime.ExecuteWorkflow();
                runtime.WaitForActivityStatusChange("Block2", TestActivityInstanceState.Executing);
                System.Threading.Thread.Sleep(1000);
                runtime.ResumeBookMark("Block2", null);
                ExpectedTrace trace = pick.GetExpectedTrace();
                runtime.WaitForCompletion(trace);
            }
        }
예제 #28
0
        public void TryTerminatingActivityAfterThrowInTryCatch()
        {
            s_exceptionType     = typeof(InvalidCastException);
            s_terminationReason = "I like home!";

            TestTryCatch tryCatch = new TestTryCatch("TryCatch")
            {
                Try = new TestSequence("TryingSeq")
                {
                    Activities =
                    {
                        new TestWriteLine()
                        {
                            Message     = "I'm Trying here",
                            HintMessage = "I'm Trying here"
                        },
                        new TestThrow <ArgumentException>("TryException")
                        {
                            ExpectedOutcome = Outcome.CaughtException(),
                        },
                        new TestTerminateWorkflow()
                        {
                            ExceptionExpression = context => new InvalidCastException("I want to go home now!"),
                            Reason = s_terminationReason
                        }
                    }
                },
                Catches =
                {
                    new TestCatch <ArgumentException>()
                    {
                        Body = new TestWriteLine("CaughtException")
                        {
                            Message     = "aha I caught you!",
                            HintMessage = "aha I caught you!"
                        }
                    }
                },
                Finally = new TestWriteLine("Finally")
                {
                    Message     = "Ha! Now you have to stay",
                    HintMessage = "Ha! Now you have to stay"
                }
            };


            using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(tryCatch))
            {
                testWorkflowRuntime.OnWorkflowCompleted += new EventHandler <TestWorkflowCompletedEventArgs>(workflowCompletedNoExceptions);
                testWorkflowRuntime.ExecuteWorkflow();
                testWorkflowRuntime.WaitForCompletion();
            }
        }
예제 #29
0
        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!");
        }
예제 #30
0
 public static void PersistAndUpdate(this TestWorkflowRuntime twRuntime, WorkflowIdentity updatedIdentity)
 {
     twRuntime.PersistWorkflow();
     twRuntime.UnloadWorkflow();
     if (null != updatedIdentity)
     {
         twRuntime.LoadAndUpdateWorkflow(updatedIdentity.ToString());
     }
     else
     {
         twRuntime.LoadWorkflow();
     }
     twRuntime.ResumeWorkflow();
 }