Example #1
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);
        }
Example #2
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);
        }