public void TestGetFormData() { var employeeType = CodeNameResolver.GetTypeByName("AA_Employee").As <EntityType>(); var employeeForm = employeeType.DefaultEditForm; var employee = Entity.GetInstancesOfType(employeeType).FirstOrDefault(); using (var request = new PlatformHttpRequest(@"data/v1/form/data", PlatformHttpMethod.Post)) { FormDataRequest formDataRequest = new FormDataRequest { FormId = employeeForm.Id.ToString(), EntityId = employee.Id.ToString(), Query = "name, description" }; request.PopulateBody(formDataRequest); HttpWebResponse response = request.GetResponse(); var formDataResponse = request.DeserialiseResponseBody <FormDataResponse>(); Assert.IsNotNull(formDataResponse); // check that it worked (200) Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK)); } }
public void LogEmployeesAge() { using (new WorkflowRunContext { RunTriggersInCurrentThread = true }) { var wf = new Workflow() { Name = "Log Employees Age " + DateTime.Now }; wf.AddDefaultExitPoint(); EntityType type = CodeNameResolver.GetTypeByName("AA_Employee").As <EntityType>(); wf.AddVariable <ResourceListArgument>("list", "all(AA_Employee)", type) .AddForEach("foreach", "list", type) .AddLog("Log", "{{foreach_Record.Age}}", "foreach", "Loop") .AddTransition("Log", "foreach"); wf.Save(); var wfInput = new Dictionary <string, object>(); var run = (RunWorkflow(wf, wfInput)); Assert.AreEqual(WorkflowRunState_Enumeration.WorkflowRunCompleted, run.WorkflowRunStatus_Enum, "The workflow completed sucessfully."); } }
public void CreateActivityRun() { var personType = CodeNameResolver.GetTypeByName("AA_Person").As <EntityType>(); const string createdRecordArgKey = "Record"; var createActivity = new CreateActivity(); createActivity.Save(); ToDelete.Add(createActivity.Id); var nextActivity = (CreateImplementation)createActivity.As <WfActivity>().CreateWindowsActivity(); var inputs = new Dictionary <string, object> { { "Object", personType } }; IDictionary <string, object> result = RunActivity(nextActivity, inputs); Assert.AreEqual(2, result.Count, "There are two results, and exit point + a value"); Assert.IsTrue(result.ContainsKey(createdRecordArgKey)); var resourceId = (IEntity)result[createdRecordArgKey]; ToDelete.Add(resourceId.Id); var person = Entity.Get(resourceId.Id); Assert.IsNotNull(person, "We have a person"); }
public void GetResourceByReport( ) { var personReport = CodeNameResolver.GetInstance("AA_Person", "Report"); var getResources = new GetResourcesActivity( ); getResources.Save( ); //_toDelete.Add(getResources.Id); var getResourcesAs = getResources.As <WfActivity>( ); ActivityImplementationBase nextActivity = getResourcesAs.CreateWindowsActivity( ); var args = new Dictionary <string, object> { { "Report", personReport }, }; IDictionary <string, object> result = RunActivity(nextActivity, args); var list = result["List"] as IEnumerable <IEntity>; var first = result["First"]; var personType = CodeNameResolver.GetTypeByName("AA_Person").As <EntityType>(); long countPeople = personType.GetDescendantsAndSelf().SelectMany(t => t.InstancesOfType).Select(i => i.Id).Distinct().Count(); Assert.IsNotNull(list); Assert.AreEqual(list.Count( ), countPeople, "The count of people is correct"); }
//[Ignore("This test is the same as the failing intg workflow tests '610' and '620' due to the enforcement of cardinality. The problem is that the assignment of a relationship is not clearing the old relationship if the cardinality does not permit it.")] public void ReassignReportDuringManagerCreate() { var aaManager = CodeNameResolver.GetTypeByName("AA_Manager").As <EntityType>(); var reportsTo = Entity.Get <Relationship>(new EntityRef("test:reportsTo")); var oldMgr = new Entity(aaManager); oldMgr.Save(); ToDelete.Add(oldMgr.Id); var employee1 = CreateEmployee(oldMgr, reportsTo); var employee2 = CreateEmployee(oldMgr, reportsTo); var createActivity = new CreateActivity(); createActivity.InputArguments.Add(new ResourceArgument { Name = "1" }.Cast <ActivityArgument>()); createActivity.InputArguments.Add(new ResourceArgument { Name = "1_value_" }.Cast <ActivityArgument>()); createActivity.InputArguments.Add(new BoolArgument { Name = "1_reverse" }.Cast <ActivityArgument>()); createActivity.InputArguments.Add(new BoolArgument { Name = "1_replace" }.Cast <ActivityArgument>()); createActivity.Save(); ToDelete.Add(createActivity.Id); var nextActivity = (CreateImplementation)createActivity.As <WfActivity>().CreateWindowsActivity(); var inputs = new Dictionary <string, object> { { "Object", aaManager }, { "1_value_", new List <Entity>() { employee1, employee2 } }, { "1", reportsTo }, { "1_reverse", true }, { "1_replace", true } }; RunActivity(nextActivity, inputs); }
public void Bug_25770_AssigningWithNull() { var aaManager = CodeNameResolver.GetTypeByName("AA_Manager").As <EntityType>(); var reportsTo = Entity.Get <Relationship>(new EntityRef("test:reportsTo")); var createActivity = new CreateActivity(); createActivity.InputArguments.Add(new ResourceArgument { Name = "1" }.Cast <ActivityArgument>()); createActivity.InputArguments.Add(new ResourceArgument { Name = "1_value_" }.Cast <ActivityArgument>()); createActivity.InputArguments.Add(new BoolArgument { Name = "1_reverse" }.Cast <ActivityArgument>()); createActivity.InputArguments.Add(new BoolArgument { Name = "1_replace" }.Cast <ActivityArgument>()); createActivity.Save(); ToDelete.Add(createActivity.Id); var nextActivity = (CreateImplementation)createActivity.As <WfActivity>().CreateWindowsActivity(); var inputs = new Dictionary <string, object> { { "Object", aaManager }, { "1_value_", new List <Entity>() { null } // NULL (This was a side effect of a problem in the expression engine) }, { "1", reportsTo }, { "1_reverse", true }, { "1_replace", true } }; RunActivity(nextActivity, inputs); }
public void TestGetForm_ById( ) { var employeeType = CodeNameResolver.GetTypeByName("AA_Employee").As <EntityType>( ); var employeeForm = employeeType.DefaultEditForm; using ( var request = new PlatformHttpRequest(string.Format(@"data/v1/form/{0}", employeeForm.Id))) { HttpWebResponse response = request.GetResponse( ); // check that it worked (200) Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK)); } }
Entity CreateEmployee(Entity oldMgr, Relationship reportsTo) { var aaEmployee = CodeNameResolver.GetTypeByName("AA_Employee").As <EntityType>(); var employee = new Entity(aaEmployee); employee.Save(); var rel = employee.GetRelationships(reportsTo); rel.Add(oldMgr); employee.Save(); ToDelete.Add(employee.Id); return(employee); }
public void UpdateField() { var employeeType = CodeNameResolver.GetTypeByName("AA_Person").As <EntityType>(); var ageField = employeeType.Fields.First(f => f.Name == "Age"); var bob = new Entity(employeeType); bob.Save(); ToDelete.Add(bob.Id); var updateActivity = new UpdateFieldActivity(); updateActivity.InputArguments.Add(new ResourceArgument { Name = "1" }.Cast <ActivityArgument>()); updateActivity.InputArguments.Add(new IntegerArgument { Name = "1_value" }.Cast <ActivityArgument>()); updateActivity.Save(); ToDelete.Add(updateActivity.Id); var updateActionAs = updateActivity.As <WfActivity>(); ActivityImplementationBase nextActivity = updateActionAs.CreateWindowsActivity(); var args = new Dictionary <string, object> { { "Record", bob }, { "1_value", 32 }, { "1", (new EntityRef(ageField.Id)).Entity } }; RunActivity(nextActivity, args); Entity.Get(bob); var age = (int?)bob.GetField(ageField); Assert.AreEqual(32, age); }
public string CreateQueryXml(string script, string rootType1) { EntityRef rootType; if (rootType1.StartsWith("name:")) { rootType = new EntityRef(CodeNameResolver.GetTypeByName(rootType1.Substring(5))); } else { rootType = (EntityRef)rootType1; // cast alias string } StructuredQuery query = CreateQuery(script, rootType); string xml = Serializer <StructuredQuery> .ToXml(query); string xml2 = CleanXml(xml); return(xml2); }
private Workflow CreateTestWf() { var person = CodeNameResolver.GetTypeByName("AA_Person").As <EntityType>(); var ageField = person.Fields.First(f => f.Name == "Age"); var wf = new Workflow { Name = "Test" }; wf.AddDefaultExitPoint() .AddInput <ResourceArgument>("ResourceId") .AddUpdateField("Update Field", ageField.As <Resource>(), "ResourceId", "13"); wf.InputArgumentForAction = wf.InputArguments.First(); wf.Save(); ToDelete.Add(wf.Id); return(wf); }
public void TestGetForm_DoesNotReturnCalculations() { var calcTestType = CodeNameResolver.GetTypeByName("AA_Calculations").As <EntityType>(); var calcTestForm = calcTestType.DefaultEditForm; using ( var request = new PlatformHttpRequest(string.Format(@"data/v1/form/{0}", calcTestForm.Id))) { HttpWebResponse response = request.GetResponse(); // check that it worked (200) Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK)); using (Stream stream = response.GetResponseStream()) using (TextReader reader = new StreamReader(stream)) { string json = reader.ReadToEnd(); Assert.That(json, Contains.Substring("isCalculatedField")); Assert.That(json, Is.Not.ContainsSubstring("fieldCalculation")); } } }
public void TestGetInstance_NoDefaultForm( ) { EntityType myDef = null; try { var personType = CodeNameResolver.GetTypeByName("AA_Person").As <EntityType>( ); myDef = new EntityType( ); myDef.Inherits.Add(personType); myDef.Save( ); IEntity myInst = Entity.Create(myDef.Id); myInst.Save( ); using ( var request = new PlatformHttpRequest(string.Format(@"data/v1/instance/{0}", myInst.Id))) { HttpWebResponse response = request.GetResponse( ); // check that it worked (200) Assert.IsTrue(response.StatusCode == HttpStatusCode.OK); } } finally { try { if (myDef != null) { myDef.Delete( ); } } catch (Exception exc) { EventLog.Application.WriteError(exc.ToString( )); } } }
private static EntityType GetEntityType(string name) { return(CodeNameResolver.GetTypeByName(name).As <EntityType>()); }
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 ); }