public void ParseOrAndExpressionTest1() { Action <string> testExpression = delegate(string condition) { IConditionExpression expression = ConditionExpressionParser.Instance.Parse( condition); Assert.IsNotNull(expression, "Expected an expression instance."); BinaryOperatorExpression operatorExpression = expression as BinaryOperatorExpression; Assert.IsNotNull(operatorExpression, "Expected an operator expression."); Assert.AreEqual(BinaryExpressionOperator.Or, operatorExpression.Operator, "Unexpected operator."); // // Or left // BinaryOperatorExpression andExpression = operatorExpression.Left as BinaryOperatorExpression; Assert.IsNotNull(andExpression, "Expected an operator expression."); Assert.AreEqual(BinaryExpressionOperator.And, andExpression.Operator, "Unexpected operator."); // // And Left // BinaryOperatorExpression testExpression1 = andExpression.Left as BinaryOperatorExpression; Assert.IsNotNull(testExpression1, "Expected an operator expression."); Assert.AreEqual(BinaryExpressionOperator.Equal, testExpression1.Operator, "Unexpected operator."); ElementAttributeExpression test1AttributeExpression = testExpression1.Left as ElementAttributeExpression; Assert.IsNotNull(test1AttributeExpression, "Unexpected left node type."); Assert.AreEqual(ElementAttributeType.Name, test1AttributeExpression.ElementAttribute, "Attribute expression was not parsed correctly."); StringExpression test1StringExpression = testExpression1.Right as StringExpression; Assert.IsNotNull(test1StringExpression, "Unexpected right node type."); Assert.AreEqual("Test 1", test1StringExpression.Text, "String expression was not parsed correctly."); // // And Right // BinaryOperatorExpression testExpression2 = andExpression.Right as BinaryOperatorExpression; Assert.IsNotNull(testExpression2, "Expected an operator expression."); Assert.AreEqual(BinaryExpressionOperator.Equal, testExpression2.Operator, "Unexpected operator."); ElementAttributeExpression test2AttributeExpression = testExpression2.Left as ElementAttributeExpression; Assert.IsNotNull(test2AttributeExpression, "Unexpected left node type."); Assert.AreEqual(ElementAttributeType.Name, test2AttributeExpression.ElementAttribute, "Attribute expression was not parsed correctly."); StringExpression test2StringExpression = testExpression2.Right as StringExpression; Assert.IsNotNull(test2StringExpression, "Unexpected right node type."); Assert.AreEqual("Test 2", test2StringExpression.Text, "String expression was not parsed correctly."); // // Or right // BinaryOperatorExpression testExpression3 = operatorExpression.Right as BinaryOperatorExpression; Assert.IsNotNull(testExpression3, "Expected an operator expression."); Assert.AreEqual(BinaryExpressionOperator.Equal, testExpression3.Operator, "Unexpected operator."); ElementAttributeExpression test3AttributeExpression = testExpression3.Left as ElementAttributeExpression; Assert.IsNotNull(test3AttributeExpression, "Unexpected left node type."); Assert.AreEqual(ElementAttributeType.Name, test3AttributeExpression.ElementAttribute, "Attribute expression was not parsed correctly."); StringExpression test3StringExpression = testExpression3.Right as StringExpression; Assert.IsNotNull(test3StringExpression, "Unexpected right node type."); Assert.AreEqual("Test 3", test3StringExpression.Text, "String expression was not parsed correctly."); }; string expressionText; expressionText = "(($(Name) == 'Test 1') And ($(Name) == 'Test 2')) Or ($(Name) == 'Test 3')"; testExpression(expressionText); expressionText = "$(Name) == 'Test 1' And $(Name) == 'Test 2' Or $(Name) == 'Test 3'"; testExpression(expressionText); }