public void SendMailUsingRecipientList()
        {
            string subject = "Subject " + Guid.NewGuid().ToString();
            string body    = "Body " + Guid.NewGuid().ToString();

            var emailSenderMock = new Mock <IEmailSender>();

            emailSenderMock
            .Setup(m => m.SendMessages(It.IsAny <IReadOnlyCollection <MailMessage> >()))
            .Callback <IReadOnlyCollection <MailMessage> >(x =>
            {
                var emails = x.ToList();
                Assert.True(emails.Count == 1);
                Assert.True(emails[0].Subject == subject);
                Assert.True(emails[0].Body == body);
                Assert.True(emails[0].To.Count > 1);
                Assert.True(emails[0].CC.Count == 0);
                Assert.True(emails[0].Bcc.Count == 0);
                Assert.True(emails[0].Attachments.Count == 0);
            });

            Action <Workflow, WfActivity> configurationCallback = (wf, emailActionAs) =>
            {
                ActivityTestHelper.AddEntityExpressionToInputArgument(wf, emailActionAs, "Email To", new EntityRef("core:sendEmailActivityRecipientsList"));
                ActivityTestHelper.AddEntityExpressionToInputArgument(wf, emailActionAs, "Send As", new EntityRef("core:sendEmailActivityGroupDistribution"));
                ActivityTestHelper.AddExpressionToActivityArgument(wf, emailActionAs, "Recipients List", "all(Employee_Test)", false);
                ActivityTestHelper.SetActivityArgumentToResource(wf, emailActionAs, "TO Address Field", Entity.Get <Resource>("oldshared:workEmail"));
                ActivityTestHelper.AddExpressionToActivityArgument(wf, emailActionAs, "Subject", $"'{subject}'", false);
                ActivityTestHelper.AddExpressionToActivityArgument(wf, emailActionAs, "Body", $"'{body}'", false);
                ActivityTestHelper.AddExpressionToActivityArgument(wf, emailActionAs, "No Reply", "true", false);
            };

            SendMailWithConfigAction(configurationCallback, emailSenderMock.Object);
        }
        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();
            }
        }
        public void SendMailUsingAddressesWithBadAddress()
        {
            string subject = "Subject " + Guid.NewGuid().ToString();
            string body    = "Body " + Guid.NewGuid().ToString();

            var emailSenderMock = new Mock <IEmailSender>();

            emailSenderMock
            .Setup(m => m.SendMessages(It.IsAny <IReadOnlyCollection <MailMessage> >()))
            .Callback <IReadOnlyCollection <MailMessage> >(x =>
            {
                var emails = x.ToList();
                Assert.True(emails.Count == 1);
                Assert.True(emails[0].Subject == subject);
                Assert.True(emails[0].Body == body);
                Assert.True(emails[0].To.Count == 2);
                Assert.True(ContainsAddress(emails[0].To, "*****@*****.**"));
                Assert.True(ContainsAddress(emails[0].To, "*****@*****.**"));
                Assert.True(emails[0].CC.Count == 0);
                Assert.True(emails[0].Bcc.Count == 0);
                Assert.True(emails[0].Attachments.Count == 0);
            });

            Action <Workflow, WfActivity> configurationCallback = (wf, emailActionAs) =>
            {
                ActivityTestHelper.AddEntityExpressionToInputArgument(wf, emailActionAs, "Email To", new EntityRef("core:sendEmailActivityRecipientsAddress"));
                ActivityTestHelper.AddEntityExpressionToInputArgument(wf, emailActionAs, "Send As", new EntityRef("core:sendEmailActivityGroupDistribution"));
                ActivityTestHelper.AddExpressionToActivityArgument(wf, emailActionAs, "To Addresses", "'[email protected]; NotAnEmailAddress.com; [email protected]'");
                ActivityTestHelper.AddExpressionToActivityArgument(wf, emailActionAs, "Subject", $"'{subject}'", false);
                ActivityTestHelper.AddExpressionToActivityArgument(wf, emailActionAs, "Body", $"'{body}'", false);
                ActivityTestHelper.AddExpressionToActivityArgument(wf, emailActionAs, "No Reply", "true", false);
            };

            SendMailWithConfigAction(configurationCallback, emailSenderMock.Object);
        }
Beispiel #4
0
        public void ProxyCallingItself_bug_17649()
        {
            using (new WorkflowRunContext {
                RunTriggersInCurrentThread = true
            })
            {
                // Inner Workflow
                var wf = new Workflow
                {
                    Name = "ProxyCallingItself_bug_17649 " + DateTime.Now
                };

                var isInnerArg = new BoolArgument()
                {
                    Name = "Is Inner"
                }.As <ActivityArgument>();
                wf.InputArguments.Add(isInnerArg);

                wf.AddDefaultExitPoint();

                var decision = new DecisionActivity()
                {
                    Name = "Is Inner"
                };
                var decisionAs = decision.As <WfActivity>();
                ActivityTestHelper.AddExpressionToActivityArgument(wf, decisionAs, "DecisionArgument", "[Is Inner]", false);

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

                WorkflowProxy innerProxy   = ActivityTestHelper.CreateWorkflowProxy(wf);
                var           innerProxyAs = innerProxy.As <WfActivity>();

                wf.ContainedActivities.Add(innerProxyAs);

                ActivityTestHelper.AddMissingExpressionParametersToWorkflow(wf);

                ActivityTestHelper.AddExpressionToActivityArgument(wf, innerProxyAs, "Is Inner", "true", false);

                ActivityTestHelper.AddTransition(wf, decisionAs, innerProxyAs, "No");
                ActivityTestHelper.AddTermination(wf, innerProxyAs);
                ActivityTestHelper.AddTermination(wf, decisionAs, "Yes");

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

                wf.Validate();


                var input = new Dictionary <string, object>()
                {
                    { "Is Inner", true }
                };
                var run = (RunWorkflow(wf, input));

                Assert.AreEqual(WorkflowRunState_Enumeration.WorkflowRunCompleted, run.WorkflowRunStatus_Enum, "Finished without errors");
            }
        }
        public void SendMailWithAttachments()
        {
            string subject = "Subject " + Guid.NewGuid().ToString();
            string body    = "Body " + Guid.NewGuid().ToString();

            string tempHash = null;
            var    buff     = Encoding.UTF8.GetBytes("Email Attachment File " + CryptoHelper.GetRandomPrintableString(10));

            using (MemoryStream stream = new MemoryStream(buff))
            {
                tempHash = Factory.DocumentFileRepository.Put(stream);
            }

            var file = Entity.Create <Document>();

            file.Name          = "Email Attachment Test File";
            file.Description   = "Send Email Attachment Test";
            file.FileDataHash  = tempHash;
            file.Size          = buff.Length;
            file.FileExtension = "txt";
            file.Save();

            var emailSenderMock = new Mock <IEmailSender>();

            emailSenderMock
            .Setup(m => m.SendMessages(It.IsAny <IReadOnlyCollection <MailMessage> >()))
            .Callback <IReadOnlyCollection <MailMessage> >(x =>
            {
                var emails = x.ToList();
                Assert.True(emails.Count == 1);
                Assert.True(emails[0].To.Count == 2);
                Assert.True(ContainsAddress(emails[0].To, "*****@*****.**"));
                Assert.True(ContainsAddress(emails[0].To, "*****@*****.**"));
                Assert.True(emails[0].CC.Count == 0);
                Assert.True(emails[0].Bcc.Count == 0);
                Assert.True(emails[0].Attachments.Count == 1);
                Assert.True(emails[0].Attachments[0].ContentStream.Length == buff.Length);
            });


            Action <Workflow, WfActivity> configurationCallback = (wf, emailActionAs) =>
            {
                ActivityTestHelper.AddEntityExpressionToInputArgument(wf, emailActionAs, "Email To", new EntityRef("core:sendEmailActivityRecipientsAddress"));
                ActivityTestHelper.AddEntityExpressionToInputArgument(wf, emailActionAs, "Send As", new EntityRef("core:sendEmailActivityGroupDistribution"));
                ActivityTestHelper.AddExpressionToActivityArgument(wf, emailActionAs, "To Addresses", "'[email protected]; [email protected]'");
                ActivityTestHelper.AddExpressionToActivityArgument(wf, emailActionAs, "Subject", $"'{subject}'", false);
                ActivityTestHelper.AddExpressionToActivityArgument(wf, emailActionAs, "Body", $"'{body}'", false);
                ActivityTestHelper.AddExpressionToActivityArgument(wf, emailActionAs, "No Reply", "true", false);
                ActivityTestHelper.AddExpressionToActivityArgument(wf, emailActionAs, "Attachments", file.Cast <Resource>().ToEnumerable());
            };

            SendMailWithConfigAction(configurationCallback, emailSenderMock.Object);

            file.Delete();
        }
        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();
            }
        }
        public void SendMailUsingAddressesFromInbox()
        {
            string subject = "Subject " + Guid.NewGuid().ToString();
            string body    = "Body " + Guid.NewGuid().ToString();

            var inbox = new Inbox()
            {
                Name = "Test Inbox 1", InboxEmailAddress = "*****@*****.**"
            };

            inbox.Save();

            var emailSenderMock = new Mock <IEmailSender>();

            emailSenderMock
            .Setup(m => m.SendMessages(It.IsAny <IReadOnlyCollection <MailMessage> >()))
            .Callback <IReadOnlyCollection <MailMessage> >(x =>
            {
                var emails = x.ToList();
                Assert.True(emails.Count == 1);
                Assert.True(emails[0].Subject == subject);
                Assert.True(emails[0].Body == body);
                Assert.True(emails[0].To.Count == 1);
                Assert.True(ContainsAddress(emails[0].To, "*****@*****.**"));
                Assert.True(emails[0].CC.Count == 1);
                Assert.True(ContainsAddress(emails[0].CC, "*****@*****.**"));
                Assert.True(emails[0].Bcc.Count == 1);
                Assert.True(ContainsAddress(emails[0].Bcc, "*****@*****.**"));
                Assert.True(emails[0].Attachments.Count == 0);
                Assert.True(emails[0].From.DisplayName == inbox.Name);
                Assert.True(emails[0].From.Address == inbox.InboxEmailAddress);
            });

            Action <Workflow, WfActivity> configurationCallback = (wf, emailActionAs) =>
            {
                ActivityTestHelper.AddEntityExpressionToInputArgument(wf, emailActionAs, "Email To", new EntityRef("core:sendEmailActivityRecipientsAddress"));
                ActivityTestHelper.AddEntityExpressionToInputArgument(wf, emailActionAs, "Send As", new EntityRef("core:sendEmailActivityGroupDistribution"));
                ActivityTestHelper.AddExpressionToActivityArgument(wf, emailActionAs, "To Addresses", "'*****@*****.**'");
                ActivityTestHelper.AddExpressionToActivityArgument(wf, emailActionAs, "CC Addresses", "'*****@*****.**'");
                ActivityTestHelper.AddExpressionToActivityArgument(wf, emailActionAs, "BCC Addresses", "'*****@*****.**'");
                ActivityTestHelper.AddExpressionToActivityArgument(wf, emailActionAs, "Subject", $"'{subject}'", false);
                ActivityTestHelper.AddExpressionToActivityArgument(wf, emailActionAs, "Body", $"'{body}'", false);
                ActivityTestHelper.AddExpressionToActivityArgument(wf, emailActionAs, "No Reply", "false", false);
                ActivityTestHelper.AddEntityExpressionToInputArgument(wf, emailActionAs, "Reply to Inbox", new EntityRef(inbox));
            };

            SendMailWithConfigAction(configurationCallback, emailSenderMock.Object);

            inbox.Delete();
        }
Beispiel #8
0
        public void TestRun( )
        {
            var wf = new Workflow
            {
                Name = "Wf"
            };

            wf.AddDefaultExitPoint( );

            var l1 = new LogActivity
            {
                Name = "l1"
            }.Cast <WfActivity>( );
            var l2 = new LogActivity
            {
                Name = "12"
            }.Cast <WfActivity>( );

            // wf.FirstActivity = l1;
            //wf.ContainedActivities.Add(l1);
            wf.ContainedActivities.Add(l2);

            ActivityTestHelper.AddFirstActivityWithMapping(wf, l1, null);
            ActivityTestHelper.AddExpressionToActivityArgument(wf, l1, "Message", "'Message 1'", false);

            ActivityTestHelper.AddTransition(wf, l1, l2);
            ActivityTestHelper.AddExpressionToActivityArgument(wf, l2, "Message", "'Message 2'", false);

            ActivityTestHelper.AddTermination(wf, l2, l2.GetDefaultExitPoint(), CreateDefaultExitPoint());

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

            l1.Save( );
            l2.Save( );

            ToDelete.Add(wf.Id);
            ToDelete.Add(l1.Id);
            ToDelete.Add(l2.Id);

            var run = (RunWorkflow(wf));

            Assert.AreEqual(WorkflowRunState_Enumeration.WorkflowRunCompleted, run.WorkflowRunStatus_Enum, "Finished without errors");

            // run using service
        }
Beispiel #9
0
        /// <summary>
        /// Add a delete activity
        /// </summary>
        public static Workflow AddDelete(this Workflow wf, string name, string resourceExpression = null, string fromNamed = null, string fromExit = null)
        {
            var uf = new DeleteActivity()
            {
                Name = name
            };
            var ufAs = uf.As <WfActivity>();


            if (resourceExpression != null)
            {
                ActivityTestHelper.AddExpressionToActivityArgument(wf, ufAs, "Record", resourceExpression, false);
            }

            wf.AddActivity(ufAs, fromNamed, fromExit);
            AddMissingExpressionParametersToWorkflow(wf);

            return(wf);
        }
Beispiel #10
0
        /// <summary>
        /// Add a get records activity
        /// </summary>
        public static Workflow AddGetRecords(this Workflow wf, string name, string definitionExpression, string reportExpression = null, string fromNamed = null, string fromExit = null)
        {
            var act = new GetResourcesActivity()
            {
                Name = name
            };
            var actAs = act.As <WfActivity>();

            ActivityTestHelper.AddExpressionToActivityArgument(wf, actAs, "Object", definitionExpression, false);


            if (reportExpression != null)
            {
                ActivityTestHelper.AddExpressionToActivityArgument(wf, actAs, "Report", reportExpression, false);
            }

            wf.AddActivity(actAs, fromNamed, fromExit);
            AddMissingExpressionParametersToWorkflow(wf);

            return(wf);
        }
Beispiel #11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="fieldAliasExpressionPairs">An array of field-alias, expression pairs</param>
        public static Workflow AddUpdate(this Workflow wf, string name, string resourceExpression, string[] fieldAliasExpressionPairs,
                                         string fromNamed = null, string fromExit = null)
        {
            var update = new UpdateFieldActivity()
            {
                Name = name
            };
            var updateAs = update.As <WfActivity>();

            ActivityTestHelper.AddExpressionToActivityArgument(wf, updateAs, "Record", resourceExpression, false);

            wf.AddActivity(updateAs, fromNamed, fromExit);

            var count = 0;

            for (int i = 0; i < fieldAliasExpressionPairs.Count(); i += 2)
            {
                var argName      = "input" + count++;
                var argValueName = argName + "_value";

                var result1 = (new StringArgument()
                {
                    Name = argName
                }).As <ActivityArgument>();;
                update.InputArguments.Add(result1);
                AddExpressionToActivityArgument(wf, updateAs, argName, fieldAliasExpressionPairs[i]);

                var result2 = (new ObjectArgument {
                    Name = argValueName
                }).As <ActivityArgument>();
                update.InputArguments.Add(result2);
                AddExpressionToActivityArgument(wf, updateAs, argValueName, fieldAliasExpressionPairs[i + 1]);
            }

            AddMissingExpressionParametersToWorkflow(wf);

            return(wf);
        }
Beispiel #12
0
        public void LowAccessUserPausedPriorNestedWorkflow_bug_27863()
        {
            using (new WorkflowRunContext {
                RunTriggersInCurrentThread = true
            })
            {
                Workflow       myParentWorkflow = null;
                Workflow       myChildWorkflow  = null;
                UserAccount    myUser           = null;
                Person         myPerson         = null;
                PromptUserTask userInputTask    = null;

                try
                {
                    myChildWorkflow = Entity.Create <Workflow>()
                                      .AddDefaultExitPoint()
                                      .AddInput <BoolArgument>("InputChild")
                                      .AddLog("Child Log", "Child Log");

                    myChildWorkflow.Name = "Child Workflow 27863 " + DateTime.Now;
                    myChildWorkflow.WorkflowRunAsOwner = true;
                    myChildWorkflow.Save();

                    myParentWorkflow = Entity.Create <Workflow>()
                                       .AddDefaultExitPoint()
                                       .AddInput <BoolArgument>("InputParent")
                                       .AddPromptUser("User Input")
                                       .AddWorkflowProxy("Child Workflow", myChildWorkflow)
                                       .AddLog("Parent Log", "Parent Log");

                    var childWorkflowActivity = myParentWorkflow.ContainedActivities.FirstOrDefault(a => a.Name == "Child Workflow");

                    ActivityTestHelper.AddExpressionToActivityArgument(myParentWorkflow, childWorkflowActivity, "InputChild", "[InputParent]");

                    myParentWorkflow.Name = "Parent Workflow 27863 " + DateTime.Now;
                    myParentWorkflow.WorkflowRunAsOwner = true;
                    myParentWorkflow.Save();

                    myPerson             = Entity.Create <Person>();
                    myPerson.FirstName   = "Billy";
                    myPerson.LastName    = "Bob";
                    myUser               = Entity.Create <UserAccount>();
                    myUser.Name          = "bb" + DateTime.Now;
                    myUser.AccountHolder = myPerson;
                    myUser.Save();

                    new AccessRuleFactory().AddAllowByQuery(myUser.As <Subject>(),
                                                            Workflow.Workflow_Type.As <SecurableEntity>(),
                                                            new EntityRef("core:read").ToEnumerable(),
                                                            TestQueries.Entities(new EntityRef("core:workflow")).ToReport());

                    WorkflowRun run;

                    using (new SetUser(myUser))
                        using (new WorkflowRunContext(true)
                        {
                            RunTriggersInCurrentThread = true
                        })
                        {
                            run = RunWorkflow(myParentWorkflow);
                        }

                    run.WorkflowRunStatus_Enum.Should().Be(WorkflowRunState_Enumeration.WorkflowRunPaused);
                    run.PendingActivity.Should().NotBeNull();
                    run.PendingActivity.Name.Should().Be("User Input");
                    run.TaskWithinWorkflowRun.Should().NotBeNull().And.NotBeEmpty().And.HaveCount(1);

                    userInputTask = run.TaskWithinWorkflowRun.First().AsWritable <PromptUserTask>();
                    userInputTask.Should().NotBeNull();

                    userInputTask.PromptForTaskStateInfo.Should().NotBeNull().And.HaveCount(1);
                    userInputTask.PromptForTaskStateInfo.Select(si => si.StateInfoArgument.Name).Should().Contain("InputParent");

                    var value = userInputTask.PromptForTaskStateInfo.First(si => si.StateInfoArgument.Name == "InputParent");
                    var param = value.StateInfoValue.AsWritable <BoolArgument>();
                    param.BoolParameterValue = true;
                    param.Save();

                    userInputTask.TaskStatus_Enum    = TaskStatusEnum_Enumeration.TaskStatusCompleted;
                    userInputTask.UserTaskIsComplete = true;

                    using (new SetUser(myUser))
                        using (new WorkflowRunContext(true)
                        {
                            RunTriggersInCurrentThread = true
                        })
                        {
                            userInputTask.Save();
                        }

                    var wf = Entity.Get <Workflow>(myParentWorkflow.Id, Workflow.RunningInstances_Field);

                    wf.RunningInstances.Count().Should().Be(1);
                    var runResume = wf.RunningInstances.First();

                    Assert.IsTrue(WaitForWorkflowToStop(runResume), "Workflow run should have completed.");

                    runResume = Entity.Get <WorkflowRun>(runResume.Id, WorkflowRun.WorkflowRunStatus_Field);
                    runResume.Should().NotBeNull();
                    runResume.WorkflowRunStatus_Enum.Should().Be(WorkflowRunState_Enumeration.WorkflowRunCompleted);
                    runResume.RunLog.Should().NotBeNull().And.NotBeEmpty();
                }
                finally
                {
                    if (userInputTask != null)
                    {
                        ToDelete.Add(userInputTask.Id);
                    }
                    if (myParentWorkflow != null)
                    {
                        ToDelete.Add(myParentWorkflow.Id);
                    }
                    if (myChildWorkflow != null)
                    {
                        ToDelete.Add(myChildWorkflow.Id);
                    }
                    if (myUser != null)
                    {
                        ToDelete.Add(myUser.Id);
                    }
                    if (myPerson != null)
                    {
                        ToDelete.Add(myPerson.Id);
                    }
                }
            }
        }
        public void SetVariableTest( )
        {
            using (new WorkflowRunContext {
                RunTriggersInCurrentThread = true
            })
            {
                var workflow = new Workflow
                {
                    Name = "Wf" + DateTime.Now
                };

                workflow.AddDefaultExitPoint();

                var v1 = Entity.Create <IntegerArgument>().As <ActivityArgument>();
                v1.Name = "v1";
                ActivityTestHelper.AddVariableToWorkflow(workflow, v1);

                var v2 = Entity.Create <ResourceArgument>().As <ActivityArgument>();
                v2.Name = "v2";
                ActivityTestHelper.AddVariableToWorkflow(workflow, v2);

                var v3 = Entity.Create <ResourceListArgument>().As <ActivityArgument>();
                v3.Name = "v3";
                ActivityTestHelper.AddVariableToWorkflow(workflow, v3);

                // set starting values
                workflow.AddExpressionToWorkflowVariable("v1", "111", false);
                workflow.AddEntityExpressionToVariable("v2", new EntityRef("core:person"));
                //ActivityHelper.AddExpressionToWorkflowVariable(workflow, "v3", "[Resource Type]", false);

                // assign 222 to v1
                var setV1   = Entity.Create <AssignToVariable>();
                var setV1As = setV1.Cast <WfActivity>();
                setV1.TargetVariable = v1;
                ActivityTestHelper.AddExpressionToActivityArgument(workflow, setV1As, "Value", "222", false);
                workflow.FirstActivity = setV1As;
                workflow.ContainedActivities.Add(setV1As);
                ActivityTestHelper.AddTermination(workflow, setV1As);
                // output
                var v1Out   = Entity.Create <StringArgument>();
                var v1OutAs = v1Out.Cast <ActivityArgument>();
                v1Out.Name = "v1Out";

                workflow.OutputArguments.Add(v1OutAs);

                ActivityTestHelper.AddAssignToVar(workflow, "set out", "'output is ' + v1", "v1Out");
                ActivityTestHelper.AddMissingExpressionParametersToWorkflow(workflow);

                workflow.Save();

                ToDelete.Add(workflow.Id);

                var run = (RunWorkflow(workflow));

                Assert.IsTrue(run.WorkflowRunStatus_Enum == WorkflowRunState_Enumeration.WorkflowRunCompleted, "Run Completed");


                IDictionary <string, object> outputs = run.GetOutput();

                Assert.IsTrue(outputs.ContainsKey("v1Out"), "Output has the result.");
                Assert.AreEqual("output is 222", outputs["v1Out"], "Ensure the variable was updated and sent to the output");
            }
        }
        public void DecisionTest()
        {
            var wf = new Workflow
            {
                Name = "ConnectingParameters Wf"
            };
            var wfAs = wf.Cast <WfActivity>();

            wf.InputArguments.Add((new IntegerArgument
            {
                Name = "wfInInt"
            }).Cast <ActivityArgument>());

            var yesExit = new ExitPoint
            {
                IsDefaultExitPoint = true,
                Name = "Yes"
            };
            var noExit = new ExitPoint
            {
                Name = "No"
            };

            wf.ExitPoints.Add(yesExit);
            wf.ExitPoints.Add(noExit);

            var decision1 = new DecisionActivity
            {
                Name = "Decision1"
            };
            var decision1As = decision1.Cast <WfActivity>();


            ActivityTestHelper.AddFirstActivityWithMapping(
                wf,
                decision1As,
                null);

            string wfInIntSubString = ActivityTestHelper.CreateArgumentInstance(wf, wfAs, wfAs.GetInputArgument("wfInInt"));

            ActivityTestHelper.AddExpressionToActivityArgument(wf, decision1As, "DecisionArgument", wfInIntSubString + " > 5", false);

            ActivityTestHelper.AddTermination(
                wf,
                decision1As,
                Entity.Get <ExitPoint>(new EntityRef("core", "decisionActivityYesExitPoint")),
                yesExit);

            ActivityTestHelper.AddTermination(
                wf,
                decision1As,
                Entity.Get <ExitPoint>(new EntityRef("core", "decisionActivityNoExitPoint")),
                noExit);

            ActivityTestHelper.AddMissingExpressionParametersToWorkflow(wf);

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

            var input = new Dictionary <string, object>
            {
                {
                    "wfInInt", 10
                }
            };

            var run = RunWorkflow(wf, input);

            Assert.AreEqual(run.GetExitPoint().Id, yesExit.Id, "Input of '10' should result in a 'yes' decision");

            input = new Dictionary <string, object>
            {
                {
                    "wfInInt", 1
                }
            };

            run = RunWorkflow(wf, input);

            Assert.AreEqual(WorkflowRunState_Enumeration.WorkflowRunCompleted, run.WorkflowRunStatus_Enum, "Finished without errors");

            Assert.AreEqual(noExit.Id, run.GetExitPoint().Id, "Input of '1' should results in a 'no' decision");
        }
        public void SwitchTest( )
        {
            var wf = new Workflow
            {
                Name = "ConnectingParameters Wf"
            };
            var wfAs = wf.Cast <WfActivity>( );

            wf.InputArguments.Add((new StringArgument
            {
                Name = "wfInString"
            }).Cast <ActivityArgument>( ));

            var wfYesExit = new ExitPoint
            {
                IsDefaultExitPoint = true,
                Name = "Wf Yes"
            };
            var wfNoExit = new ExitPoint
            {
                Name = "Wf No"
            };
            var wfMaybeExit = new ExitPoint
            {
                Name = "Wf Maybe"
            };
            var wfDontKnowExit = new ExitPoint
            {
                Name = "Wf Dont know"
            };

            wf.ExitPoints.Add(wfYesExit);
            wf.ExitPoints.Add(wfNoExit);
            wf.ExitPoints.Add(wfMaybeExit);
            wf.ExitPoints.Add(wfDontKnowExit);

            var switch1 = new SwitchActivity
            {
                Name = "Switch1"
            };
            var switch1As = switch1.Cast <WfActivity>( );

            ActivityTestHelper.AddFirstActivityWithMapping(
                wf,
                switch1As,
                null);

            ActivityTestHelper.CreateArgumentInstance(wf, wfAs, wfAs.GetInputArgument("wfInString"));
            ActivityTestHelper.AddExpressionToActivityArgument(wf, switch1As, "Value to Switch On", "wfInString", false);

            var switchYesExit = new ExitPoint
            {
                IsDefaultExitPoint = true,
                Name = "Yes"
            };
            var switchNoExit = new ExitPoint
            {
                Name = "No"
            };
            var switchMaybeExit = new ExitPoint
            {
                Name = "Maybe"
            };

            switch1.ExitPoints.Add(switchYesExit);
            switch1.ExitPoints.Add(switchNoExit);
            switch1.ExitPoints.Add(switchMaybeExit);

            ActivityTestHelper.AddTermination(
                wf,
                switch1As,
                switchYesExit,
                wfYesExit);

            ActivityTestHelper.AddTermination(
                wf,
                switch1As,
                switchNoExit,
                wfNoExit);

            ActivityTestHelper.AddTermination(
                wf,
                switch1As,
                switchMaybeExit,
                wfMaybeExit);

            var otherwiseExit = Entity.Get <ExitPoint>(new EntityRef("core", "switchActivityOtherwiseExitPoint"));

            ActivityTestHelper.AddTermination(
                wf,
                switch1As,
                otherwiseExit,
                wfDontKnowExit);

            ActivityTestHelper.AddMissingExpressionParametersToWorkflow(wf);

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

            TestResult(wf, "Yes", wfYesExit);
            TestResult(wf, "No", wfNoExit);
            TestResult(wf, "Maybe", wfMaybeExit);
            TestResult(wf, "Something else", wfDontKnowExit);
        }
Beispiel #16
0
        protected Workflow CreateDisplayFormTestWf(EntityRef priority, decimal?percentageComplete, bool?waitForNext, decimal?timeoutSeconds = null, bool?keepTask = null)
        {
            // moved this out to help with deadlocking issues when running the test.

            Person      dummyPerson  = null;
            UserAccount dummyAccount = null;

            using (new WorkflowRunContext {
                RunTriggersInCurrentThread = true
            })
            {
                dummyPerson = Entity.Create <Person>();
                var tag = Rand.Next().ToString();
                dummyPerson.FirstName = "Dummy" + tag;
                dummyPerson.LastName  = "Dummy" + tag;
                dummyPerson.Name      = dummyPerson.FirstName + ' ' + dummyPerson.LastName;
                dummyPerson.Save();

                dummyAccount               = Entity.Create <UserAccount>();
                dummyAccount.Name          = "Dummy" + DateTime.Now + Rand.Next();
                dummyAccount.AccountHolder = dummyPerson;
                dummyAccount.Save();
            }

            var displayFormWf = Entity.Create <Workflow>();

            displayFormWf.Name = "Test approval Wf";

            displayFormWf
            .AddWfExitPoint("First Exit", true)
            .AddWfExitPoint("Second Exit")
            .AddWfExitPoint("Time-out")
            .AddLog("log", "Test");


            var displayForm = Entity.Create <DisplayFormActivity>();

            displayForm.Name = "displayForm";
            var displayFormAs = displayForm.Cast <WfActivity>();
            var withExits     = displayForm.Cast <EntityWithArgsAndExits>();

            // add some exits
            foreach (var name in new[]
            {
                "Option 1",
                "Option 2"
            })
            {
                var exitPoint = Entity.Create <ExitPoint>();
                exitPoint.Name = name;
                exitPoint.ExitPointActionSummary = name + " action summary";
                exitPoint.IsDefaultExitPoint     = name == "Option 1";
                withExits.ExitPoints.Add(exitPoint);
            }

            displayFormWf.AddActivity(displayFormAs, dontTerminate: true);

            var timeOutExitPoint = Entity.Get <ExitPoint>("core:displayFormTimeout");

            displayFormWf
            .AddEntityExpressionToInputArgument(displayFormAs, "Form", new EntityRef("test", "personForm"))
            .AddEntityExpressionToInputArgument(displayFormAs, "Record", new EntityRef("test", "aaAaSriKorada"))
            .AddEntityExpressionToInputArgument(displayFormAs, "For Person", dummyPerson);

            if (timeoutSeconds != null)
            {
                var days = (double)timeoutSeconds / 60.0 / 60.0 / 24.0;
                ActivityTestHelper.AddExpressionToActivityArgument(displayFormWf, displayFormAs, "Due in (Days)",
                                                                   days.ToString(CultureInfo.InvariantCulture));
            }
            if (priority != null)
            {
                displayFormWf.AddEntityExpressionToInputArgument(displayFormAs, "Priority", priority);
            }

            if (percentageComplete != null)
            {
                displayFormWf.AddExpressionToActivityArgument(displayFormAs, "% Completed", percentageComplete.ToString());
            }

            if (waitForNext != null)
            {
                displayFormWf.AddExpressionToActivityArgument(displayFormAs, "Wait for next form", waitForNext.ToString());
            }

            if (keepTask != null)
            {
                displayFormWf.AddExpressionToActivityArgument(displayFormAs, "Record history", keepTask.ToString());
            }

            displayFormWf
            .AddOutput <ResourceArgument>("UserTaskOutput")
            .AddAssignToVar("AssignOutput", "[displayForm_Completed task]", "UserTaskOutput", "displayForm", "Option 2")
            .AddTermination("displayForm", "Option 1", "First Exit")
            .AddTermination("AssignOutput", null, "Second Exit")
            .AddTermination("displayForm", timeOutExitPoint.Name, "Time-out");


            //ActivityTestHelper.AddTermination(displayFormWf, displayFormAs, "Option 2", "Second Exit");
            //ActivityTestHelper.AddTermination(displayFormWf, displayFormAs, timeOutExitPoint.Name, "Time-out");

            displayFormWf.Save();
            ToDelete.Add(displayFormWf.Id);
            ToDelete.Add(dummyAccount.Id);
            ToDelete.Add(dummyAccount.AccountHolder.Id);
            return(displayFormWf);
        }
Beispiel #17
0
        public void TestDisplayFormDeleteInputParameter_Bug_25116()
        {
            using (new WorkflowRunContext {
                RunTriggersInCurrentThread = true
            })
            {
                IEntity  driver = null;
                Workflow wf     = null;

                try
                {
                    WorkflowRun run, run2;


                    #region Arrange
                    var driverType = new EntityRef("test", "driver");

                    driver = Entity.Create(driverType);
                    driver.SetField("core:name", "Test Delete Driver");
                    driver.Save();

                    wf      = Entity.Create <Workflow>();
                    wf.Name = "TEST WF";
                    wf.AddDefaultExitPoint();
                    wf.AddInput <ResourceArgument>("Input", Entity.Get <EntityType>(driverType));
                    wf.InputArgumentForAction = wf.InputArguments.First();

                    var i = Entity.Create <WfExpression>();
                    i.ArgumentToPopulate = wf.InputArgumentForAction;
                    wf.ExpressionMap     = new EntityCollection <WfExpression> {
                        i
                    };
                    wf.InputArgumentForAction.PopulatedByExpression = new EntityCollection <WfExpression> {
                        i
                    };

                    var uAExitA = Entity.Create <ExitPoint>();
                    uAExitA.Name = "Exit A";
                    uAExitA.ExitPointActionSummary = "Exit A action summary";
                    uAExitA.IsDefaultExitPoint     = true;
                    uAExitA.Save();

                    var userActionA = Entity.Create <DisplayFormActivity>();
                    userActionA.Name = "A";
                    userActionA.ExitPoints.Add(uAExitA);

                    var uA = userActionA.As <WfActivity>();
                    wf.AddActivity(uA);

                    ActivityTestHelper.AddExpressionToActivityArgument(wf, uA, "Record", "[Input]");
                    ActivityTestHelper.AddExpressionToActivityArgument(wf, uA, "Wait for next form", "true");
                    ActivityTestHelper.AddExpressionToActivityArgument(wf, uA, "Hide comment field", "true");
                    ActivityTestHelper.AddExpressionToActivityArgument(wf, uA, "Record history", "false");
                    ActivityTestHelper.AddEntityExpression(wf, uA, uA.GetInputArgument("For Person"), new EntityRef("core", "administratorPerson"));
                    ActivityTestHelper.AddEntityExpression(wf, uA, uA.GetInputArgument("Form"), new EntityRef("test", "personForm"));
                    uA.Save();

                    var delete = Entity.Create <DeleteActivity>();
                    delete.Name = "Delete";

                    var d = delete.As <WfActivity>();
                    wf.AddActivity(d);

                    ActivityTestHelper.AddExpressionToActivityArgument(wf, d, "Record", "[Input]");
                    d.Save();

                    var uBExitC = Entity.Create <ExitPoint>();
                    uBExitC.Name = "Exit C";
                    uBExitC.ExitPointActionSummary = "Exit C action summary";
                    uBExitC.IsDefaultExitPoint     = true;
                    uBExitC.Save();

                    var userActionB = Entity.Create <DisplayFormActivity>();
                    userActionB.Name = "B";
                    userActionB.ExitPoints.Add(uBExitC);

                    var uB = userActionB.As <WfActivity>();
                    wf.AddActivity(uB);

                    ActivityTestHelper.AddEntityExpression(wf, uB, uB.GetInputArgument("For Person"), new EntityRef("core", "administratorPerson"));
                    uB.Save();

                    ActivityTestHelper.AddMissingExpressionParametersToWorkflow(wf);

                    wf.Save();
                    #endregion

                    // Act
                    var wfInput = new Dictionary <string, object> {
                        { "Input", driver }
                    };

                    using (new WorkflowRunContext(true))
                    {
                        run = RunWorkflow(wf, wfInput);
                    }
                    run.WorkflowRunStatus_Enum.Should().Be(WorkflowRunState_Enumeration.WorkflowRunPaused);
                    run.PendingActivity.Should().NotBeNull();
                    run.PendingActivity.Name.Should().Be("A");
                    run.TaskWithinWorkflowRun.Should().NotBeNull().And.NotBeEmpty().And.HaveCount(1);

                    var userTaskA = run.TaskWithinWorkflowRun.First().AsWritable <DisplayFormUserTask>();
                    userTaskA.AvailableTransitions.Should().NotBeNull().And.NotBeEmpty().And.HaveCount(1);
                    userTaskA.WorkflowRunForTask.Id.Should().Be(run.Id);

                    var resumeEvent = new UserCompletesTaskEvent
                    {
                        CompletionStateId = userTaskA.AvailableTransitions.First(t => t.Name == "Exit A").Id,
                        UserTaskId        = run.TaskWithinWorkflowRun.First().Id
                    };

                    using (new WorkflowRunContext(true))
                    {
                        run2 = WorkflowRunner.Instance.ResumeWorkflow(run, resumeEvent);
                    }

                    // Assert
                    run2.WorkflowRunStatus_Enum.Should().Be(WorkflowRunState_Enumeration.WorkflowRunPaused);
                    run2.PendingActivity.Should().NotBeNull();
                    run2.PendingActivity.Name.Should().Be("B");
                    run2.TaskWithinWorkflowRun.Should().NotBeNull().And.NotBeEmpty().And.HaveCount(1);

                    var deletedDriver = Entity.Exists(new EntityRef(driver.Id));
                    deletedDriver.Should().BeFalse();
                }
                finally
                {
                    if (wf != null)
                    {
                        ToDelete.Add(wf.Id);
                    }
                    if (driver != null && Entity.Exists(new EntityRef(driver.Id)))
                    {
                        ToDelete.Add(driver.Id);
                    }
                }
            }
        }
        public void EditPausedWorkflowUnderHobbledSecurityAccount_Bug_25246()
        {
            Workflow wf = null, wfClone = null;

            try
            {
                #region Arrange
                var dogBreedType = Entity.GetByName <EntityType>("AA_DogBreeds").FirstOrDefault();
                dogBreedType.Should().NotBeNull("Couldn't locate the type for dog breeds.");

                var poodle = Entity.GetByName("Poodle").FirstOrDefault();
                poodle.Should().NotBeNull("Couldn't locate poodle.");

                wf      = Entity.Create <Workflow>();
                wf.Name = "Pet the poodle.";
                wf.AddDefaultExitPoint();
                wf.AddInput <ResourceArgument>("Input", dogBreedType);
                wf.InputArgumentForAction = wf.InputArguments.First();

                var i = Entity.Create <WfExpression>();
                i.ArgumentToPopulate = wf.InputArgumentForAction;
                wf.ExpressionMap     = new EntityCollection <WfExpression> {
                    i
                };
                wf.InputArgumentForAction.PopulatedByExpression = new EntityCollection <WfExpression> {
                    i
                };

                var exitPoint = Entity.Create <ExitPoint>();
                exitPoint.Name = "Pet";
                exitPoint.IsDefaultExitPoint = true;
                exitPoint.Save();

                var userAction = Entity.Create <DisplayFormActivity>();
                userAction.Name = "Do Action";
                userAction.ExitPoints.Add(exitPoint);

                var act = userAction.As <WfActivity>();
                wf.AddActivity(act);

                ActivityTestHelper.AddExpressionToActivityArgument(wf, act, "Record", "[Input]");
                ActivityTestHelper.AddEntityExpression(wf, act, act.GetInputArgument("For Person"), new EntityRef("core", "administratorPerson"));
                act.Save();

                ActivityTestHelper.AddMissingExpressionParametersToWorkflow(wf);

                wf.Save();
                #endregion

                // Act
                using (new SetUser(Entity.Get <UserAccount>("core:administratorUserAccount")))
                {
                    // Hobbled.

                    var wfInput = new Dictionary <string, object> {
                        { "Input", poodle }
                    };

                    var run = RunWorkflow(wf, wfInput);

                    run.WorkflowRunStatus_Enum.Should().Be(WorkflowRunState_Enumeration.WorkflowRunPaused);
                    run.PendingActivity.Should().NotBeNull();
                    run.PendingActivity.Name.Should().Be("Do Action");
                    run.TaskWithinWorkflowRun.Should().NotBeNull().And.NotBeEmpty().And.HaveCount(1);

                    run.WorkflowBeingRun.Should().NotBeNull();
                    run.WorkflowBeingRun.FirstActivity.Should().NotBeNull();
                    run.WorkflowBeingRun.RunningInstances.Should().NotBeNull();
                    run.WorkflowBeingRun.RunningInstances.Count.Should().Be(1);

                    // Edit
                    WorkflowUpdateHelper.Update(wf.Id, () =>
                    {
                        var wfEdit         = Entity.Get <Workflow>(wf.Id, true).AsWritable <Workflow>();
                        wfEdit.Description = "What?";

                        var actEdit   = wfEdit.FirstActivity.AsWritable <WfActivity>();
                        actEdit.Name += "2";
                        actEdit.Save();

                        wfEdit.Save();
                    });

                    // Assert
                    var wfOriginal = Entity.Get <Workflow>(wf.Id);
                    wfOriginal.Should().NotBeNull();
                    wfOriginal.Description.Should().Be("What?");
                    wfOriginal.FirstActivity.Should().NotBeNull();
                    wfOriginal.FirstActivity.Name.Should().Be("Do Action2"); // i guess?
                    wfOriginal.RunningInstances.Should().NotBeNull().And.BeEmpty();
                    wfOriginal.WfOlderVersion.Should().NotBeNull();
                    wfOriginal.WfNewerVersion.Should().BeNull();

                    wfClone = wfOriginal.WfOlderVersion;
                    wfClone.Description.Should().BeNullOrEmpty();
                    wfClone.FirstActivity.Should().NotBeNull();
                    wfClone.FirstActivity.Name.Should().Be("Do Action");
                    wfClone.RunningInstances.Should().NotBeNull();
                    wfClone.RunningInstances.Count.Should().Be(1);
                }
            }
            finally
            {
                if (wf != null)
                {
                    ToDelete.Add(wf.Id);
                }
                if (wfClone != null)
                {
                    ToDelete.Add(wfClone.Id);
                }
            }
        }
        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.");
            }
        }
Beispiel #20
0
        public void TestMultipleNestedWorkflowActivities_Bug_24928()
        {
            using (new WorkflowRunContext {
                RunTriggersInCurrentThread = true
            })
            {
                Workflow wfA = null, wfB = null, wfC = null, wfD = null;

                #region Arrange
                var exitA = Entity.Create <ExitPoint>();
                exitA.Name = "TEST Exit A";
                exitA.IsDefaultExitPoint = true;
                exitA.Save();

                var exitB = Entity.Create <ExitPoint>();
                exitB.Name = "TEST Exit B";
                exitB.IsDefaultExitPoint = true;
                exitB.Save();

                var exitC = Entity.Create <ExitPoint>();
                exitC.Name = "TEST Exit C";
                exitC.IsDefaultExitPoint = true;
                exitC.Save();

                var exitD = Entity.Create <ExitPoint>();
                exitD.Name = "TEST Exit D";
                exitD.IsDefaultExitPoint = true;
                exitD.Save();

                wfA      = Entity.Create <Workflow>();
                wfA.Name = "TEST WF A";
                wfA.ExitPoints.Add(exitA);

                var logA = Entity.Create <LogActivity>().As <WfActivity>();
                logA.Name = "TEST Log A";
                wfA.AddActivity(logA);

                ActivityTestHelper.AddExpressionToActivityArgument(wfA, logA, "Message", "'WF A'");
                wfA.Save();

                wfB      = Entity.Create <Workflow>();
                wfB.Name = "TEST WF B";
                wfB.ExitPoints.Add(exitB);

                var logB = Entity.Create <LogActivity>().As <WfActivity>();
                logB.Name = "TEST Log B";
                wfB.AddActivity(logB);

                ActivityTestHelper.AddExpressionToActivityArgument(wfB, logB, "Message", "'WF B'");
                wfB.Save();

                wfC      = Entity.Create <Workflow>();
                wfC.Name = "TEST WF C";
                wfC.ExitPoints.Add(exitC);

                var proxyA = Entity.Create <WorkflowProxy>();
                proxyA.Name            = "TEST Run WF A";
                proxyA.WorkflowToProxy = wfA;
                var exitProxyA = Entity.Create <ExitPoint>();
                exitProxyA.Name = "TEST Exit A";
                exitProxyA.IsDefaultExitPoint = true;
                proxyA.ExitPoints.Add(exitProxyA);
                wfC.AddActivity(proxyA.As <WfActivity>());

                var logCa = Entity.Create <LogActivity>().As <WfActivity>();
                logCa.Name = "TEST Log C A";
                wfC.AddActivity(logCa);

                ActivityTestHelper.AddExpressionToActivityArgument(wfC, logCa, "Message", "'WF C A'");

                var proxyB = Entity.Create <WorkflowProxy>();
                proxyB.Name            = "TEST Run WF B";
                proxyB.WorkflowToProxy = wfB;
                var exitProxyB = Entity.Create <ExitPoint>();
                exitProxyB.Name = "TEST Exit B";
                exitProxyB.IsDefaultExitPoint = true;
                proxyB.ExitPoints.Add(exitProxyB);
                wfC.AddActivity(proxyB.As <WfActivity>());

                var logCb = Entity.Create <LogActivity>().As <WfActivity>();
                logCb.Name = "TEST Log C B";
                wfC.AddActivity(logCb);

                ActivityTestHelper.AddExpressionToActivityArgument(wfC, logCb, "Message", "'WF C B'");
                wfC.Save();

                wfD      = Entity.Create <Workflow>();
                wfD.Name = "TEST WF D";
                wfD.ExitPoints.Add(exitD);

                var proxyA2 = Entity.Create <WorkflowProxy>();
                proxyA2.Name            = "TEST Run WF A";
                proxyA2.WorkflowToProxy = wfA;
                var exitProxyA2 = Entity.Create <ExitPoint>();
                exitProxyA2.Name = "TEST Exit A";
                exitProxyA2.IsDefaultExitPoint = true;
                proxyA2.ExitPoints.Add(exitProxyA2);
                wfD.AddActivity(proxyA2.As <WfActivity>());

                var logDa = Entity.Create <LogActivity>().As <WfActivity>();
                logDa.Name = "TEST Log D A";
                wfD.AddActivity(logDa);

                ActivityTestHelper.AddExpressionToActivityArgument(wfD, logDa, "Message", "'WF D A'");

                var proxyB2 = Entity.Create <WorkflowProxy>();
                proxyB2.Name            = "TEST Run WF B";
                proxyB2.WorkflowToProxy = wfB;
                var exitProxyB2 = Entity.Create <ExitPoint>();
                exitProxyB2.Name = "TEST Exit B";
                exitProxyB2.IsDefaultExitPoint = true;
                proxyB2.ExitPoints.Add(exitProxyB2);
                wfD.AddActivity(proxyB2.As <WfActivity>());

                var logDb = Entity.Create <LogActivity>().As <WfActivity>();
                logDb.Name = "TEST Log D B";
                wfD.AddActivity(logDb);

                ActivityTestHelper.AddExpressionToActivityArgument(wfD, logDb, "Message", "'WF D B'");

                var proxyC = Entity.Create <WorkflowProxy>();
                proxyC.Name            = "TEST Run D C";
                proxyC.WorkflowToProxy = wfC;
                var exitProxyC = Entity.Create <ExitPoint>();
                exitProxyC.Name = "TEST Exit C";
                exitProxyC.IsDefaultExitPoint = true;
                proxyC.ExitPoints.Add(exitProxyC);
                wfD.AddActivity(proxyC.As <WfActivity>());

                var logDc = Entity.Create <LogActivity>().As <WfActivity>();
                logDc.Name = "TEST Log D C";
                wfD.AddActivity(logDc);

                ActivityTestHelper.AddExpressionToActivityArgument(wfD, logDc, "Message", "'WF D C'");
                wfD.Save();
                #endregion

                // Act
                WorkflowRun run;
                using (new WorkflowRunContext(true))
                {
                    run = RunWorkflow(wfD);
                }

                // Assert
                run.Should().NotBeNull();
                run.WorkflowRunStatus_Enum.Should().Be(WorkflowRunState_Enumeration.WorkflowRunCompleted);
                run.Id.Should().Be(run.Id);
                run.RunStepCounter.Should().Be(7);
            }
        }
Beispiel #21
0
        public void PassingValuesBetweenActivities( )
        {
            // This test creates a person with an age of ten and a workflow that takes the persons resource id as inputs, reads that persons age and writes it out to the log embedded in a message.
            // Testing:
            //      Mapping workflow input arguments.
            //      Mapping an output argument to a variable.
            //      Using an expression that contains an input parameter.

            var personType = CodeNameResolver.GetTypeByName("AA_Person").As <EntityType>();
            var ageField   = personType.Fields.First(f => f.Name == "Age");

            var peter = Entity.Create(personType).As <Resource>();

            peter.Name = "Peter" + DateTime.Now;

            peter.SetField(ageField, 10);
            peter.Save( );
            ToDelete.Add(peter.Id);

            var workflow = new Workflow
            {
                Name = "Wf" + DateTime.Now
            };

            workflow.AddDefaultExitPoint( );

            var resourceIdArg = new ResourceArgument
            {
                Name           = "ResourceId",
                ConformsToType = personType
            };
            var resourceIdArgAs = resourceIdArg.As <ActivityArgument>( );

            workflow.InputArguments.Add(resourceIdArg.As <ActivityArgument>( ));
            //workflow.Save( );
            var workflowAs = workflow.As <WfActivity>( );



            // log activity
            var log = new LogActivity
            {
                Name = "log" + DateTime.Now
            };
            var logAs = log.As <WfActivity>( );

            workflow.ContainedActivities.Add(logAs);
            workflow.FirstActivity = logAs;

            ActivityTestHelper.AddExpressionToActivityArgument(workflow, logAs, "Message", "'Peters age is ' + ResourceId.Age", false);

            ActivityTestHelper.AddTermination(workflow, logAs);

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

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

            var input = new Dictionary <string, object>
            {
                {
                    "ResourceId", peter
                }
            };

            var run = (RunWorkflow(workflow, input));


            Assert.AreEqual(WorkflowRunState_Enumeration.WorkflowRunCompleted, run.WorkflowRunStatus_Enum, "The workflow run and completed without error");

            //RunActivity( nextActivity, input );
        }