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); }
public void CanParseChoices() { var controller = new YamlScriptController(); var result = controller.Parse(YamlTestFileLoader.Load(@"Zorgtoeslag4.yaml")); Assert.False(result.IsError); }
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); }
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 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); }
public static Model GetDefaultTestModel() { var controller = new YamlScriptController(); var result = controller.Parse(YamlTestFileLoader.Load(@"Zorgtoeslag5.yaml")); Assert.False(result.IsError); return(result.Model); }
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"); }
public void ShouldReturnCorrectCultureForKeywords(string culture) { Globalization.SetKeywordResourceCulture(new CultureInfo(culture)); YamlRuleParser parser = new YamlRuleParser(YamlTestFileLoader.Load($"Globalization/rule.{culture}.yaml"), null); Assert.NotEmpty(parser.Flow()); Assert.NotNull(parser.Header()); }
public async void CanExecuteRuleYamlFromContentsUT() { RulesControllerDiscipl controller = new RulesControllerDiscipl(); var result = await controller.ExecuteRuleYamlContents(new OpenApi.v1.Features.discipl.Dto.ExecuteRuleYamlFromContentRequest() { Yaml = YamlTestFileLoader.Load(@"Zorgtoeslag5.yaml") }); }
public void Yaml_Can_Parse_Formulas() { var yamlParser = new YamlRuleParser(YamlTestFileLoader.Load(@"Rijksoverheid/Zorgtoeslag.yaml"), null); var functions = yamlParser.Formulas(); Assert.True(functions.Count() == 11); Assert.True(functions.ElementAt(1).Name == "maximaalvermogen"); Assert.True(functions.ElementAt(1).IsSituational == true); }
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); }
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); }
public void Flow_Zorgtoeslag_Model_Flow_Deserialization() { var parser = new YamlRuleParser(YamlTestFileLoader.Load(@"Rijksoverheid/Zorgtoeslag.yaml"), null); var steps = parser.Flow(); Assert.True(steps.Count() == 3); Assert.True((from p in steps where p.Formula == "recht" select p).Single().Situation == ""); Assert.True((from p in steps where p.Situation == "buitenland" select p).Single().Description == "bereken de zorgtoeslag wanner men in het buitenland woont"); Assert.True((from p in steps where p.Name == "2" select p).First().Description == "bereken de zorgtoeslag wanneer men binnen nederland woont"); }
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)); }
private void InitialiseYamls() { YamlSourceHelper.SetAllYamlFromUri(YamlSourceController, Uri); //this type of setting will override whatever is provided via url, so it will only set if there is nothing set yet. YamlSourceHelper.SetDefaultYaml(YamlSourceController, null, YamlTestFileLoader.Load(@"Zorgtoeslag5.yaml"), YamlTestFileLoader.Load(@"Zorgtoeslag5Content.yaml"), YamlTestFileLoader.Load(@"Zorgtoeslag5Routing.yaml") ); }
public async void Service_Parse_Yaml_Successfull() { APIServiceController controller = new APIServiceController(InitMoqLogger(), new YamlScriptController(), InitMoqRoutingController()); var s = new ParseRequest() { Config = YamlTestFileLoader.Load(@"Rijksoverheid/Zorgtoeslag.yaml") }; var result = await controller.Parse(s); Assert.False(result.IsError); }
public void Yaml_Can_Convert_To_Json() { var deserializer = new DeserializerBuilder().Build(); var yamlObject = deserializer.Deserialize(new StringReader(YamlTestFileLoader.Load(@"Rijksoverheid/Zorgtoeslag.yaml"))); var serializer = new SerializerBuilder() .JsonCompatible() .Build(); var json = serializer.Serialize(yamlObject); }
public void Yaml_Passes_AttributeNaming_Stuurinformatie() { var map = YamlRuleParser.Map(YamlTestFileLoader.Load(@"Rijksoverheid/Zorgtoeslag.yaml")); var s = ""; foreach (var entry in (YamlMappingNode)map.Children[new YamlScalarNode("stuurinformatie")]) { s += (((YamlScalarNode)entry.Key).Value) + ","; } Assert.True("bron,domein,jaar,onderwerp,organisatie,status,type,versie" == Order(s)); }
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"); }
public void Yaml_Passes_AttributeValues_Stuurinformatie() { var map = YamlRuleParser.Map(YamlTestFileLoader.Load(@"Rijksoverheid/Zorgtoeslag.yaml")); var s = ""; var entries = (YamlMappingNode)map.Children[new YamlScalarNode("stuurinformatie")]; foreach (var entry in entries) { s += entry.Value + ","; } Assert.True("1.0,2019,belastingdienst,https://download.belastingdienst.nl/toeslagen/docs/berekening_zorgtoeslag_2019_tg0821z91fd.pdf,ontwikkel,toeslagen,zorg,zorgtoeslag" == Order(s)); }
public void Yaml_Can_Deserialize_Root_Nodes() { var map = YamlRuleParser.Map(YamlTestFileLoader.Load(@"Rijksoverheid/Zorgtoeslag.yaml")); // Load the stream var s = ""; foreach (var entry in map.Children) { s += (((YamlScalarNode)entry.Key).Value) + ","; } Assert.True("berekening,formules,stuurinformatie,tabellen" == Order(s)); }
public async void CorrectlyHandlesADebugSessionWithoutDebugExceptions() { RulesControllerDiscipl controller = new RulesControllerDiscipl(); var result = await controller.DebugRuleYamlContents(new OpenApi.v1.Features.discipl.Dto.DebugRuleYamlFromContentRequest() { Yaml = YamlTestFileLoader.Load(@"Zorgtoeslag5.yaml") }); Assert.Equal(404, ((ObjectResult)result).StatusCode); Assert.Equal(ExecuteRuleYamlResultTypes.Ok, ((Vs.Rules.OpenApi.v1.Features.discipl.Dto.DebugRuleYamlFromContentResponse)((ObjectResult)result).Value).ExecutionStatus); }
public void Yaml_Can_Deserialize_Tables() { var yamlParser = new YamlRuleParser(YamlTestFileLoader.Load(@"Rijksoverheid/Zorgtoeslag.yaml"), null); var tabellen = yamlParser.Tabellen(); Assert.True(tabellen.Count() == 1); var tabel = tabellen.Single(); Assert.True(tabel.Name == "woonlandfactoren"); Assert.True(tabel.ColumnTypes.Count == 2); Assert.True(tabel.ColumnTypes[0].Name == "woonland"); Assert.True(tabel.ColumnTypes[1].Name == "factor"); }
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)); }
public async void ShouldProvideDebugInformationUT() { RulesControllerDiscipl controller = new RulesControllerDiscipl(); var result = await controller.DebugRuleYamlContents(new OpenApi.v1.Features.discipl.Dto.DebugRuleYamlFromContentRequest() { Yaml = YamlTestFileLoader.Load(@"Malformed/nl-NL/HeaderUnknownProperty.yaml") }); var value = ((Vs.Rules.OpenApi.v1.Features.discipl.Dto.DebugRuleYamlFromContentResponse)((Microsoft.AspNetCore.Mvc.ObjectResult)result).Value); Assert.NotEmpty(value.ParseResult.FormattingExceptions); Assert.NotNull(value.ParseResult.FormattingExceptions[0].DebugInfo); Assert.NotNull(value.ParseResult.FormattingExceptions[0].Message); }
public void ShouldDeserialize() { var yaml = YamlTestFileLoader.Load(@"Zorgtoeslag5.layers.yaml"); var deserializer = new DeserializerBuilder().Build(); var result = deserializer.Deserialize <LayerConfiguration>(yaml); Assert.Equal("1.0", result.Version); Assert.Equal(3, result.Layers.ToList().Count()); Assert.Single(result.Layers.ElementAt(0).Contexts); Assert.Equal(3, result.Layers.ElementAt(1).Contexts.Count()); Assert.Null(result.Layers.ElementAt(1).Contexts.ElementAt(0).Language); Assert.Equal(LanguageCode.EN, result.Layers.ElementAt(1).Contexts.ElementAt(1).Language); Assert.Equal(LanguageCode.AR, result.Layers.ElementAt(1).Contexts.ElementAt(2).Language); Assert.Single(result.Layers.ElementAt(2).Contexts); Assert.True(true); }
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"); }
public void Service_Execute_Zorgtoeslag_From_Url() { APIServiceController controller = new APIServiceController(InitMoqLogger(), new YamlScriptController(), InitMoqRoutingController()); var executeRequest = new ExecuteRequest() { Config = YamlTestFileLoader.Load(@"Rijksoverheid/Zorgtoeslag.yaml"), Parameters = new ParametersCollection() { new ClientParameter("alleenstaande", "ja", TypeInference.InferenceResult.TypeEnum.Boolean, "Dummy") } }; var payload = JsonConvert.SerializeObject(executeRequest); var result = controller.Execute(executeRequest).Result; Assert.True(result.Questions.Parameters.Count == 1); Assert.True(result.Questions.Parameters[0].Name == "woonland"); }
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); }
public void ShouldInitialize() { var yaml = YamlTestFileLoader.Load(@"Zorgtoeslag5.layers.yaml"); var sut = new LayerController(); sut.Initialize(yaml); Assert.Equal(sut.LayerConfiguration.Start.Line, sut.LayerConfiguration.End.Line); Assert.Equal(sut.LayerConfiguration.Start.Col, sut.LayerConfiguration.End.Col); Assert.Equal(sut.LayerConfiguration.Start.Index, sut.LayerConfiguration.End.Index); Assert.Equal("1.0", sut.LayerConfiguration.Version); Assert.Equal(3, sut.LayerConfiguration.Layers.ToList().Count()); Assert.Single(sut.LayerConfiguration.Layers.ElementAt(0).Contexts); Assert.Equal(3, sut.LayerConfiguration.Layers.ElementAt(1).Contexts.Count()); Assert.Null(sut.LayerConfiguration.Layers.ElementAt(1).Contexts.ElementAt(0).Language); Assert.Equal(LanguageCode.EN, sut.LayerConfiguration.Layers.ElementAt(1).Contexts.ElementAt(1).Language); Assert.Equal(LanguageCode.AR, sut.LayerConfiguration.Layers.ElementAt(1).Contexts.ElementAt(2).Language); Assert.Single(sut.LayerConfiguration.Layers.ElementAt(2).Contexts); }