Ejemplo n.º 1
0
        public void GetContentNodesFromExecutionResult()
        {
            QuestionArgs argsret    = null;
            var          controller = new YamlScriptController();

            controller.QuestionCallback = (FormulaExpressionContext sender, QuestionArgs args) =>
            {
                argsret = args;
            };
            var result     = controller.Parse(YamlTestFileLoader.Load(@"Zorgtoeslag5.yaml"));
            var parameters = new ParametersCollection()
            {
                new ClientParameter("woonland", "Nederland", TypeInference.InferenceResult.TypeEnum.List, "Dummy")
            } as IParametersCollection;
            var executionResult = new ExecutionResult(ref parameters) as IExecutionResult;

            try
            {
                controller.ExecuteWorkflow(ref parameters, ref executionResult);
            }
            catch (UnresolvedException ex)
            {
            }
            Assert.Equal(35, executionResult.ContentNodes.Count());
            Assert.Equal("stap.woonsituatie.keuze.alleenstaande",
                         executionResult.ContentNodes.FirstOrDefault(c => c.Parameter.Name == argsret.Parameters.ToList()[0].Name).Parameter.SemanticKey);
            Assert.Equal("stap.woonsituatie.keuze.aanvrager_met_toeslagpartner",
                         executionResult.ContentNodes.FirstOrDefault(c => c.Parameter.Name == argsret.Parameters.ToList()[1].Name).Parameter.SemanticKey);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> ExecuteRuleYaml([FromBody] ExecuteRuleYamlFromUriRequest request)
        {
            return(StatusCode(500, new ServerError500Response(new NotImplementedException())));

            var controller = new YamlScriptController();
            var response   = new ExecuteRuleYamlFromUriResponse();
            var parameters = request.ClientParameters.Adapt <IParametersCollection>();

            controller.QuestionCallback = (FormulaExpressionContext sender, QuestionArgs args) =>
            {
            };

            var downloadResult = request.Endpoint.DownloadYaml();
            var result         = controller.Parse(downloadResult.Content);

            // map the parsing result.


            if (result.IsError)
            {
                return(StatusCode(400, response));
            }
            ;
            var executionResult = new ExecutionResult(ref parameters) as IExecutionResult;

            controller.ExecuteWorkflow(ref parameters, ref executionResult);

            return(StatusCode(200, new ExecuteRuleYamlFromUriResponse()));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> GenerateContentTemplate(Uri url)
        {
            try
            {
                var ret = await Download(url);

                if (ret.StatusCode != 200)
                {
                    return(ret);
                }

                var yaml = ret.Value.ToString();
                YamlScriptController controller = new YamlScriptController();
                var         result      = controller.Parse(yaml);
                ParseResult parseResult = new ParseResult()
                {
                };
                if (result.IsError)
                {
                    return(StatusCode(400, parseResult));
                }

                return(StatusCode(200, controller.CreateYamlContentTemplate()));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, new ServerError500Response(ex)));
            }
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> ValidateRuleYaml(Uri url)
        {
            try
            {
                var ret = await Download(url);

                if (ret.StatusCode != 200)
                {
                    return(ret);
                }
                YamlScriptController controller = new YamlScriptController();
                var         yaml        = ret.Value.ToString();
                var         result      = controller.Parse(yaml);
                ParseResult parseResult = new ParseResult()
                {
                    IsError = result.IsError,
                    Message = result.Message
                };
                return(StatusCode(200, parseResult));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, new ServerError500Response(ex)));
            }
        }
Ejemplo n.º 5
0
        public void ExecutionResultHasCorrectSemanticKeyOnGeenRecht()
        {
            QuestionArgs argsret    = null;
            var          controller = new YamlScriptController();

            controller.QuestionCallback = (FormulaExpressionContext sender, QuestionArgs args) =>
            {
                argsret = args;
            };
            var result     = controller.Parse(YamlTestFileLoader.Load(@"Zorgtoeslag5.yaml"));
            var parameters = new ParametersCollection()
            {
                new ClientParameter("woonland", "Anders", TypeInference.InferenceResult.TypeEnum.List, "Dummy")
            } as IParametersCollection;
            var executionResult = new ExecutionResult(ref parameters) as IExecutionResult;

            try
            {
                controller.ExecuteWorkflow(ref parameters, ref executionResult);
            }
            catch (UnresolvedException ex)
            {
            }
            Assert.Equal("stap.woonland", executionResult.Step.SemanticKey);
            Assert.Equal("stap.woonland.geen_recht", executionResult.Step.Break.SemanticKey);
            Assert.True(executionResult?.Parameters?.Any(p => p.Name == "recht" && !(bool)p.Value));
        }
        public async Task <ExecutionResult> Execute(string yaml, IParametersCollection parameters)
        {
            await _parameters.ReadStateAsync();

            var state = _parameters.State as IParametersCollection;


            var executionResult = new ExecutionResult(ref parameters) as IExecutionResult;

            var controller = new YamlScriptController();

            controller.QuestionCallback = (sender, args) =>
            {
                executionResult.Questions = args;
            };
            var result = controller.Parse(yaml);

            executionResult = new ExecutionResult(ref parameters);
            try
            {
                controller.ExecuteWorkflow(ref state, ref executionResult);
            }
            catch (UnresolvedException) { }
            _parameters.State = executionResult.Parameters as ParametersCollection;
            await _parameters.WriteStateAsync();

            return(executionResult as ExecutionResult);
        }
Ejemplo n.º 7
0
        public void CanParseChoices()
        {
            var controller = new YamlScriptController();
            var result     = controller.Parse(YamlTestFileLoader.Load(@"Zorgtoeslag4.yaml"));

            Assert.False(result.IsError);
        }
Ejemplo n.º 8
0
        void Formula_Can_Execute_FormulaExpressionContext()
        {
            var controller = new YamlScriptController();

            controller.QuestionCallback = (FormulaExpressionContext sender, QuestionArgs args) =>
            {
                // should not be called.
                throw new Exception("Questioncallback should not be called.");
            };
            var result     = controller.Parse(YamlTestFileLoader.Load(@"Rijksoverheid/Zorgtoeslag.yaml"));
            var parameters = new ParametersCollection()
            {
                new ClientParameter("alleenstaande", "ja", TypeInference.InferenceResult.TypeEnum.Boolean, "Dummy"),
                new ClientParameter("woonland", "Nederland", TypeInference.InferenceResult.TypeEnum.List, "Dummy"),
                new ClientParameter("toetsingsinkomen_aanvrager", (double)19000, TypeInference.InferenceResult.TypeEnum.Double, "Dummy"),
                new ClientParameter("toetsingsinkomen_toeslagpartner", (double)0, TypeInference.InferenceResult.TypeEnum.Double, "Dummy")
            } as IParametersCollection;
            var model     = result.Model;
            var context   = new FormulaExpressionContext(ref model, ref parameters, controller.GetFormula("normpremie"), controller.QuestionCallback, controller);
            var parameter = context.Evaluate();

            Assert.True(parameter.Name == "normpremie");
            Assert.True((double)parameter.Value == 419.86704999999995);
            Assert.True(parameters.Count == 7);
        }
Ejemplo n.º 9
0
        public void ShouldAcceptWaarde()
        {
            var controller  = new YamlScriptController();
            var parseResult = controller.Parse(_testYaml1);

            Assert.False(parseResult.IsError);
        }
Ejemplo n.º 10
0
        void Formula_Can_Execute_FormulaExpressionContext_UsingQuestionAnswer()
        {
            var controller = new YamlScriptController();
            var result     = controller.Parse(YamlTestFileLoader.Load(@"Rijksoverheid/Zorgtoeslag.yaml"));
            var parameters = new ParametersCollection()
            {
                new ClientParameter("alleenstaande", "ja", TypeInference.InferenceResult.TypeEnum.Boolean, "Dummy"),
                new ClientParameter("woonland", "Nederland", TypeInference.InferenceResult.TypeEnum.List, "Dummy"),
                new ClientParameter("toetsingsinkomen_toeslagpartner", (double)0, TypeInference.InferenceResult.TypeEnum.Double, "Dummy")
            } as IParametersCollection;
            var  model  = result.Model;
            bool called = false;

            OnQuestion = (FormulaExpressionContext sender, QuestionArgs args) =>
            {
                Assert.True(args.Parameters[0].Name == "toetsingsinkomen_aanvrager");
                called = true;
            };
            var  context             = new FormulaExpressionContext(ref model, ref parameters, controller.GetFormula("normpremie"), OnQuestion, controller);
            bool unresolvedException = false;

            try
            {
                var parameter = context.Evaluate();
            }
            catch (UnresolvedException)
            {
                unresolvedException = true;
            }
            Assert.True(called);
            Assert.True(unresolvedException);
        }
Ejemplo n.º 11
0
        public void ShouldReturnBooleanAsFirstQuestionNewSituation()
        {
            var isException = false;

            //prepare the result
            var parameters      = new ParametersCollection() as IParametersCollection;
            var executionResult = new ExecutionResult(ref parameters) as IExecutionResult;

            //prepare yaml definition
            var controller = new YamlScriptController();

            controller.Parse(_testYaml2);
            //set the callback
            controller.QuestionCallback = (FormulaExpressionContext sender, QuestionArgs args) =>
            {
                executionResult.Questions = args;
            };

            try
            {
                controller.ExecuteWorkflow(ref parameters, ref executionResult);
            }
            catch (UnresolvedException)
            {
                isException = true;
            }

            Assert.True(isException);
            Assert.Empty(executionResult.Parameters);
            Assert.Equal(2, executionResult.Questions.Parameters.Count);
            Assert.Equal("A", executionResult.Questions.Parameters[0].Name);
            Assert.Equal("B", executionResult.Questions.Parameters[1].Name);
            Assert.Single(executionResult.Stacktrace);
            Assert.Equal("Test A of B", executionResult.Stacktrace.First().Step.Description);
        }
Ejemplo n.º 12
0
        public void ShouldAcceptKeuze()
        {
            //List<ParametersCollection> parameters = new List<ParametersCollection>();
            var controller  = new YamlScriptController();
            var parseResult = controller.Parse(_testYaml1);

            Assert.False(parseResult.IsError);
        }
Ejemplo n.º 13
0
        public static Model GetDefaultTestModel()
        {
            var controller = new YamlScriptController();
            var result     = controller.Parse(YamlTestFileLoader.Load(@"Zorgtoeslag5.yaml"));

            Assert.False(result.IsError);
            return(result.Model);
        }
Ejemplo n.º 14
0
        public void Model_Parse_Yaml_To_Model()
        {
            var controller = new YamlScriptController();
            var result     = controller.Parse(YamlTestFileLoader.Load(@"Rijksoverheid/Zorgtoeslag.yaml"));

            Assert.True(controller.GetSituation("standaardpremie", "alleenstaande").Expression == "1609");
            Assert.True(controller.GetSituation("maximaalvermogen", "aanvrager_met_toeslagpartner").Expression == "145136");
        }
Ejemplo n.º 15
0
        void Formula_Can_Discover_Parameters_And_InferedTypes_From_Yaml()
        {
            var controller = new YamlScriptController();
            var result     = controller.Parse(YamlTestFileLoader.Load(@"WettelijkeRente.yaml"));

            Assert.False(result.IsError);
            var parameters = controller.GetFunctionTree(controller);

            Assert.True(parameters.Count == 4);
        }
Ejemplo n.º 16
0
        void Formula_Can_Discover_Parameters_From_Yaml()
        {
            var controller = new YamlScriptController();
            var result     = controller.Parse(YamlTestFileLoader.Load(@"Rijksoverheid/Zorgtoeslag.yaml"));

            Assert.False(result.IsError);
            var parameters = controller.GetFunctionTree(controller);

            Assert.True(parameters.Count == 9);
        }
Ejemplo n.º 17
0
        public void ShouldStillReadDescription()
        {
            var controller  = new YamlScriptController();
            var parseResult = controller.Parse(_testYaml1);

            Assert.Single(parseResult.Model.Steps);
            var stepToTest = parseResult.Model.Steps.First();

            Assert.Equal("toetsingsinkomen", stepToTest.Name);
            Assert.Equal("toetsingsinkomen", stepToTest.Description);
        }
Ejemplo n.º 18
0
        public void ShouldGenerateAValidContentYamlTemplate()
        {
            var controller = new YamlScriptController();

            var result = controller.Parse(YamlTestFileLoader.Load(@"Zorgtoeslag5.yaml"));

            Assert.False(result.IsError);
            var template = controller.CreateYamlContentTemplate();

            Assert.False(string.IsNullOrEmpty(template));
        }
Ejemplo n.º 19
0
        public void ShouldNotNeedDescription()
        {
            //List<ParametersCollection> parameters = new List<ParametersCollection>();
            var controller  = new YamlScriptController();
            var parseResult = controller.Parse(_testYaml2);

            Assert.Single(parseResult.Model.Steps);
            var stepToTest = parseResult.Model.Steps.First();

            Assert.Equal("Test A of B", stepToTest.Name);
            Assert.Equal("Test A of B", stepToTest.Description);
        }
Ejemplo n.º 20
0
        public void Flow_ZorgToeslag_2019_Scenario1_Condition_Branche_Test()
        {
            var controller = new YamlScriptController();
            var result     = controller.Parse(YamlTestFileLoader.Load(@"Rijksoverheid/Zorgtoeslag.yaml"));
            var parameters = new ParametersCollection();

            parameters.Add(new ClientParameter("woonland", "Nederland", TypeInference.InferenceResult.TypeEnum.List, "Dummy"));
            //  var executionResult = controller.ExecuteWorkflow(parameters);
            // Tsjechië,            0.2412
            // context.Variables.Add("woonland", "Tsjechië");
            // var formula = controller.GetFormula("woonlandfactor");
        }
Ejemplo n.º 21
0
        public void ShouldHaveTwoChoices()
        {
            //List<ParametersCollection> parameters = new List<ParametersCollection>();
            var controller  = new YamlScriptController();
            var parseResult = controller.Parse(_testYaml2);

            Assert.Single(parseResult.Model.Steps);
            var stepToTest = parseResult.Model.Steps.First();

            Assert.Equal(2, stepToTest.Choices.Count());
            Assert.Equal("A", stepToTest.Choices.ElementAt(0).Situation);
            Assert.Equal("B", stepToTest.Choices.ElementAt(1).Situation);
        }
Ejemplo n.º 22
0
        public void CanDetermineTableLookupValueFromQuestion()
        {
            var controller = new YamlScriptController();
            var result     = controller.Parse(YamlTestFileLoader.Load(@"TableTests.yaml"));

            Assert.False(result.IsError);
            var parameters = new ParametersCollection() as IParametersCollection;

            controller.QuestionCallback = (FormulaExpressionContext sender, QuestionArgs args) =>
            {
                Assert.True(args.Parameters[0].Name == "woonland");
                Assert.True(args.Parameters[0].Type == TypeInference.InferenceResult.TypeEnum.List);
                // This list can be used to do a selection of a valid woonland
                Assert.True(((List <object>)args.Parameters[0].Value).Count > 0);
                // Provide an anwser by selecting an item: Finland from the list
                parameters.Add(new ClientParameter(args.Parameters[0].Name,
                                                   ((List <object>)args.Parameters[0].Value)[1], TypeInference.InferenceResult.TypeEnum.List, "Dummy"));
            };
            var executionResult = new ExecutionResult(ref parameters) as IExecutionResult;

            try
            {
                var workflow = controller.ExecuteWorkflow(ref parameters, ref executionResult);
            }
            catch (UnresolvedException)
            {
                // The server lookup needs to be evaluated again to get the resulting woonlandfactor.
                // In this case the client will not need to have to answer another question.
                // Maybe this can be put in core, in order to make the client logic simpler.
                var evaluateAgain = controller.ExecuteWorkflow(ref parameters, ref executionResult);
            }
            Assert.True(parameters[0].Name == "woonland");
            Assert.True((string)parameters[0].Value == "Finland");
            Assert.True(parameters[1].Name == "woonlandfactor");
            Assert.True((double)parameters[1].Value == 0.7161);
            Assert.True(parameters[2].Name == "recht");
            Assert.True((bool)parameters[2].Value == true);

            // Quick Hack to see if recht is false by selecting woonland: Anders
            parameters.Clear();
            parameters.Add(new ClientParameter("woonland", "Anders", TypeInference.InferenceResult.TypeEnum.List, "Dummy"));
            var recalculate = controller.ExecuteWorkflow(ref parameters, ref executionResult);

            Assert.True(parameters[0].Name == "woonland");
            Assert.True((string)parameters[0].Value == "Anders");
            Assert.True(parameters[1].Name == "woonlandfactor");
            Assert.True((double)parameters[1].Value == 0);
            Assert.True(parameters[2].Name == "recht");
            Assert.True((bool)parameters[2].Value == false);
            Assert.NotNull(recalculate.Stacktrace.FindLast(p => p.IsStopExecution == true));
        }
Ejemplo n.º 23
0
        public async Task <IActionResult> DebugRuleYamlContents([FromBody] DebugRuleYamlFromContentRequest request)
        {
            var response   = new DebugRuleYamlFromContentResponse();
            var controller = new YamlScriptController();
            var result     = controller.Parse(request.Yaml);

            if (result.IsError)
            {
                response.ParseResult = new ParseResult();
                response.ParseResult.FormattingExceptions = result.Exceptions.Exceptions.Adapt <List <Dto.Exceptions.FormattingException> >();
                response.ExecutionStatus = ExecuteRuleYamlResultTypes.SyntaxError;
                return(StatusCode(200, response));
            }
            // No Errors found.
            return(StatusCode(404, response));
        }
Ejemplo n.º 24
0
        public async Task <IActionResult> ExecuteRuleYamlContents([FromBody] ExecuteRuleYamlFromContentRequest request)
        {
            if (String.IsNullOrEmpty(request.Yaml))
            {
                return(StatusCode(400, null));
            }
            var controller = new YamlScriptController();
            var response   = new ExecuteRuleYamlFromContentResponse();
            var parameters = request.ClientParameters.Adapt <IParametersCollection>();

            if (parameters is null)
            {
                parameters = new ParametersCollection();
            }
            IExecutionResult executionResult = null;

            controller.QuestionCallback = (FormulaExpressionContext sender, QuestionArgs args) =>
            {
                executionResult.Questions = args;
            };
            var result = controller.Parse(request.Yaml);

            if (result.IsError)
            {
                response.ParseResult = new ParseResult();
                response.ParseResult.FormattingExceptions = result.Exceptions.Exceptions.Adapt <List <Dto.Exceptions.FormattingException> >();
                response.ExecutionStatus = ExecuteRuleYamlResultTypes.SyntaxError;

                return(StatusCode(400, response));
            }
            executionResult = new ExecutionResult(ref parameters);
            try
            {
                executionResult = controller.ExecuteWorkflow(ref parameters, ref executionResult);
            }
            catch (UnresolvedException)
            {
            }
            if (executionResult.IsError)
            {
                response.ExecutionStatus = ExecuteRuleYamlResultTypes.Ok;
                return(StatusCode(400, response));
            }
            response.Questions        = executionResult.Questions.Parameters.Adapt <IEnumerable <ServerParameter> >();
            response.ServerParameters = executionResult.Parameters.Adapt <IEnumerable <ServerParameter> >();
            return(StatusCode(200, response));
        }
Ejemplo n.º 25
0
        public void StuurInformatieTest()
        {
            var controller = new YamlScriptController();
            var result     = controller.Parse(YamlTestFileLoader.Load(@"Rijksoverheid/Zorgtoeslag.yaml"));

            Assert.False(result.IsError);
            var header = controller.GetHeader();

            Assert.True(header.Onderwerp == "zorgtoeslag");
            Assert.True(header.Organisatie == "belastingdienst");
            Assert.True(header.Type == "toeslagen");
            Assert.True(header.Domein == "zorg");
            Assert.True(header.Versie == "1.0");
            Assert.True(header.Status == "ontwikkel");
            Assert.True(header.Jaar == "2019");
            Assert.True(header.Bron == "https://download.belastingdienst.nl/toeslagen/docs/berekening_zorgtoeslag_2019_tg0821z91fd.pdf");
        }
Ejemplo n.º 26
0
 public async void ShouldReturnDebugInformation(string yamlFile)
 {
     // IMPORTANT please the nl-NL language at the end of the collection, as other
     // tests are primarily tested under nl-NL yaml test files.
     foreach (var language in new[] { "nl-NL", "en-US" })
     {
         Globalization.SetKeywordResourceCulture(new System.Globalization.CultureInfo(language));
         Globalization.SetFormattingExceptionResourceCulture(new System.Globalization.CultureInfo(language));
         var controller = new YamlScriptController();
         var result     = controller.Parse(YamlTestFileLoader.Load($"Malformed/{language}/{yamlFile}.yaml"));
         Assert.True(result.IsError);
         Assert.NotNull(result.Exceptions);
         Assert.NotNull(result.Message);
         Assert.True(result.Exceptions.Exceptions.Count == 1);
         Assert.NotNull(result.Exceptions.Exceptions[0].DebugInfo);
         Output.WriteLine($"{language} message: {result.Message} {result.Exceptions.Exceptions[0].DebugInfo}");
     }
 }
Ejemplo n.º 27
0
        void Formula_Table_Lookup_Test()
        {
            // -naam: woonlandfactoren
            //  woonland, factor:
            //  - [Finland, 0.7161]
            var controller            = new YamlScriptController();
            var result                = controller.Parse(YamlTestFileLoader.Load(@"Rijksoverheid/Zorgtoeslag.yaml"));
            ExpressionContext context = new ExpressionContext(controller);

            //  Tsjechië,            0.2412
            context.Variables.Add("woonland", "Tsjechië");
            var formula = controller.GetFormula("woonlandfactor");
            //  select(string tableName, string lookupValue, string lookupColumn, string resultColumn)
            IDynamicExpression e       = context.CompileDynamic(formula.Functions[0].Expression);
            double             result1 = (double)e.Evaluate();

            Assert.True(result1 == 0.2412);
        }
Ejemplo n.º 28
0
        public void MinimalCompilationTest()
        {
            var controller = new YamlScriptController();
            var result     = controller.Parse(File.OpenText(@"../../../minimal.yaml").ReadToEnd());
            //var p = parser.Flow();
            StringBuilder i = new StringBuilder(); // grain interface.
            StringBuilder p = new StringBuilder(); // grain persistence.

            var m = result.Model;

            i.AppendLine($"public interface {m.Header.Onderwerp} : IGrainWithStringKey {{");
            p.AppendLine("using System;");
            p.AppendLine($"namespace {m.Header.Organisatie.ToPascalCase()}.{m.Header.Domein.ToPascalCase()}.{m.Header.Type.ToPascalCase()}.{m.Header.Onderwerp.ToPascalCase()} {{");
            p.AppendLine($"[Serializable]public class {m.Header.Onderwerp}_state {{");
            p.AppendLine($"public const string hBron = \"{m.Header.Bron}\";");
            p.AppendLine($"public const string hDomein = \"{m.Header.Domein}\";");
            p.AppendLine($"public const string hPeriode = \"{m.Header.Jaar}\";");
            p.AppendLine($"public const string hOnderwerp = \"{m.Header.Onderwerp}\";");
            p.AppendLine($"public const string hOrganisatie = \"{m.Header.Organisatie}\";");
            p.AppendLine($"public const string hStatus = \"{m.Header.Status}\";");
            p.AppendLine($"public const string hType = \"{m.Header.Type}\";");
            p.AppendLine($"public const string hVersie = \"{m.Header.Versie}\";");
            //p.AppendLine($"public class {m.Header.Onderwerp}_state {{");
            foreach (var step in result.Model.Steps)
            {
                // i.AppendLine($"public interface {m.Header.Onderwerp} : IGrainWithIntegerKey {{");
                if (step.Choices != null)
                {
                    foreach (var choice in step.Choices)
                    {
                        p.AppendLine($"public bool {choice.Situation} {{get;set;}}");
                    }
                }
                if (step.Value != null)
                {
                    p.AppendLine($"public double {step.Value} {{get;set;}}");
                }
            }

            p.AppendLine($"}}"); // end class
            p.AppendLine($"}}"); // end namespace
            var state = p.ToString();
        }
Ejemplo n.º 29
0
        public void ShouldReturnNoRight()
        {
            var isException = false;

            //prepare the result
            var parameters = new ParametersCollection
            {
                new ClientParameter("A", "nee", TypeInference.InferenceResult.TypeEnum.Boolean, "Dummy"),
                new ClientParameter("B", "ja", TypeInference.InferenceResult.TypeEnum.Boolean, "Dummy")
            } as IParametersCollection;
            var executionResult = new ExecutionResult(ref parameters) as IExecutionResult;

            //prepare yaml definition
            var controller = new YamlScriptController();

            controller.Parse(_testYaml2);
            //set the callback
            controller.QuestionCallback = (FormulaExpressionContext sender, QuestionArgs args) =>
            {
                executionResult.Questions = args;
            };

            try
            {
                controller.ExecuteWorkflow(ref parameters, ref executionResult);
            }
            catch (UnresolvedException)
            {
                isException = true;
            }

            Assert.False(isException);
            Assert.Equal(3, executionResult.Parameters.Count);
            Assert.Equal("A", executionResult.Parameters[0].Name);
            Assert.False((bool)executionResult.Parameters[0].Value);
            Assert.Equal("B", executionResult.Parameters[1].Name);
            Assert.True((bool)executionResult.Parameters[1].Value);
            Assert.Equal("recht", executionResult.Parameters[2].Name);
            Assert.False((bool)executionResult.Parameters[2].Value);
            Assert.Null(executionResult.Questions);
            Assert.Single(executionResult.Stacktrace);
            Assert.Equal("Test A of B", executionResult.Stacktrace.First().Step.Description);
        }
Ejemplo n.º 30
0
        public async Task <IExecutionResult> Execute(string yaml, IParametersCollection parameters)
        {
            IExecutionResult executionResult = null;
            var controller = new YamlScriptController();

            controller.QuestionCallback = (FormulaExpressionContext sender, QuestionArgs args) =>
            {
                executionResult.Questions = args;
            };
            var result = controller.Parse(yaml);

            executionResult = new ExecutionResult(ref parameters) as IExecutionResult;
            try
            {
                controller.ExecuteWorkflow(ref parameters, ref executionResult);
            }
            catch (UnresolvedException) { }

            return(executionResult);
        }