public static Workflow AddEntityExpressionToVariable(this Workflow wf, string argumentName, EntityRef entityRef) { var destination = wf.Variables.First(v => v.Name == argumentName); ActivityTestHelper.AddEntityExpression(wf, wf.As <WfActivity>(), destination, entityRef); return(wf); }
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); } } }