Exemplo n.º 1
0
        public Constraint CombineConstraint(Constraint other, System.Linq.Expressions.ExpressionType op)
        {
            BooleanCombinationConstraint combinedConstraint = new BooleanCombinationConstraint(op);

            combinedConstraint.AddConstraint(this);
            combinedConstraint.AddConstraint(other);

            return combinedConstraint;
        }
        public void BooleanCombinationConstraint_BuildAndExpression()
        {
            BooleanCombinationConstraint constraint = new BooleanCombinationConstraint(ExpressionType.And);

            constraint.AddConstraint(new AtomicConstraint("one=1"));
            constraint.AddConstraint(new AtomicConstraint("two=2"));
            constraint.AddConstraint(new AtomicConstraint("three=3"));

            StringBuilder builder = new StringBuilder();
            constraint.BuildExpression(builder);

            Assert.AreEqual("( one=1 ) AND ( two=2 ) AND ( three=3 )", builder.ToString());
        }
        public void BooleanCombinationConstraint_CombineConstraints()
        {
            BooleanCombinationConstraint baseConstraint = new BooleanCombinationConstraint(ExpressionType.Or);

            baseConstraint.AddConstraint(new AtomicConstraint("one=1"));
            baseConstraint.AddConstraint(new AtomicConstraint("two=2"));

            Constraint combinedConstraint = baseConstraint.CombineConstraint(new AtomicConstraint("three=3"), ExpressionType.Or);

            StringBuilder builder = new StringBuilder();

            combinedConstraint.BuildExpression(builder);

            Assert.AreEqual("( one=1 ) OR ( two=2 ) OR ( three=3 )", builder.ToString());
        }
        public Constraint CombineConstraint(Constraint other, ExpressionType op)
        {
            if (op == type)
            {
                // The operator types match, so we can create a single constraint combining all sub-constraints

                BooleanCombinationConstraint newConstraint = new BooleanCombinationConstraint(type);
                newConstraint.childConstraints = this.childConstraints;
                newConstraint.childConstraints.Add(other);
                return newConstraint;
            }
            else
            {
                BooleanCombinationConstraint combinedConstraint = new BooleanCombinationConstraint(type);

                combinedConstraint.AddConstraint(this);
                combinedConstraint.AddConstraint(other);
                return combinedConstraint;
            }
        }