Ejemplo n.º 1
0
        public void TestLoopOverNoResultsInExpression()
        {
            using (new WorkflowRunContext {
                RunTriggersInCurrentThread = true
            })
            {
                var wf = new Workflow();

                wf.AddDefaultExitPoint();

                var forEach1 = new ForEachResource
                {
                    Name = "foreach1" + DateTime.Now
                };
                var forEach1As = forEach1.As <WfActivity>();

                ActivityTestHelper.AddExpressionToActivityArgument(wf, forEach1As, "List", "all([Workflow Run State]) where Name='Wibble wobble bob'");  // there shouldn't be any

                wf.FirstActivity = forEach1As;
                wf.ContainedActivities.Add(forEach1As);

                var loopExitPoint = Entity.Get <ExitPoint>(ForeachImplementation.LoopExitPointAlias);

                ActivityTestHelper.AddTransition(wf, forEach1As, forEach1As, loopExitPoint);
                ActivityTestHelper.AddTermination(wf, forEach1As);

                wf.Save();
                ToDelete.Add(wf.Id);

                var run = (RunWorkflow(wf));

                IDictionary <string, object> outputs = run.GetOutput();
            }
        }
Ejemplo n.º 2
0
        public void TestLoopOverNoResultsFromGetRelationship()
        {
            using (new WorkflowRunContext {
                RunTriggersInCurrentThread = true
            })
            {
                var myType = new EntityType {
                    Name = "MyType"
                };
                myType.Save();
                ToDelete.Add(myType.Id);

                var wf = new Workflow {
                    Name = "TestLoopOverNoResultsFromGetRelationship"
                };

                wf.AddDefaultExitPoint();

                var getResources = new GetResourcesActivity {
                    Name = "GetResources"
                };
                var getResourcesAs = getResources.As <WfActivity>();

                ActivityTestHelper.AddEntityExpressionToInputArgument(wf, getResourcesAs, "Object", myType);   // this type has no instances

                wf.FirstActivity = getResourcesAs;
                wf.ContainedActivities.Add(getResourcesAs);

                var forEach1 = new ForEachResource
                {
                    Name = "foreach1" + DateTime.Now
                };
                var forEach1As = forEach1.As <WfActivity>();

                ActivityTestHelper.AddExpressionToActivityArgument(wf, forEach1As, "List", "[List]");  // there shouldn't be any

                wf.ContainedActivities.Add(forEach1As);

                ActivityTestHelper.AddTransition(wf, getResourcesAs, forEach1As);
                ActivityTestHelper.AddTransition(wf, forEach1As, forEach1As, "Loop");
                ActivityTestHelper.AddTermination(wf, forEach1As, "Finished");

                ActivityTestHelper.AddMissingExpressionParametersToWorkflow(wf);
                wf.Save();
                ToDelete.Add(wf.Id);

                var run = RunWorkflow(wf);

                IDictionary <string, object> outputs = run.GetOutput();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Add a foreach activity
        /// </summary>
        public static Workflow AddForEach(this Workflow wf, string name, string listExpression, EntityType listType, string fromNamed = null, string fromExit = null)
        {
            var forEach = new ForEachResource()
            {
                Name = name
            };
            var forEachAs = forEach.As <WfActivity>();

            AddExpressionToActivityArgument(wf, forEachAs, "List", listExpression);

            wf.AddActivity(forEachAs, fromNamed, fromExit);

            AddMissingExpressionParametersToWorkflow(wf);

            var resourceArgInst = forEachAs.GetOutputArgumentInstances().First(ai => ai.Name == name + "_Record");

            resourceArgInst.InstanceConformsToType = listType;

            return(wf);
        }
Ejemplo n.º 4
0
        public void TestInputVarNotSet()
        {
            using (new WorkflowRunContext {
                RunTriggersInCurrentThread = true
            })
            {
                var wf = new Workflow();

                wf.AddDefaultExitPoint();

                var forEach1 = new ForEachResource
                {
                    Name = "foreach1" + DateTime.Now
                };
                var forEach1As = forEach1.As <WfActivity>();

                wf.FirstActivity = forEach1As;
                wf.ContainedActivities.Add(forEach1As);

                var loopExitPoint = Entity.Get <ExitPoint>(ForeachImplementation.LoopExitPointAlias);

                ActivityTestHelper.AddTransition(wf, forEach1As, forEach1As, loopExitPoint);
                ActivityTestHelper.AddTermination(wf, forEach1As);
                //ActivityHelper.AddMissingExpressionParametersToWorkflow(wf);

                wf.Save();
                ToDelete.Add(wf.Id);

                ActivityImplementationBase nextActivity = forEach1As.Cast <WfActivity>().CreateWindowsActivity();

                var metaData = new WorkflowMetadata();
                nextActivity.Validate(metaData);

                Assert.IsTrue(metaData.ValidationMessages.Count() == 1, "There is only one validation message");
                Assert.IsTrue(metaData.ValidationMessages.First().StartsWith("Mandatory argument"), "Validation is 'Mandatory argument'");
            }
        }
Ejemplo n.º 5
0
        public void LoopWithinLoop_bug_17651()
        {
            using (new WorkflowRunContext {
                RunTriggersInCurrentThread = true
            })
            {
                var wf = new Workflow()
                {
                    Name = "LoopWithinLoop_bug_17651"
                };
                wf.AddDefaultExitPoint();

                var count = new IntegerArgument()
                {
                    Name = "count"
                };
                ActivityTestHelper.AddVariableToWorkflow(wf, count.As <ActivityArgument>());
                wf.AddExpressionToWorkflowVariable("count", "0");

                var foreachX = new ForEachResource()
                {
                    Name = "ForEachX" + DateTime.Now
                };
                var foreachXAs = foreachX.As <WfActivity>();
                ActivityTestHelper.AddExpressionToActivityArgument(wf, foreachXAs, "List", "all([Workflow Event])");

                wf.FirstActivity = foreachXAs;
                wf.ContainedActivities.Add(foreachXAs);


                var foreachY = new ForEachResource()
                {
                    Name = "ForEachY" + DateTime.Now
                };
                var foreachYAs = foreachY.As <WfActivity>();
                ActivityTestHelper.AddExpressionToActivityArgument(wf, foreachYAs, "List", "all([Event Email Priority Enum])");

                wf.ContainedActivities.Add(foreachYAs);

                ActivityTestHelper.AddTransition(wf, foreachXAs, foreachYAs, "Loop");
                ActivityTestHelper.AddTermination(wf, foreachXAs, "Finished");

                var assign = new AssignToVariable()
                {
                    Name = "Assign"
                };
                var assignAs = assign.As <WfActivity>();
                assign.TargetVariable = count.As <ActivityArgument>();
                ActivityTestHelper.AddExpressionToActivityArgument(wf, assignAs, "Value", "count + 1");

                wf.ContainedActivities.Add(assignAs);

                ActivityTestHelper.AddTransition(wf, foreachYAs, assignAs, "Loop");
                ActivityTestHelper.AddTransition(wf, foreachYAs, foreachXAs, "Finished");

                ActivityTestHelper.AddTransition(wf, assignAs, foreachYAs);

                var output = new IntegerArgument()
                {
                    Name = "out"
                };
                var outputAs = output.As <ActivityArgument>();

                wf.OutputArguments.Add(outputAs);

                ActivityTestHelper.AddAssignToVar(wf, "Set Output", "count", "out");

                ActivityTestHelper.AddMissingExpressionParametersToWorkflow(wf);

                wf.Save();
                ToDelete.Add(wf.Id);

                var run     = (RunWorkflow(wf));
                var outputs = run.GetOutput();

                Assert.AreEqual(1, outputs.Count, "There is one output argument");

                var result = (int)outputs["out"];

                var triggeredOnCount = Entity.GetInstancesOfType <WorkflowEventEnum>(false).Count();
                var runStateCount    = Entity.GetInstancesOfType <EventEmailPriorityEnum>(false).Count();


                Assert.AreEqual(triggeredOnCount * runStateCount, result, "The nested loops ran the correct number of times.");
            }
        }