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));
                }
        }
        public void CampaignWithSurveyCompleteTrigger()
        {
            var            workflow = Entity.Create <Workflow>();
            SurveyCampaign campaign = CreateSurveyPersonCampaign().AsWritable <SurveyCampaign>();

            var survey = campaign.SurveyForCampaign.AsWritable <UserSurvey>();

            survey.SurveyTriggerOnSurveyComplete = workflow;

            survey.Save();


            var dummyRunner = new DummyWorkflowRunner();


            using (var scope = Factory.Current.BeginLifetimeScope(builder =>
            {
                builder.Register(ctx => dummyRunner).As <IWorkflowRunner>();
            }))
                using (Factory.SetCurrentScope(scope))
                {
                    int runCount = 0;
                    dummyRunner.StartWorkflowAsyncFn = (dummyWf, args) =>
                    {
                        Assert.That(dummyWf.Id, Is.EqualTo(workflow.Id));
                        Assert.That(args.Keys, Contains.Item("Input"));

                        var inputEntity = args["Input"] as IEntity;
                        Assert.That(inputEntity.Id, Is.EqualTo(campaign.SurveyResponses.First().Id));

                        runCount++;
                        return("111");
                    };

                    var task = campaign.SurveyResponses.First().UserSurveyTaskForResults.First().AsWritable <UserSurveyTask>();

                    task.UserTaskIsComplete = true;
                    task.TaskStatus_Enum    = TaskStatusEnum_Enumeration.TaskStatusCompleted;
                    var taskId = task.Id;
                    task.Save();

                    //Thread.Sleep(1000);

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