Beispiel #1
0
        public void TestValidate()
        {
            ExprCaseNode caseNode = SupportExprNodeFactory.MakeCaseSyntax1Node();

            caseNode.Validate(SupportExprValidationContextFactory.MakeEmpty(_container));

            caseNode = SupportExprNodeFactory.MakeCaseSyntax2Node();
            caseNode.Validate(SupportExprValidationContextFactory.MakeEmpty(_container));

            // No subnodes: Exception is thrown.
            TryInvalidValidate(new ExprCaseNode(false));
            TryInvalidValidate(new ExprCaseNode(true));

            // singe child node not possible, must be 2 at least
            caseNode = new ExprCaseNode(false);
            caseNode.AddChildNode(new SupportExprNode(4));
            TryInvalidValidate(caseNode);

            // in a case 1 expression (e.g. case when a=b then 1 else 2) the when child nodes must return boolean
            caseNode.AddChildNode(new SupportExprNode(2));
            TryInvalidValidate(caseNode);

            // in a case 2 expression (e.g. case a when b then 1 else 2) then a and b types must be comparable
            caseNode = new ExprCaseNode(true);
            caseNode.AddChildNode(new SupportExprNode("a"));
            caseNode.AddChildNode(new SupportExprNode(1));
            caseNode.AddChildNode(new SupportExprNode(2));
            TryInvalidValidate(caseNode);
        }
Beispiel #2
0
        public void TestEvaluate()
        {
            ExprCaseNode caseNode = SupportExprNodeFactory.MakeCaseSyntax1Node();

            caseNode.Validate(SupportExprValidationContextFactory.MakeEmpty(_container));

            Assert.AreEqual("a", caseNode.Evaluate(new EvaluateParams(MakeEvent(1), false, null)));
            Assert.AreEqual("b", caseNode.Evaluate(new EvaluateParams(MakeEvent(2), false, null)));
            Assert.AreEqual("c", caseNode.Evaluate(new EvaluateParams(MakeEvent(3), false, null)));

            caseNode = SupportExprNodeFactory.MakeCaseSyntax2Node();
            caseNode.Validate(SupportExprValidationContextFactory.MakeEmpty(_container));

            Assert.AreEqual("a", caseNode.Evaluate(new EvaluateParams(MakeEvent(1), false, null)));
            Assert.AreEqual("b", caseNode.Evaluate(new EvaluateParams(MakeEvent(2), false, null)));
            Assert.AreEqual("c", caseNode.Evaluate(new EvaluateParams(MakeEvent(3), false, null)));
        }
Beispiel #3
0
 private void TryInvalidValidate(ExprCaseNode exprCaseNode)
 {
     try {
         exprCaseNode.Validate(SupportExprValidationContextFactory.MakeEmpty(_container));
         Assert.Fail();
     }
     catch (ExprValidationException)
     {
         // expected
     }
 }