Beispiel #1
0
        private static ExpectedTrace RemovePlaceholderTrace(ExpectedTrace expectedTrace)
        {
            ExpectedTrace modifiedTrace = new ExpectedTrace(expectedTrace);
            int           count         = modifiedTrace.Trace.Steps.Count;

            for (int i = 0; i < count; i++)
            {
                WorkflowTraceStep workflowTraceStep = expectedTrace.Trace.Steps[i];
                if (workflowTraceStep is IPlaceholderTraceProvider)
                {
                    modifiedTrace.Trace.Steps[i] = ((IPlaceholderTraceProvider)workflowTraceStep).GetPlaceholderTrace();
                    continue;
                }
                else if (workflowTraceStep is TraceGroup)
                {
                    ExpectedTrace tempExpectedTrace = new ExpectedTrace
                    {
                        Trace = TraceGroup.GetNewTraceGroup((TraceGroup)workflowTraceStep)
                    };

                    modifiedTrace.Trace.Steps.RemoveAt(i);

                    ExpectedTrace cleanedUpExpectedTrace = TrackingFilter.RemovePlaceholderTrace(tempExpectedTrace);

                    //add only if it is non-empty
                    modifiedTrace.Trace.Steps.Insert(i, cleanedUpExpectedTrace.Trace);
                }
            }
            return(modifiedTrace);
        }
Beispiel #2
0
        public void VariableScopingTest()
        {
            DelegateInArgument <string> _currentVariable = new DelegateInArgument <string>()
            {
                Name = "_currentVariable"
            };

            TestParallelForEach <string> parallelForEach = new TestParallelForEach <string>("ParallelForEach")
            {
                CurrentVariable  = _currentVariable,
                HintValues       = new string[] { "Hello", "How", "Are", "You" },
                ValuesExpression = (context => new string[] { "Hello", "How", "Are", "You" }),
                Body             = new TestParallelForEach <string>("Inner Parallel For Each")
                {
                    HintValues       = new string[] { "Take" },
                    ValuesExpression = (context => new string[] { "Take" }),
                    Body             = new TestWriteLine("Writeline")
                    {
                        MessageExpression = (env) => (string)_currentVariable.Get(env),
                        HintMessageList   = { "You", "Are", "How", "Hello" }
                    }
                }
            };

            ExpectedTrace tr = parallelForEach.GetExpectedTrace();

            TestRuntime.RunAndValidateWorkflow(parallelForEach, tr);
        }
Beispiel #3
0
        public static void ValidateWorkflow(Guid workflowInstanceId, TestActivity testWorkflowDefinition)
        {
            ActualTrace   actualTrace   = TestTraceManager.Instance.GetInstanceActualTrace(workflowInstanceId);
            ExpectedTrace expectedTrace = testWorkflowDefinition.GetExpectedTrace();

            actualTrace.Validate(testWorkflowDefinition.GetExpectedTrace());
        }
        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);
            }
        }
Beispiel #5
0
        public static void ValidateTracking(ExpectedTrace expectedTrace, ActualTrace actualTrace, TrackingProfile profile, TestProfileType profileType, TrackingParticipantType participantType)
        {
            //1. Filter the expected trace against the workFlow profile
            ExpectedTrace filteredExpectedTrace = TrackingFilter.ApplyTrackingProfile(expectedTrace, profile);

            ////2. Delete not supported trace steps by testObjects.
            ActualTrace modifiedActualTrace = TrackingFilter.DeleteNotSupportedTraceSteps(actualTrace);

            TestTraceManager.OptionalLogTrace("[TestTrackingDataManager]*****ValidateTracking()");
            ////3. Validate the expected & the actual trace
            TestTraceManager.OptionalLogTrace("[TestTrackingDataManager]Profile = {0}", profile);
            TestTraceManager.OptionalLogTrace("[TestTrackingDataManager]Actual Trace = {0}", actualTrace);
            TestTraceManager.OptionalLogTrace("[TestTrackingDataManager]Expected Trace = {0}", expectedTrace);
            TestTraceManager.OptionalLogTrace("[TestTrackingDataManager]Filtered Expected Trace (after applying tracking profile) = {0}", filteredExpectedTrace);
            TestTraceManager.OptionalLogTrace("[TestTrackingDataManager]Modified ActualTrace Trace = {0}", modifiedActualTrace);
            TestTraceManager.OptionalLogTrace("[TestTrackingDataManager]Invoking internally the trace validation...");

            ////if (!(TestProfileProvider.IsAllOrNullProfile(profileType) &&
            if (((participantType != TrackingParticipantType.SqlTrackingParticipant) &&
                 (participantType != TrackingParticipantType.ETWTrackingParticipant)))
            {
                modifiedActualTrace.Validate(filteredExpectedTrace, TestTraceManager.IsDefaultTrackingConfiguration);
            }

            //Log.TraceInternal("[TestTrackingDataManager]*****Validate method Succeeded...");
        }
Beispiel #6
0
        public void ParallelForEachInTryCatchFinally()
        {
            TestTryCatch tcf = new TestTryCatch("TCF")
            {
                Try = new TestParallelForEach <string>("Parallel for each")
                {
                    Body = new TestThrow <InvalidCastException>
                    {
                        ExpectedOutcome = Outcome.CaughtException(typeof(InvalidCastException))
                    },
                    HintValues = new List <string>()
                    {
                        "str1", "STR2", "str3"
                    },
                    ValuesExpression    = (context => new List <string>()
                    {
                        "str1", "STR2", "str3"
                    }),
                    CompletionCondition = true,
                    HintIterationCount  = 1,
                },
                Catches =
                {
                    new TestCatch <InvalidCastException>()
                    {
                        HintHandleException = true
                    }
                }
            };

            ExpectedTrace tr = tcf.GetExpectedTrace();

            TestRuntime.RunAndValidateWorkflow(tcf, tr);
        }
Beispiel #7
0
        public override ExpectedTrace GetExpectedTrace()
        {
            this.ResetForValidation();

            OrderedTraces orderedTrace = new OrderedTraces();
            Outcome       outcome      = _activity.GetTrace(orderedTrace);
            ExpectedTrace baseTrace    = new ExpectedTrace(orderedTrace);

            baseTrace.AddIgnoreTypes(typeof(WorkflowExceptionTrace));
            baseTrace.AddIgnoreTypes(typeof(WorkflowAbortedTrace));
            baseTrace.AddIgnoreTypes(typeof(SynchronizeTrace));
            baseTrace.AddIgnoreTypes(typeof(BookmarkResumptionTrace));

            bool compensate = outcome.DefaultPropogationState != OutcomeState.Completed;

            foreach (Directive directive in this.CompensationHint)
            {
                TestActivity target = _activity.FindChildActivity(directive.Name);

                if (compensate)
                {
                    target.GetCompensationTrace(baseTrace.Trace);
                }
                else
                {
                    target.GetConfirmationTrace(baseTrace.Trace);
                }
            }

            return(baseTrace);
        }
        internal void ValidateTrackingAndTracing(ExpectedTrace expectedTrace, ExpectedTrace expectedWorkflowInstanceTrace)
        {
            //The expected trace may get modified in the validateTraces method. Hence make a copy to be prior to tracking validation.
            //We are merging two sets of traces
            //1) the traces generated by activities
            //2) the traces generated by workflowinstance method calls
            UnorderedTraces mergedTrace = new UnorderedTraces();

            mergedTrace.Steps.Add(expectedTrace.Trace);
            if (expectedWorkflowInstanceTrace != null)
            {
                mergedTrace.Steps.Add(expectedWorkflowInstanceTrace.Trace);
            }

            ExpectedTrace expectedMergedTrace = new ExpectedTrace(expectedTrace)
            {
                Trace = mergedTrace
            };

            ValidateTracking(expectedTrace);

            //Log.TraceInternal("[TestWorkflowRuntime]***Validate Tracing...");

            ValidateTraces(expectedMergedTrace, GetActualTrace());
        }
Beispiel #9
0
        private static ExpectedTrace NormalizeTrace(ExpectedTrace expectedTrace)
        {
            ExpectedTrace tempTrace = new ExpectedTrace(expectedTrace);

            TraceValidator.NormalizeExpectedTrace(tempTrace.Trace);

            return(tempTrace);
        }
Beispiel #10
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);
     }
 }
Beispiel #11
0
 private void AddIgnoreTypes(ExpectedTrace expected)
 {
     // always ignore WorkflowInstanceTraces
     expected.AddIgnoreTypes(typeof(WorkflowExceptionTrace));
     expected.AddIgnoreTypes(typeof(WorkflowAbortedTrace));
     expected.AddIgnoreTypes(typeof(SynchronizeTrace));
     expected.AddIgnoreTypes(typeof(BookmarkResumptionTrace));
 }
Beispiel #12
0
        public void SameVariableNameNest()
        {
            //TestParameters.DisableXamlRoundTrip = true;
            Variable <string> var1 = VariableHelper.CreateInitialized <string>("var1", "Variable in Pick");
            Variable <string> var2 = VariableHelper.CreateInitialized <string>("var1", "Variable in Branch1");

            TestSequence seq = new TestSequence("TestSeq")
            {
                Variables =
                {
                    var1
                },
                Activities =
                {
                    new TestPick()
                    {
                        DisplayName = "Pick",

                        Branches =
                        {
                            new TestPickBranch()
                            {
                                DisplayName = "Branch1",
                                Variables   =
                                {
                                    var2
                                },
                                Trigger = new TestDelay()
                                {
                                    Duration = new TimeSpan(0, 0, 3)
                                },
                                Action = new TestWriteLine("Action1")
                                {
                                    HintMessage       = "Variable in Branch1",
                                    MessageExpression = (env) => var2.Get(env)
                                }
                            },
                            new TestPickBranch()
                            {
                                DisplayName = "Branch2",
                                Trigger     = new TestBlockingActivity("Block2")
                                {
                                    ExpectedOutcome = Outcome.Canceled
                                },
                                Action = new TestWriteLine("Action2")
                                {
                                    Message = "Action2"
                                }
                            },
                        }
                    }
                }
            };

            ExpectedTrace trace = seq.GetExpectedTrace();

            TestRuntime.RunAndValidateWorkflow(seq, trace);
        }
Beispiel #13
0
        public void CancellationScopeInPick()
        {
            // CancellationScope does not have test OM
            CancellationScope cancel = new CancellationScope()
            {
                DisplayName = "TestCancellationScope",
                Body        = new TestSequence()
                {
                    Activities =
                    {
                        new TestDelay("LongDelay", new TimeSpan(0, 0, 5))
                    }
                }.ProductActivity,
                              CancellationHandler = new TestSequence()
                {
                    Activities =
                    {
                        new TestWriteLine()
                        {
                            Message = "Cancelled"
                        }
                    }
                }.ProductActivity
            };

            TestCustomActivity testCancel = TestCustomActivity <CancellationScope> .CreateFromProduct(cancel);

            testCancel.ActivitySpecificTraces.Add(
                new UnorderedTraces()
            {
                Steps =
                {
                    new UserTrace("Cancelled"),
                }
            });

            TestPick pick = new TestPick()
            {
                Branches =
                {
                    new TestPickBranch()
                    {
                        Trigger = new TestDelay("ShortDelay", new TimeSpan(0, 0, 1))
                    },
                    new TestPickBranch()
                    {
                        Trigger = testCancel
                    }
                }
            };

            ExpectedTrace expectedTrace = pick.GetExpectedTrace();

            expectedTrace.AddVerifyTypes(typeof(UserTrace));

            TestRuntime.RunAndValidateWorkflow(pick, expectedTrace);
        }
Beispiel #14
0
        public void ExecuteTogether()
        {
            Variable <int> var1 = VariableHelper.CreateInitialized <int>("var1", 1);

            TestPick pick = new TestPick()
            {
                DisplayName = "PickActivity",
                Branches    =
                {
                    new TestPickBranch()
                    {
                        Variables =
                        {
                            var1
                        },
                        DisplayName = "TriggeredBranch1",
                        Trigger     = new TestSequence
                        {
                            Activities =
                            {
                                new TestDelay()
                                {
                                    Duration = new TimeSpan(0, 0, 1)
                                },
                                new TestAssign <int>()
                                {
                                    ToVariable      = var1,
                                    ValueExpression = (env) => (var1.Get(env) + 1),
                                }
                            }
                        },
                        Action = new TestWriteLine("Action1")
                        {
                            HintMessage       = "2",
                            MessageExpression = ((env) => (var1.Get(env).ToString()))
                        },
                    },
                    new TestPickBranch()
                    {
                        DisplayName = "NoTriggeredBranch2",
                        Trigger     = new TestBlockingActivity("Block")
                        {
                            ExpectedOutcome = Outcome.Canceled,
                        },
                        Action = new TestWriteLine("Action2")
                        {
                            Message = "Action2",
                        },
                    }
                }
            };

            ExpectedTrace trace = pick.GetExpectedTrace();

            TestRuntime.RunAndValidateWorkflow(pick, trace);
            TestRuntime.RunAndValidateWorkflow(pick, trace);
        }
Beispiel #15
0
        public void ParallelForEachInLoop()
        {
            //TestParameters.DisableXamlRoundTrip = true;
            List <string> list1 = new List <string>()
            {
                "Item11", "Item12", "Item13"
            };
            List <string> list2 = new List <string>()
            {
                "Item21", "Item22", "Item23"
            };
            List <List <string> > lists = new List <List <string> >();

            lists.Add(list1);
            lists.Add(list2);

            DelegateInArgument <List <string> > listVar = new DelegateInArgument <List <string> >()
            {
                Name = "listVar"
            };
            DelegateInArgument <string> _currentVariable = new DelegateInArgument <string>()
            {
                Name = "_currentVariable"
            };

            TestSequence seq = new TestSequence("Outer Seq")
            {
                Activities =
                {
                    new TestForEach <List <string> >("For Each in Outer Seq")
                    {
                        ValuesExpression = (context => lists),
                        CurrentVariable  = listVar,

                        Body = new TestParallelForEach <string>("Parallel For Each")
                        {
                            CurrentVariable = _currentVariable,
                            Body            = new TestWriteLine("Writeline in for each")
                            {
                                MessageExpression = (env) => (string)_currentVariable.Get(env),
                                HintMessageList   = { "Item13", "Item12", "Item11", "Item23", "Item22", "Item21" }
                            },
                            HintValues         = list1, // This is a hack to let the tracing know about the number of values inside ValuesExpression.
                            ValuesExpression   = context => listVar.Get(context),
                            HintIterationCount = 3
                        },

                        HintIterationCount = 2
                    }
                }
            };

            ExpectedTrace tr = seq.GetExpectedTrace();

            TestRuntime.RunAndValidateWorkflow(seq, tr);
        }
        internal void ValidateTrackingAndTracing(ExpectedTrace expectedTrace)
        {
            expectedTrace.AddIgnoreTypes(false, typeof(WorkflowInstanceTrace));
            //The expected trace may get modified in the validateTraces method. Hence make a copy to be userd for tracking validation.
            ExpectedTrace copyOfExpectedTrace = new ExpectedTrace(expectedTrace);

            ValidateTracking(copyOfExpectedTrace);
            //Log.TraceInternal("[TestTracingWatcher]Validate Tracing...");
            ValidateTraces(expectedTrace, GetActualTrace());
        }
Beispiel #17
0
        public void ExecuteParallel()
        {
            TestPick pick = new TestPick()
            {
                DisplayName = "PickActivity",
                Branches    =
                {
                    new TestPickBranch()
                    {
                        DisplayName = "TriggeredBranch1",
                        Trigger     = new TestDelay()
                        {
                            Duration = new TimeSpan(0, 0, 1)
                        },
                        Action = new TestWriteLine("Action1")
                        {
                            Message = "Action1",
                        },
                    },
                    new TestPickBranch()
                    {
                        DisplayName = "NoTriggeredBranch2",
                        Trigger     = new TestDelay()
                        {
                            ExpectedOutcome = Outcome.Canceled,
                            Duration        = new TimeSpan(0, 0, 2)
                        },
                        Action = new TestWriteLine("Action2")
                        {
                            Message = "Action2",
                        },
                    }
                }
            };

            List <string> values = new List <string> {
                "a", "b"
            };
            TestParallelForEach <string> testPFE = new TestParallelForEach <string>()
            {
                Body                = pick,
                HintValues          = values,
                ValuesExpression    = (context => new List <string> {
                    "a", "b"
                }),
                CompletionCondition = false,
            };

            ExpectedTrace expected = testPFE.GetExpectedTrace();

            expected.AddVerifyTypes(typeof(UserTrace));

            TestRuntime.RunAndValidateWorkflow(testPFE, expected);
        }
Beispiel #18
0
        public void ImmediatelyCompleteTriggers()
        {
            TestPick pick = new TestPick()
            {
                DisplayName = "PickActivity",
                Branches    =
                {
                    new TestPickBranch()
                    {
                        DisplayName = "TriggeredBranch1",
                        Trigger     = new TestWriteLine("Trigger1")
                        {
                            Message = "Trigger1 Executing",
                        },
                        Action = new TestWriteLine("Action1")
                        {
                            Message = "Action1",
                        },
                    },
                    new TestPickBranch()
                    {
                        DisplayName     = "NoTriggeredBranch2",
                        ExpectedOutcome = Outcome.Canceled,
                        Trigger         = new TestWriteLine("Trigger2")
                        {
                            Message         = "Trigger2 Executing",
                            ExpectedOutcome = Outcome.Completed,
                        },
                        Action = new TestWriteLine("Action2")
                        {
                            Message = "Action2",
                        },
                    },
                    new TestPickBranch()
                    {
                        DisplayName     = "NoTriggeredBranch3",
                        ExpectedOutcome = Outcome.Canceled,
                        Trigger         = new TestWriteLine("Trigger3")
                        {
                            Message         = "Trigger3 Executing",
                            ExpectedOutcome = Outcome.Completed,
                        },
                        Action = new TestWriteLine("Action3")
                        {
                            Message = "Action3",
                        },
                    },
                }
            };

            ExpectedTrace trace = pick.GetExpectedTrace();

            TestRuntime.RunAndValidateWorkflow(pick, trace);
        }
Beispiel #19
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);
            }
        }
Beispiel #20
0
        public virtual ExpectedTrace GetExpectedTrace()
        {
            this.ResetForValidation();

            OrderedTraces orderedTrace = new OrderedTraces();

            GetTrace(orderedTrace);
            ExpectedTrace expected = new ExpectedTrace(orderedTrace);

            AddIgnoreTypes(expected);
            return(expected);
        }
Beispiel #21
0
        //[HostWorkflowAsWebService]
        public void DelayDoesNotBlockOtherExecution()
        {
            // In this scenario, I use "delayed" variable to make sure the Delay activity was not a blocking one
            // This is verified, by setting the "delayed" variable after Delay activity is done.

            DelegateInArgument <string> currentVariable = new DelegateInArgument <string>()
            {
                Name = "currentVariable"
            };
            Variable <bool> delayed = VariableHelper.CreateInitialized <bool>("delayed", false);
            TimeSpan        sec     = new TimeSpan(0, 0, 0, 0, 1);


            TestParallelForEach <string> parallelForEach = new TestParallelForEach <string>("PFE")
            {
                CurrentVariable = currentVariable,
                Body            = new TestSequence("BodyOfParallel")
                {
                    Variables  = { delayed },
                    Activities =
                    {
                        new TestIf("If condition", HintThenOrElse.Then, HintThenOrElse.Then)
                        {
                            ConditionExpression = ((env) => !delayed.Get(env)),
                            ThenActivity        = new TestSequence("Body of If")
                            {
                                Activities =
                                {
                                    new TestDelay()
                                    {
                                        Duration = sec
                                    },
                                    new TestAssign <bool>
                                    {
                                        Value      = true,
                                        ToVariable = delayed
                                    }
                                },
                            },
                        },
                    }
                },

                HintValues         = new string[] { "a", "b" },
                ValuesExpression   = (context => new string[] { "a", "b" }),
                HintIterationCount = 2
            };

            ExpectedTrace trace = parallelForEach.GetExpectedTrace();

            TestRuntime.RunAndValidateWorkflow(parallelForEach, trace);
        }
Beispiel #22
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!");
        }
Beispiel #23
0
        public void SameVariableName()
        {
            Variable <string> var1 = VariableHelper.CreateInitialized <string>("var1", "Variable in Branch1");
            Variable <string> var2 = VariableHelper.CreateInitialized <string>("var1", "Variable in Branch2");

            TestPick pick = new TestPick()
            {
                DisplayName = "Pick",
                Branches    =
                {
                    new TestPickBranch()
                    {
                        DisplayName = "Branch1",
                        Variables   =
                        {
                            var1
                        },
                        Trigger = new TestDelay()
                        {
                            Duration = new TimeSpan(0, 0, 3)
                        },
                        Action = new TestWriteLine("Action1")
                        {
                            HintMessage       = "Variable in Branch1",
                            MessageExpression = (env) => var1.Get(env)
                        }
                    },
                    new TestPickBranch()
                    {
                        DisplayName = "Branch2",
                        Variables   =
                        {
                            var2
                        },
                        Trigger = new TestBlockingActivity("Block2")
                        {
                            ExpectedOutcome = Outcome.Canceled
                        },
                        Action = new TestWriteLine("Action2")
                        {
                            Message = "Action2"
                        }
                    },
                }
            };

            ExpectedTrace trace = pick.GetExpectedTrace();

            TestRuntime.RunAndValidateWorkflow(pick, trace);
        }
        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);
        }
Beispiel #25
0
        public void OneBranch()
        {
            TestWriteLine writeLine1 = new TestWriteLine();

            writeLine1.Message     = "writeLine1";
            writeLine1.DisplayName = "writeLine1";

            TestParallel parallelActivity = new TestParallel("Parallel Activity");

            parallelActivity.Branches.Add(writeLine1);

            ExpectedTrace trace = parallelActivity.GetExpectedTrace();

            TestRuntime.RunAndValidateWorkflow(parallelActivity, trace);
        }
Beispiel #26
0
        public void CustomActivityOverridesBranchCancelStateWithCompletedState()
        {
            const string triggerMessage = "Trigger branch's trigger is executing.";
            const string actionMessage  = "Trigger branch's action is executing.";

            TestPick pick = new TestPick()
            {
                DisplayName     = "PickActivity",
                ExpectedOutcome = new Outcome(OutcomeState.Completed)
                {
                    IsOverrideable = false
                },
                Branches =
                {
                    new TestPickBranch()
                    {
                        DisplayName = "TriggeredBranch_Branch",
                        Trigger     = new TestWriteLine("TriggeredBranch_Trigger")
                        {
                            Message     = triggerMessage,
                            HintMessage = triggerMessage,
                        },
                        Action = new TestWriteLine("TriggeredBranch_Action")
                        {
                            Message     = actionMessage,
                            HintMessage = actionMessage,
                        },
                    },
                    new TestPickBranch()
                    {
                        DisplayName     = "ClosedCustomActivity_Branch",
                        ExpectedOutcome = Outcome.Completed,  // custom activity's outcome is Closed, therefore this branch is also Closed
                        Trigger         = new TestBlockingActivityWithWriteLineInCancel("ClosedCustomActivity_Trigger", OutcomeState.Completed)
                        {
                            ExpectedOutcome = Outcome.Completed,
                        },
                        Action = new TestWriteLine("ClosedCustomActivity_Action")
                        {
                            Message = "ClosedCustomActivity_Action - not supposed to show",
                        },
                    },
                }
            };

            ExpectedTrace trace = pick.GetExpectedTrace();

            TestRuntime.RunAndValidateWorkflow(pick, trace);
        }
Beispiel #27
0
        public void CancelOnAction()
        {
            TestPick pick = new TestPick
            {
                DisplayName     = "PickActivity",
                ExpectedOutcome = Outcome.Canceled,
                Branches        =
                {
                    new TestPickBranch
                    {
                        DisplayName = "Branch1",
                        Trigger     = new TestDelay()
                        {
                            Duration = new TimeSpan(0, 0, 3),
                        },
                        Action = new TestBlockingActivity("Block1")
                        {
                            ExpectedOutcome = Outcome.Canceled,
                        }
                    },
                    new TestPickBranch
                    {
                        DisplayName = "Branch2",
                        Trigger     = new TestBlockingActivity("Block2")
                        {
                            ExpectedOutcome = Outcome.Canceled,
                        },
                        Action = new TestWriteLine("Action2")
                        {
                            Message = "Action2",
                        }
                    }
                }
            };

            using (TestWorkflowRuntime runtime = TestRuntime.CreateTestWorkflowRuntime(pick))
            {
                runtime.ExecuteWorkflow();
                runtime.WaitForActivityStatusChange("Block1", TestActivityInstanceState.Executing);
                System.Threading.Thread.Sleep(1000);
                runtime.CancelWorkflow();
                ExpectedTrace trace = pick.GetExpectedTrace();
                runtime.WaitForCanceled(trace);
            }
        }
Beispiel #28
0
        public void NestedParallelForEach()
        {
            DelegateInArgument <string> _currentVariable_1 = new DelegateInArgument <string>()
            {
                Name = "_currentVariable_1"
            };
            DelegateInArgument <string> _currentVariable_2 = new DelegateInArgument <string>()
            {
                Name = "_currentVariable_2"
            };

            TestSequence sequ = new TestSequence("Sequence")
            {
                Activities =
                {
                    new TestParallelForEach <string>("Outer Parallel")
                    {
                        CurrentVariable = _currentVariable_1,
                        Body            = new TestParallelForEach <string>("Inner parallel")
                        {
                            CurrentVariable = _currentVariable_2,
                            Body            = new TestWriteLine("Writeline")
                            {
                                MessageExpression = (env) => (string)_currentVariable_2.Get(env),
                                HintMessageList   = { "iuu", "M", "iuu", "M" },
                            },

                            HintValues       = new string[] { "M", "iuu" },
                            ValuesExpression = (context => new string[]{ "M",                           "iuu" }),
                        },

                        HintValues       = new string[] { "M", "iuu" },
                        ValuesExpression = (context => new string[]{ "M",                           "iuu" }),
                    }
                }
            };

            // Using user traces to validate this test as by validating against expected trace
            // test is going into infinite loop during tracing.
            ExpectedTrace expected = sequ.GetExpectedTrace();

            expected.AddVerifyTypes(typeof(UserTrace));
            TestRuntime.RunAndValidateWorkflow(sequ, expected);
        }
        internal void ValidateTraces(ExpectedTrace expectedTrace, ActualTrace actualTrace)
        {
            //If no tracking participant tracks all events tracign validation will fail since it doesn't accoutn for the tracking profiles.
            //This is true ONLY for some trakcing test cases & not for runtime test cases which run with all tracking turned Off.
            //Hence we will not to tracing validation in this case & only do the tracking validation.
            //if (!TestTrackingDataManager.DoesAnyProfileTrackAllEvents(TestConfiguration.Current.TrackingServiceConfigurations))
            //{
            //    Log.TraceInternal("[TestTracingWatcher]No tracking participant tracks all events. Hece skipp tracing verification");
            //    return;
            //}

            foreach (TraceFilter filter in expectedTrace.Filters)
            {
                expectedTrace = filter.FilterExpectedTrace(expectedTrace);
                actualTrace   = filter.FilterActualTrace(actualTrace);
            }

            actualTrace.Validate(expectedTrace);
        }
Beispiel #30
0
        private static ExpectedTrace RemoveUserTrace(ExpectedTrace expectedTrace)
        {
            ExpectedTrace modifiedTrace = new ExpectedTrace(expectedTrace);
            int           count         = modifiedTrace.Trace.Steps.Count;
            int           removedCount  = 0;

            for (int i = 0; i < count; i++)
            {
                WorkflowTraceStep workflowTraceStep = expectedTrace.Trace.Steps[i];
                if (workflowTraceStep is UserTrace)
                {
                    modifiedTrace.Trace.Steps.Remove(workflowTraceStep);
                    removedCount++;
                    continue;
                }
                else if (workflowTraceStep is TraceGroup)
                {
                    ExpectedTrace tempExpectedTrace = new ExpectedTrace
                    {
                        Trace = TraceGroup.GetNewTraceGroup((TraceGroup)workflowTraceStep)
                    };
                    //take into account for activities already removed.
                    modifiedTrace.Trace.Steps.RemoveAt(i - removedCount);

                    ExpectedTrace cleanedUpExpectedTrace = TrackingFilter.RemoveUserTrace(tempExpectedTrace);

                    //add only if it is non-empty
                    if ((cleanedUpExpectedTrace != null) &&
                        (cleanedUpExpectedTrace.Trace != null) &&
                        (cleanedUpExpectedTrace.Trace.Steps != null) &&
                        (cleanedUpExpectedTrace.Trace.Steps.Count != 0)
                        )
                    {
                        modifiedTrace.Trace.Steps.Insert(i - removedCount, cleanedUpExpectedTrace.Trace);
                    }
                    else
                    {
                        removedCount++;
                    }
                }
            }
            return(modifiedTrace);
        }