public void SuspendResume() { var handler = new RunTriggersHandler(); var trigger = new WfTriggerUserUpdatesResource(); trigger.Save(); var resource = new Resource(); resource.Save(); var task = RunTriggersHandler.CreateBackgroundTask(trigger.Id, resource.Id, 5); var taskEntity = handler.CreateSuspendedTask(task); taskEntity.Save(); var tasks = handler.RestoreSuspendedTasks(); tasks.Should().HaveCount(1); var runParam = tasks.First().GetData <RunTriggersParams>(); runParam.TriggerDepth.ShouldBeEquivalentTo(5); runParam.TriggerId.ShouldBeEquivalentTo(trigger.Id); runParam.EntityId.ShouldBeEquivalentTo(resource.Id); }
public void SetChoice( ) { var trigger = new WfTriggerUserUpdatesResource( ); trigger.Save( ); ToDelete.Add(trigger.Id); var setAction = new SetChoiceActivity( ); setAction.Save( ); ToDelete.Add(setAction.Id); var setChoiceAs = setAction.As <WfActivity>( ); ActivityImplementationBase nextActivity = setChoiceAs.CreateWindowsActivity( ); var args = new Dictionary <string, object> { { "Resource to Update", trigger }, { "Field to Update", new EntityRef("core:triggeringCondition").Entity }, { "New Value", new EntityRef("core:triggeredOnEnumCreate").Entity }, }; RunActivity(nextActivity, args); trigger = Entity.Get <WfTriggerUserUpdatesResource>(trigger.Id); Assert.IsNotNull(trigger.TriggeringCondition, "Triggering condition should be set"); Assert.AreEqual("core:triggeredOnEnumCreate", trigger.TriggeringCondition.Alias); args = new Dictionary <string, object> { { "Resource to Update", trigger }, { "Field to Update", new EntityRef("core:triggeringCondition").Entity }, { "New Value", new EntityRef("core:triggeredOnEnumUpdate").Entity }, { "Replace Existing Values", false } // should ignore this value }; RunActivity(nextActivity, args); Assert.IsNotNull(trigger.TriggeringCondition, "Triggering condition should be set"); Assert.AreEqual("core:triggeredOnEnumUpdate", trigger.TriggeringCondition.Alias); }
// [Ignore("Failing on first run in test environment.")] public void TestWorkflowRunOnReverseRelationshipUpdate() { using (new WorkflowRunContext { RunTriggersInCurrentThread = true }) { var ageField = GetPersonField("Age"); var titleRel = GetTitleRel(); var myType = CreateMyType("Type_TestWorkflowRunOnUpdate"); Workflow wf = CreateTestWorkflow("TestWorkflowRunOnRelationshipUpdate " + DateTime.Now, "990"); var updateTrigger = new WfTriggerUserUpdatesResource { WorkflowToRun = wf, // ReSharper disable SpecifyACultureInStringConversionExplicitly Name = "Test" + DateTime.Now.ToString(), // ReSharper restore SpecifyACultureInStringConversionExplicitly TriggeringCondition_Enum = TriggeredOnEnum_Enumeration.TriggeredOnEnumUpdate, TriggerEnabled = true }; var task = new DisplayFormUserTask(); var relToUpdate = Entity.Get <Relationship>("core:recordToPresent"); updateTrigger.UpdatedRelationshipsToTriggerOn.Add(relToUpdate); // a reverse relationship updateTrigger.TriggeredOnType = myType; updateTrigger.Save(); ToDelete.Add(updateTrigger.Id); ToDelete.Add(wf.Id); EntityRef employee = CreateResource(myType); var savedEmployee = Entity.Get(employee); var age = savedEmployee.GetField <int?>(ageField); Assert.AreEqual(null, age, "Age has been not been set by workflow"); var rels = savedEmployee.GetRelationships(relToUpdate); rels.Add(task); using (new WorkflowRunContext(true)) using (var ctx = DatabaseContext.GetContext(true, preventPostSaveActionsPropagating: true)) { savedEmployee.Save(); ctx.CommitTransaction(); } savedEmployee = Entity.Get(employee); var age1 = savedEmployee.GetField <int?>(ageField); Assert.That(age1, Is.EqualTo(990), "The update has not occurred and has not triggered the workflow."); } }
protected ResourceTriggerFilterDef CreateTrigger(string name, EntityType triggeredOn, Workflow wf, bool enabled = true) { var trigger = new WfTriggerUserUpdatesResource() { Name = name, TriggerEnabled = enabled, WorkflowToRun = wf, TriggeringCondition = Entity.Get <TriggeredOnEnum>("core:triggeredOnEnumCreateUpdate") }; if (triggeredOn != null) { trigger.TriggeredOnType = triggeredOn; } trigger.Save(); ToDelete.Add(trigger.Id); return(trigger.Cast <ResourceTriggerFilterDef>()); }
public void TestForceDeadlockOnWorkflowRunOnCreate() { var ageField = GetPersonField("Age"); Workflow wf = CreateTestWorkflow("TestForceDeadlockOnWorkflowRunOnCreate" + DateTime.Now, "999"); var empType = new EntityType(); empType.Name = "MyType" + DateTime.Now.Ticks; empType.Inherits.Add(GetEntityType("AA_Employee")); empType.Save(); ToDelete.Add(empType.Id); var trigger = new WfTriggerUserUpdatesResource { WorkflowToRun = wf, TriggeringCondition_Enum = TriggeredOnEnum_Enumeration.TriggeredOnEnumCreate, TriggerEnabled = true }; trigger.TriggeredOnType = empType; trigger.Save(); ToDelete.Add(trigger.Id); ToDelete.Add(wf.Id); EntityRef employeeRef = null; for (var i = 0; i < 20; i++) { // Ensure an employee triggers the workflow employeeRef = CreateResource(empType); ToDelete.Add(employeeRef.Id); } if (!WaitUntil(() => { var savedEmployee = Entity.Get(employeeRef); var age = savedEmployee.GetField <int?>(ageField); return(age == 999); }, 50, 200)) { Assert.Fail("Age has been set by workflow"); } }
// [Ignore("Failing on first run in test environment.")] public void TestWorkflowRunOnRelationshipUpdate() { using (new WorkflowRunContext { RunTriggersInCurrentThread = true }) { var ageField = GetPersonField("Age"); var titleRel = GetTitleRel(); var myType = CreateMyType("Type_TestWorkflowRunOnUpdate"); Workflow wf = CreateTestWorkflow("TestWorkflowRunOnRelationshipUpdate " + DateTime.Now, "990"); var updateTrigger = new WfTriggerUserUpdatesResource { WorkflowToRun = wf, // ReSharper disable SpecifyACultureInStringConversionExplicitly Name = "Test" + DateTime.Now.ToString(), // ReSharper restore SpecifyACultureInStringConversionExplicitly TriggeringCondition_Enum = TriggeredOnEnum_Enumeration.TriggeredOnEnumUpdate, TriggerEnabled = true }; updateTrigger.UpdatedRelationshipsToTriggerOn.Add(titleRel); updateTrigger.TriggeredOnType = myType; updateTrigger.Save(); ToDelete.Add(updateTrigger.Id); ToDelete.Add(wf.Id); EntityRef employee = CreateResource(myType); var savedEmployee = Entity.Get(employee, true); var age = savedEmployee.GetField <int?>(ageField); Assert.AreEqual(null, age, "Age has been not been set by workflow"); UpdateEmployeeRelationship(savedEmployee.Id, titleRel); savedEmployee = Entity.Get(employee); var age1 = savedEmployee.GetField <int?>(ageField); Assert.That(age1, Is.EqualTo(990), "The update has not occurred and has not triggered the workflow."); } }
public void Run() { var wf = CreateLoggingWorkflow(); wf.Save(); var trigger = new WfTriggerUserUpdatesResource { WorkflowToRun = wf }; trigger.Save(); var taskData = new RunTriggersParams { TriggerId = trigger.Id, EntityId = EntityType.EntityType_Type.Id }; RunAndTestLog(taskData, (eventLogMonitor) => { Assert.That(wf.RunningInstances.Count(), Is.EqualTo(1)); Assert.That(wf.RunningInstances.First().WorkflowRunStatus_Enum, Is.EqualTo(WorkflowRunState_Enumeration.WorkflowRunCompleted)); }); }
//[Ignore("Failing on first run in test environment.")] public void TestWorkflowRunOnCreate( ) { using (new WorkflowRunContext { RunTriggersInCurrentThread = true }) { var ageField = GetPersonField("Age"); var myType = CreateMyType("Type_TestWorkflowRunOnUpdate"); Workflow wf = CreateTestWorkflow("TestWorkflowRunOnCreate" + DateTime.Now, "995"); var trigger = new WfTriggerUserUpdatesResource { WorkflowToRun = wf, TriggeringCondition_Enum = TriggeredOnEnum_Enumeration.TriggeredOnEnumCreate, TriggerEnabled = true }; trigger.TriggeredOnType = myType; trigger.Save(); ToDelete.Add(trigger.Id); ToDelete.Add(wf.Id); // Ensure an employee triggers the workflow EntityRef employeeRef = CreateResource(myType); var savedEmployee = Entity.Get(employeeRef); var age1 = savedEmployee.GetField <int?>(ageField); Assert.That(age1, Is.EqualTo(995), "Ensure Age has not been set by workflow"); EntityRef personRef = CreateResource(Person.Person_Type); var savedPerson = Entity.Get(personRef); var age2 = savedPerson.GetField <int?>(ageField); Assert.That(age2, Is.Null, "Ensure Age has not been set by workflow"); } }
public void TestWorkflowRunOnUpdate() { using (new WorkflowRunContext { RunTriggersInCurrentThread = true }) { var emailField = GetPersonField("Email Address"); var ageField = GetPersonField("Age"); var fnField = GetPersonField("First Name"); var lnField = GetPersonField("Last Name"); var myType = CreateMyType("Type_TestWorkflowRunOnUpdate"); Workflow wf = CreateTestWorkflow("TestWorkflowRunOnUpdate" + DateTime.Now, "991"); var updateTrigger = new WfTriggerUserUpdatesResource { WorkflowToRun = wf, // ReSharper disable SpecifyACultureInStringConversionExplicitly Name = "Test" + DateTime.Now.ToString(), // ReSharper restore SpecifyACultureInStringConversionExplicitly TriggeringCondition_Enum = TriggeredOnEnum_Enumeration.TriggeredOnEnumUpdate, TriggerEnabled = true }; updateTrigger.UpdatedFieldsToTriggerOn.Add(emailField.As <Field>()); updateTrigger.TriggeredOnType = myType; updateTrigger.Save(); ToDelete.Add(updateTrigger.Id); ToDelete.Add(wf.Id); // Ensure an employee triggers the workflow var employee = Entity.Create(myType).Cast <Resource>(); employee.SetField(fnField, "Test Firstname" + DateTime.Now); employee.SetField(lnField, "Test Lastname" + DateTime.Now); employee.SetField(ageField, 1); using (var ctx = DatabaseContext.GetContext(true, preventPostSaveActionsPropagating: true)) { employee.Save(); ctx.CommitTransaction(); } ToDelete.Add(employee.Id); //Thread.Sleep(2000); // Give the workflow time to finish if it started var savedEmployee = Entity.Get(employee); var age = savedEmployee.GetField <int?>(ageField); Assert.AreEqual(1, age, "Age has been not been set by workflow"); UpdateEmployeeField(savedEmployee.Id, ageField, 10); //Thread.Sleep(2000); // Give the workflow time to finish if it started savedEmployee = Entity.Get(savedEmployee.Id); age = savedEmployee.GetField <int?>(ageField); Assert.AreEqual(10, age, "The update has occurred but has not triggered the workflow."); UpdateEmployeeField(savedEmployee.Id, emailField, "*****@*****.**"); savedEmployee = Entity.Get(employee); age = savedEmployee.GetField <int?>(ageField); Assert.That(age, Is.EqualTo(991), "The update has occurred and has triggered the workflow."); } }