public void AskingChild(
            string childAnswer,
            IEvaluationEngine parentEngine,
            IEvaluationEngine childEngine)
        {
            "establish an hierarchical evaluation engine"._(() =>
            {
                parentEngine = new EvaluationEngine();
                childEngine  = new EvaluationEngine(parentEngine);

                parentEngine.Solve <Question, string>()
                .AggregateWithExpressionAggregator(ParentAggregator, (aggregate, value) => aggregate + value)
                .ByEvaluating((q, p) => ParentExpression);

                childEngine.Solve <Question, string>()
                .AggregateWithExpressionAggregator(ChildAggregator, (aggregate, value) => aggregate + value)
                .ByEvaluating((q, p) => ChildExpression);
            });

            "when calling answer on a child evaluation engine"._(() =>
            {
                childAnswer = childEngine.Answer(new Question());
            });

            "it should override parent aggregator with child aggregator"._(() =>
            {
                childAnswer.Should().Contain(ChildAggregator);
            });

            "it should use expressions from child and parent"._(() =>
            {
                childAnswer
                .Should().Contain(ParentExpression)
                .And.Contain(ChildExpression);
            });

            "it should evaluate expressions from parent first"._(() =>
            {
                childAnswer.EndsWith(ParentExpression + ChildExpression, StringComparison.Ordinal)
                .Should().BeTrue();
            });
        }
示例#2
0
        public void Constraints(
            IEvaluationEngine engine,
            string answer)
        {
            const string NoConstraint        = "N";
            const string WithTrueConstraint  = "T";
            const string WithFalseConstraint = "F";

            "establish a solving strategy with constraints"._(() =>
            {
                engine = new EvaluationEngine();

                engine.Solve <WhatIsTheText, string>()
                .AggregateWithExpressionAggregator(string.Empty, (aggregate, value) => aggregate + value)
                .ByEvaluating((q, p) => NoConstraint)
                .When(q => false)
                .ByEvaluating((q, p) => WithFalseConstraint)
                .When(q => true)
                .ByEvaluating((q, p) => WithTrueConstraint);
            });

            "when calling answer"._(() =>
            {
                answer = engine.Answer(new WhatIsTheText());
            });

            "it should evaluate expressions without constraints"._(() =>
            {
                answer.Should().Contain(NoConstraint);
            });

            "it should evaluate expressions with fulfilled constraints"._(() =>
            {
                answer.Should().Contain(WithTrueConstraint);
            });

            "it should ignore expressions with constraints that are not fulfilled"._(() =>
            {
                answer.Should().NotContain(WithFalseConstraint);
            });
        }
示例#3
0
        public void MissingAggregator()
        {
            IEvaluationEngine engine = null;

            Exception exception = null;

            "establish"._(() =>
            {
                engine = new EvaluationEngine();

                engine.Solve <HowManyFruitsAreThere, int>();
            });

            "when calling answer on evaluation engine and no aggregator is specified"._(() =>
            {
                exception = Catch.Exception(() => engine.Answer(new HowManyFruitsAreThere()));
            });

            "it should throw invalid operation exception"._(() =>
            {
                exception.Should().BeOfType <InvalidOperationException>();
            });
        }