ExprType TypeFromInstance(WfArgumentInstance ai)
 {
     if (ai.InstanceConformsToType != null)
     {
         if (ai.ArgumentInstanceArgument.Is <ResourceArgument>())
         {
             return(ExprTypeHelper.EntityOfType(ai.InstanceConformsToType));
         }
         else
         {
             return(ExprTypeHelper.EntityListOfType(ai.InstanceConformsToType));
         }
     }
     else
     {
         return(CalcExpressionType(ai.ArgumentInstanceArgument));
     }
 }
Beispiel #2
0
        public void Test_CountFromParam_26597(string script, int expect)
        {
            // Schema
            string     typeName = Guid.NewGuid().ToString();
            EntityType type     = new EntityType();

            type.Name = typeName;
            type.Save();
            EntityType type2 = new EntityType();

            type2.Name = typeName + "B";
            type2.Save();
            Relationship rel = new Relationship();

            rel.Cardinality_Enum = CardinalityEnum_Enumeration.ManyToMany;
            rel.FromType         = type;
            rel.ToType           = type2;
            rel.ToName           = "Risk";
            rel.Save();

            // Instance
            Resource instance = Entity.Create(type.Id).As <Resource>();

            instance.Name = "TestInstance";
            instance.Save();

            // Compile
            BuilderSettings settings = new BuilderSettings();

            settings.ParameterNames = new List <string> {
                "Input"
            };
            settings.StaticParameterResolver = param => ExprTypeHelper.EntityListOfType(new EntityRef(type.Id));
            IExpression expr = Factory.ExpressionCompiler.Compile(script, settings);

            // Run
            EvaluationSettings eval = new EvaluationSettings();

            eval.ParameterResolver = param => instance;
            var result = Factory.ExpressionRunner.Run(expr, eval);

            // Check
            Assert.That(result.Value, Is.EqualTo(expect));
        }