Exemplo n.º 1
0
        public void Workflow_GoldenPath()
        {
            using (var scope = Factory.Current.BeginLifetimeScope(builder =>
            {
                builder.RegisterType <DummyNotifier>().As <INotifier>();
            }))
                using (Factory.SetCurrentScope(scope))
                {
                    var wf = CreateNotifyWorkflow(true);

                    var person = new Person {
                        Name = "bob",
                    };
                    person.SetField("shared:businessEmail", "*****@*****.**");
                    person.Save();

                    var inputs = new Dictionary <string, object>
                    {
                        { "People", person.ToEnumerable() },
                        { "Message", "Test" }
                    };

                    WorkflowRun run1;

                    using (new TestWfRunContext())
                    {
                        run1 = (RunWorkflow(wf, inputs));
                    }

                    Assert.That(run1.WorkflowRunStatus_Enum, Is.EqualTo(WorkflowRunState_Enumeration.WorkflowRunPaused));

                    var notifications = person.GetRelationships(new EntityRef("core", "srToPerson"), Direction.Reverse);

                    Assert.That(notifications.Count(), Is.EqualTo(1));

                    var send = notifications.First().As <SendRecord>();

                    Assert.That(send.SendToNotification, Is.Not.Null);
                    Assert.That(send.SendToNotification.NMessage, Is.EqualTo("Test"));

                    using (new TestWfRunContext())
                    {
                        // reply
                        var reply = new ReplyRecord {
                            RrToSend = send, RrReply = "replying", RrReplyDate = DateTime.UtcNow
                        };
                        reply.Save();
                    }

                    var run2 = Entity.Get <WorkflowRun>(run1.Id);

                    Assert.That(run2.WorkflowRunStatus_Enum, Is.EqualTo(WorkflowRunState_Enumeration.WorkflowRunCompleted));

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

                    Assert.That(outputs.Keys, Has.Member("Notification Record"));
                    var notification = (IEntity)outputs["Notification Record"];
                    Assert.That(notification, Is.Not.Null);
                }
        }
        public void ThatTheReplyWorflowRunsAndHasCorrectInput(bool workflowHasInput)
        {
            var dummyrunner = new DummyWorkflowRunner();


            using (var scope = Factory.Current.BeginLifetimeScope(builder =>
            {
                builder.Register(ctx => dummyrunner).As <IWorkflowRunner>();
            }))
                using (Factory.SetCurrentScope(scope))
                {
                    var workflow = new Workflow {
                        WorkflowRunAsOwner = true
                    };

                    if (workflowHasInput)
                    {
                        var inputArg = new ResourceArgument {
                            Name = "myInput", ConformsToType = ReplyRecord.ReplyRecord_Type
                        };
                        workflow.InputArguments.Add(inputArg.As <ActivityArgument>());
                    }

                    var notification = new Notification();
                    notification.NReplyMapCopy.Add(new ReplyMapEntry {
                        Name = "Reply", RmeWorkflow = workflow
                    });

                    var send = new SendRecord();
                    notification.SendRecords.Add(send);

                    notification.Save();

                    int runs = 0;

                    var reply = new ReplyRecord {
                        RrToSend = send, RrReply = "Reply to anything", RrReplyDate = DateTime.UtcNow
                    };

                    dummyrunner.StartWorkflowAsyncFn = (startEvent) => {
                        runs++;
                        if (workflowHasInput)
                        {
                            Assert.That(startEvent.Arguments.Keys, Has.Member("myInput"));
                            Assert.That(startEvent.Arguments["myInput"] is IEntity, Is.True);
                            Assert.That(((IEntity)startEvent.Arguments["myInput"]).Id, Is.EqualTo(reply.Id));
                        }

                        return("1");
                    };

                    reply.Save();

                    Assert.That(runs, Is.EqualTo(1));
                }
        }