public async Task <ResultArgs <object> > AskAdviceAsync(QuestionArgs questionArgs)
        {
            if (questionArgs == null)
            {
                throw new ArgumentNullException("questionArgs");
            }

            //WE ONLY KNOW HOW TO DEAL WITH PHRASE EDIT QUESTIONS ABOUT PERCENT KNOWN.
            if (!(questionArgs.State is PhraseEdit) ||
                questionArgs.Question != StudyResources.AdvisorQuestionWhatIsPhrasePercentKnown)
            {
                return(await new Task <ResultArgs <object> >(() =>
                {
                    var errorMsg = string.Format("Unknown question for advice.\n" +
                                                 "questionArgs.State: {0}\n" +
                                                 "questionArgs.Question: {1}",
                                                 questionArgs.State.ToString(), questionArgs.Question);
                    var error = new Study.StudyException(errorMsg);
                    return new ResultArgs <object>(error);
                }));
            }

            var phrase = (PhraseEdit)questionArgs.State;

            var result = await GetPercentKnownAsync(phrase);

            //THE RESULT IS CASTED ALREADY AS A DOUBLE. WE NEED TO WRAP IT AS A DOUBLE
            var percentKnownObjectWrapper = new ResultArgs <object>(result.Object);


            return(await StudyHelper.WrapInTask <ResultArgs <object> >(percentKnownObjectWrapper));

            //var answerTask = new Task<ResultArgs<object>>(() => { return new ResultArgs<object>(percentKnown); });
            //return await answerTask;
        }
예제 #2
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));
        }
 private void TryToAnswerQuestion(QuestionArgs question, IPresident asker)
 {
     if (CanAnswerQuestion(question))
     {
         asker.RecieveAnswer(question, GetAnswer(question));
     }
 }
예제 #4
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);
        }