Exemplo n.º 1
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);
        }
        private void CheckExceptionPropagated(ThrowFromInterfaceMethodsBase throwExceptionExtension, string exceptionMessage, TestWorkflowRuntime runtime)
        {
            throwExceptionExtension.ExceptionMessage = exceptionMessage;
            throwExceptionExtension.IsThrow          = true;

            runtime.Extensions.Add(throwExceptionExtension);
            ExceptionHelpers.CheckForException(typeof(Exception), throwExceptionExtension.ExceptionMessage, delegate
            {
                runtime.ResumeWorkflow();
            });
            throwExceptionExtension.IsThrow = false;
        }
Exemplo n.º 3
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!");
        }
Exemplo n.º 4
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();
 }
        public void CheckWorkflowProperties()
        {
            TestActivity workflow = new TestWriteLine("Write1", "Write a line");

            TestWorkflowRuntime runtime = TestRuntime.CreateTestWorkflowRuntime(workflow);

            runtime.CreateWorkflow();
            runtime.Extensions.Add(new CheckWorkflowPropertiesExtension(runtime.CurrentWorkflowInstanceId, workflow.ProductActivity));

            runtime.ResumeWorkflow();
            ExpectedTrace expectedTrace = workflow.GetExpectedTrace();

            expectedTrace.AddIgnoreTypes(typeof(UserTrace));
            runtime.WaitForCompletion(expectedTrace);
        }
        public void TryResumingTerminatedInstanceWithoutPersistence()
        {
            //TestParameters.SetParameter("PersistenceProviderFactoryType", "NoPP");

            s_exceptionType     = typeof(TAC.ApplicationException);
            s_exceptionMsg      = "I am throwing this Exception";
            s_terminationReason = "Terminating Now!";

            TestSequence seq = new TestSequence("Executing")
            {
                Activities =
                {
                    new TestWriteLine("AboutToTerminate")
                    {
                        Message     = "Terminating Soon!",
                        HintMessage = "Terminating Soon!"
                    },
                    new TestTerminateWorkflow("Terminating")
                    {
                        ExceptionExpression = ((env) => new TAC.ApplicationException("I am throwing this Exception")),
                        Reason = s_terminationReason
                    }
                },
            };

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

                try
                {
                    testWorkflowRuntime.ResumeWorkflow();
                    throw new TestCaseFailedException("Should not be able to resume the instance");
                }
                catch (Exception e)
                {
                    ExceptionHelpers.ValidateException(e, (typeof(WorkflowApplicationTerminatedException)), null);
                }
            }

            //TestParameters.SetParameter("PersistenceProviderFactoryType", "SQLPP");
        }
        public void ThrowFromInterfaceMethods()
        {
            TestActivity workflow = new TestWriteLine("Write1", "Write a line");

            TestWorkflowRuntime runtime = TestRuntime.CreateTestWorkflowRuntime(workflow);

            runtime.PersistenceProviderFactoryType = null;
            runtime.CreateWorkflow();

            ThrowFromAdditionalExtensions throwFromAdditionalExtensions = new ThrowFromAdditionalExtensions();

            CheckExceptionPropagated(throwFromAdditionalExtensions, "Throw from AdditionalExtensionsAdded", runtime);

            ThrowFromSetInstance throwFromSetInstance = new ThrowFromSetInstance();

            CheckExceptionPropagated(throwFromSetInstance, "Throw from SetInstance", runtime);

            runtime.ResumeWorkflow();
            ExpectedTrace expectedTrace = workflow.GetExpectedTrace();

            expectedTrace.AddIgnoreTypes(typeof(UserTrace));
            runtime.WaitForCompletion(expectedTrace);
        }
        public void VerifyAdditionalExtensionsAdded()
        {
            TestActivity        workflow = new TestReadLine <int>("Read1", "Read1");
            TestWorkflowRuntime runtime  = TestRuntime.CreateTestWorkflowRuntime(workflow);

            runtime.OnWorkflowUnloaded += WorkflowInstanceHelper.wfRuntime_OnUnload;
            runtime.CreateWorkflow();
            runtime.Extensions.Add(new AdditionalExtensionsAdded(new Collection <object>()
            {
                new OperationOrderTracePersistExtension(runtime.CurrentWorkflowInstanceId)
            }));

            runtime.ResumeWorkflow();
            runtime.WaitForIdle();
            runtime.ResumeBookMark("Read1", 1);

            ExpectedTrace expectedTrace = workflow.GetExpectedTrace();

            expectedTrace.AddIgnoreTypes(typeof(UserTrace));
            runtime.WaitForCompletion(expectedTrace);
            runtime.WaitForTrace(new UserTrace(WorkflowInstanceHelper.UnloadMessage));
            runtime.WaitForTrace(new UserTrace(OperationOrderTracePersistExtension.TraceSave));
        }
Exemplo n.º 9
0
        public void SetTextWriterToNullAndUseATextWriterExtension()
        {
            string stringToWrite = "Writing text to  a file with StreamWriter object";

            using (StreamWriter streamWriter = new StreamWriter(new FileStream(_tempFilePath, FileMode.Create, FileAccess.Write)))
            {
                TestProductWriteline writeline = new TestProductWriteline("Write with StreamWriter")
                {
                    Text = stringToWrite,
                };
                writeline.ProductWriteLine.TextWriter = null;

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

            VerifyTextOfWriteLine(_tempFilePath, stringToWrite);
        }
        public static void TestResumeWithDelay()
        {
            var testSequence = new TestSequence()
            {
                Activities =
                {
                    new TestDelay()
                    {
                        Duration = TimeSpan.FromMilliseconds(100)
                    },
                }
            };

            JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~");
            TestWorkflowRuntime workflowRuntime = TestRuntime.CreateTestWorkflowRuntime(testSequence, null, jsonStore, PersistableIdleAction.Unload);

            workflowRuntime.ExecuteWorkflow();
            workflowRuntime.PersistWorkflow();
            workflowRuntime.WaitForUnloaded();
            workflowRuntime.LoadWorkflow();
            workflowRuntime.ResumeWorkflow();
            workflowRuntime.WaitForCompletion(false);
        }
Exemplo n.º 11
0
        private static void TestInstanceOperationFromResumeBookmarkCallback(int operationsId, bool isSync)
        {
            string         shouldNotExecuteMsg = "Should not see this message";
            Variable <int> value           = VariableHelper.Create <int>("value");
            TestWriteLine  writeLineNotRun = new TestWriteLine("NotExecuted", shouldNotExecuteMsg)
            {
            };
            TestSequence testSequence = new TestSequence()
            {
                Variables  = { value },
                Activities =
                {
                    new TestWriteLine()
                    {
                        Message = "Workflow Started"
                    },
                    new TestWaitReadLine <int>("Read", "Read")
                    {
                        BookmarkValue = value
                    },
                }
            };

            //Get Expected Trace without TestWriteLine()
            if (operationsId == 2)
            {
                testSequence.ExpectedOutcome = Outcome.Canceled;
            }

            ExpectedTrace expectedTrace = testSequence.GetExpectedTrace();

            if (operationsId == 4)
            {
                expectedTrace.Trace.Steps.RemoveAt(expectedTrace.Trace.Steps.Count - 1);
            }
            else if (operationsId == 3)
            {
                expectedTrace.Trace.Steps.RemoveAt(expectedTrace.Trace.Steps.Count - 1);
                expectedTrace.Trace.Steps.Add(new ActivityTrace(testSequence.DisplayName, ActivityInstanceState.Faulted));
            }


            //Now Add TestWriteLine to workflow
            testSequence.Activities.Add(writeLineNotRun);

            TestWorkflowRuntimeAsyncResult asyncResultResume    = null;
            TestWorkflowRuntimeAsyncResult asyncResultOperation = null;
            string message = "";

            //Execute Workflow
            JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~");
            // using PersistableIdleAction.None here because the idle unload was racing with the resume bookmark after the wait for the BeforeWait trace.
            TestWorkflowRuntime workflowRuntime = TestRuntime.CreateTestWorkflowRuntime(testSequence, null, jsonStore, PersistableIdleAction.None);

            workflowRuntime.ExecuteWorkflow();
            workflowRuntime.WaitForActivityStatusChange("Read", TestActivityInstanceState.Executing);
            if (isSync)
            {
                //Log.Info("Resuming Bookmark");
                if (isSync)
                {
                    workflowRuntime.ResumeBookMark("Read", 9999);
                }
                else
                {
                    asyncResultResume = workflowRuntime.BeginResumeBookMark("Read", 9999, null, null);
                }

                workflowRuntime.WaitForTrace(new UserTrace(WaitReadLine <int> .BeforeWait));
                switch (operationsId)
                {
                case 2:
                    //Cancel Workflow during OnResumeBookmark is executing
                    //Log.Info("CancelWorkflow during OnResumeBookmark executing");
                    if (isSync)
                    {
                        workflowRuntime.CancelWorkflow();
                    }
                    else
                    {
                        asyncResultOperation = workflowRuntime.BeginCancelWorkflow(null, null);

                        workflowRuntime.EndResumeBookMark(asyncResultResume);
                        workflowRuntime.EndCancelWorkflow(asyncResultOperation);
                    }
                    //Trace.WriteLine should not execute
                    break;

                case 3:
                    //Terminate Workflow during OnResumeBookmark is executing
                    //Log.Info("TerminateWorkflow during OnResumeBookmark executing");
                    if (isSync)
                    {
                        workflowRuntime.TerminateWorkflow("Terminate Exception");
                    }
                    else
                    {
                        asyncResultOperation = workflowRuntime.BeginTerminateWorkflow("Terminate Exception", null, null);

                        workflowRuntime.EndResumeBookMark(asyncResultResume);
                        workflowRuntime.EndTerminateWorkflow(asyncResultOperation);
                    }
                    //Trace.WriteLine should not execute.
                    break;

                case 4:
                    //Unload Workflow during OnResumeBookmark is executing
                    //This should wait till ResumeMark finishes the work
                    //Log.Info("UnloadWorkflow during OnResumeBookmark executing");
                    if (isSync)
                    {
                        workflowRuntime.UnloadWorkflow();
                    }
                    else
                    {
                        asyncResultOperation = workflowRuntime.BeginUnloadWorkflow(null, null);

                        workflowRuntime.EndResumeBookMark(asyncResultResume);
                        workflowRuntime.EndUnloadWorkflow(asyncResultOperation);
                    }

                    //message = String.Format(ExceptionStrings.WorkflowInstanceUnloaded, workflowRuntime.CurrentWorkflowInstanceId);
                    ExceptionHelpers.CheckForException(typeof(WorkflowApplicationUnloadedException), message, new ExceptionHelpers.MethodDelegate(
                                                           delegate
                    {
                        workflowRuntime.ResumeWorkflow();
                    }));

                    break;
                }
            }

            if (isSync)
            {
                switch (operationsId)
                {
                case 2:
                {
                    workflowRuntime.WaitForCanceled(expectedTrace);
                    break;
                }

                case 3:
                {
                    Exception terminationException;
                    workflowRuntime.WaitForTerminated(1, out terminationException, expectedTrace);
                    break;
                }

                case 4:
                {
                    // We tried to do a ResumeWorkflow without loading it after an unload, so we expected
                    // to get a WorkflowApplicationUnloadedException. The workflow will never complete,
                    // so don't wait for it to complete.
                    break;
                }
                }
            }
            else
            {
                //Give some time for Workflow to execute
                Thread.CurrentThread.Join((int)TimeSpan.FromSeconds(1).TotalMilliseconds);
            }

            if (isSync)
            {
                expectedTrace.AddIgnoreTypes(typeof(WorkflowInstanceTrace));
                workflowRuntime.ActualTrace.Validate(expectedTrace);
            }
            else
            {
                //The traces are vary in the async situations, thus we can not do a full trace valdation
                //validate the writeline after read activity is not executed is sufficient
                if (workflowRuntime.ActualTrace.ToString().Contains(shouldNotExecuteMsg))
                {
                    throw new Exception("The NotExecuted WriteLine activity has been executed, the expectation is it does not");
                }
            }
        }
Exemplo n.º 12
0
        public void DelayPersisted()
        {
            Variable <int>       counter  = new Variable <int>("Counter", 0);
            TestBlockingActivity blocking = new TestBlockingActivity("B");

            TestSequence seq = new TestSequence
            {
                Activities =
                {
                    new TestWriteLine("Before")
                    {
                        Message = "Before"
                    },
                    new TestDelay()
                    {
                        Duration = TimeSpan.FromSeconds(1)
                    },
                    new TestWriteLine("After")
                    {
                        Message = "After"
                    }
                }
            };

            TestSequence seq2 = new TestSequence
            {
                Activities =
                {
                    new TestWriteLine("Before")
                    {
                        Message = "Before"
                    },
                    new TestDelay()
                    {
                        Duration = TimeSpan.FromSeconds(1)
                    },
                    new TestWriteLine("After")
                    {
                        Message = "After"
                    }
                }
            };


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

            var instanceHandle = jsonStore.CreateInstanceHandle();
            var instanceView   = jsonStore.Execute(instanceHandle, new CreateWorkflowOwnerCommand(), TimeSpan.MaxValue);
            var instanceOwner  = instanceView.InstanceOwner;

            jsonStore.DefaultInstanceOwner = instanceOwner;

            //Guid id;
            using (TestWorkflowRuntime runtime =
                       TestRuntime.CreateTestWorkflowRuntime(seq, null, jsonStore, PersistableIdleAction.Unload))
            {
                runtime.ExecuteWorkflow();

                runtime.WaitForUnloaded();

                //id = runtime.CurrentWorkflowInstanceId;

                Thread.Sleep(TimeSpan.FromSeconds(2));

                //runtime.InitiateWorkflowForLoad();
                //runtime.LoadRunnableInitiatedWorkflowForInstance(/*TimeSpan.Zero, id*/);
                runtime.LoadRunnableWorkflow();

                runtime.ResumeWorkflow();

                runtime.WaitForCompletion();
            }
        }