Esempio n. 1
0
        public static void ModifyAndValidateException(TestActivity testActivity, Type exceptionType, string errorString)
        {
            string originalXaml = XamlTestDriver.Serialize(testActivity.ProductActivity);
            string modifiedXaml = testActivity.ModifyXamlDelegate(originalXaml);

            ExceptionHelpers.CheckForException(exceptionType, errorString, () => Deserialize(modifiedXaml));
        }
        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;
        }
Esempio n. 3
0
        public static void ValidateInstantiationException(TestActivity testActivity, Type exceptionType, string errorString)
        {
            Dictionary <string, string> exception = new Dictionary <string, string>();

            exception.Add("Message", errorString);
            ExceptionHelpers.CheckForException(
                exceptionType,
                exception,
                delegate
            {
                WorkflowApplication instance = new WorkflowApplication(testActivity.ProductActivity);
                instance.Extensions.Add(TestRuntime.TraceListenerExtension);
                instance.Run();
            },
                true);
        }
        private void GetBookMarksOnAbortedWorkflow(bool isDefaultTimeout)
        {
            const string traceToWaitMsg = "Continue WaitForTrace1";
            Sequence     sequence       = new Sequence()
            {
                Activities =
                {
                    new WaitForTrace()
                    {
                        DisplayName = "WaitForTrace1",
                        TraceToWait = new InArgument <string>(traceToWaitMsg)
                    },
                    new ReadLine <string>(bookMarkName_InvalidOperationsOnAbortedWorkflow)
                    {
                    }
                }
            };

            WorkflowApplication instance = new WorkflowApplication(sequence)
            {
                Aborted = OnWorkflowInstanceAborted
            };

            instance.Run();

            TestTraceManager.Instance.WaitForTrace(instance.Id, new SynchronizeTrace(WaitForTrace.EnterExecute), 1);
            instance.Abort();
            //Continue WaitForTrace. The instance should get aborted after WaitForTrace1 activity is done
            TestTraceManager.Instance.AddTrace(instance.Id, new SynchronizeTrace(traceToWaitMsg));
            SynchronizeTrace.Trace(instance.Id, traceToWaitMsg);

            TestTraceManager.Instance.WaitForTrace(instance.Id, new SynchronizeTrace(WorkflowInstanceAbortTests.AbortedHandlerCalled), 1);
            string message = String.Format(ExceptionStrings.WorkflowApplicationAborted, instance.Id);

            ExceptionHelpers.CheckForException(typeof(WorkflowApplicationAbortedException), message,
                                               delegate
            {
                if (isDefaultTimeout)
                {
                    instance.GetBookmarks();
                }
                else
                {
                    instance.GetBookmarks(TimeSpan.FromMilliseconds(1));
                }
            });
        }
        public static Activity <Location <TResult> > ConvertReference <TResult>(Expression <Func <ActivityContext, TResult> > expression, Exception expectedException)
        {
            Activity <Location <TResult> > result = null;

            if (expectedException != null)
            {
                ExceptionHelpers.CheckForException(
                    expectedException.GetType(), expectedException.Message,
                    () => { result = ExpressionServices.ConvertReference <TResult>(expression); }, true);
            }
            else
            {
                result = ExpressionServices.ConvertReference <TResult>(expression);
            }

            return(result);
        }
        private static readonly string s_path = string.Empty; //DirectoryAssistance.GetTestBinsDirectory("TempFile.txt");

        public static void ValidateExpressionXaml <T>(TestExpression te)
        {
            Activity expectedActivity = null, actualActivity = null;

            Expression <Func <ActivityContext, T> > lambdaExpression = null;

            lambdaExpression = (Expression <Func <ActivityContext, T> >)te.CreateLambdaExpresson <T>();
            //Log.TraceInternal("Expression: {0}", lambdaExpression.ToString());

            expectedActivity = te.CreateExpectedActivity() as Activity;

            if (te.ExpectedConversionException != null)
            {
                ExceptionHelpers.CheckForException(
                    te.ExpectedConversionException.GetType(), te.ExpectedConversionException.Message,
                    () => { actualActivity = ExpressionServices.Convert(lambdaExpression); }, true);
            }
            else
            {
                actualActivity = ExpressionServices.Convert(lambdaExpression);
                ValidateActivity(expectedActivity, actualActivity);
            }
        }
Esempio n. 7
0
        private static void TestInstanceOperationFromResumeBookmarkCallback(int operationsId, bool isSync)
        {
            var shouldNotExecuteMsg = "Should not see this message";
            var value           = VariableHelper.Create <int>("value");
            var writeLineNotRun = new TestWriteLine("NotExecuted", shouldNotExecuteMsg)
            {
            };
            var 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;
            }

            var 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;
            var message = "";

            //Execute Workflow
            var 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.
            var 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:
                {
                    workflowRuntime.WaitForTerminated(1, out var 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");
                }
            }
        }