public void Evaluate_GivenNullNegative_Throws()
        {
            // GIVEN
            var positiveDecision = new Mock <Decision <EmployeeInfo, BonusCalculation> >();
            var decisionQuery    = new DecisionQuery <EmployeeInfo, BonusCalculation>
            {
                Test     = _ => true,
                Positive = positiveDecision.Object,
                Negative = null
            };
            var input = new EmployeeInfo();

            // WHEN THEN
            Assert.Throws <DecisionException>(() => decisionQuery.Evaluate(input), "'Positive' cannot be null");
        }
        public void Evaluate_GivenNegativeTest_EvaluatesNegative()
        {
            // GIVEN
            var positiveDecision = new Mock <Decision <EmployeeInfo, BonusCalculation> >();
            var negativeDecision = new Mock <Decision <EmployeeInfo, BonusCalculation> >();
            var decisionQuery    = new DecisionQuery <EmployeeInfo, BonusCalculation>
            {
                Test     = _ => false,
                Positive = positiveDecision.Object,
                Negative = negativeDecision.Object
            };
            var input = new EmployeeInfo();

            // WHEN
            decisionQuery.Evaluate(input);

            // THEN
            positiveDecision.Verify(decision => decision.Evaluate(input), Times.Never);
            negativeDecision.Verify(decision => decision.Evaluate(input), Times.Once);
        }
Ejemplo n.º 3
0
 public IEnumerable <Activity> Evaluate(Activity activity)
 {
     return(_entryPoint.Evaluate(activity));
 }
Ejemplo n.º 4
0
        static void MainDecisionTrees()
        {
            // The tree is constructed from a query
              var tree =
              new DecisionQuery
              {
            Title = "More than $40k",
            // Test is specified using a lambda function
            Test = (client) => client.Income > 40000,
            // Sub-trees can be 'DecisionResult' or 'DecisionQuery'
            Positive = new DecisionResult { Result = true },
            Negative = new DecisionResult { Result = false }
              };

              // Test a client using this tree
              // Create client using object initializer
              var john = new Client {
              Name = "John Doe", Income = 40000, YearsInJob = 1,
              UsesCreditCard = true, CriminalRecord = false
            };
              tree.Evaluate(john);
        }