public void BoolPrimitiveMemberExpressionTest()
        {
            ODataFilterParser parser = new ODataFilterParser("Product/IsAvailable");

            Exception ex = null;
            try
            {
                ODataExpression exp = parser.Parse();
            }
            catch (NotSupportedException e)
            {
                ex = e;
            }

            Assert.IsNotNull(ex);

            //Assert.IsNotNull(exp);
            //Assert.IsTrue(exp.GetType() == typeof(ODataMemberExpression));

            //ODataMemberExpression memExp = (ODataMemberExpression)exp;
            //Assert.AreEqual(ExpressionType.MemberAccess, memExp.ExpressionType);
            //Assert.AreEqual("Product", memExp.Member);

            //Assert.AreEqual(ExpressionType.MemberAccess, memExp.Instance.ExpressionType);
            //Assert.AreEqual("IsAvailable", ((ODataMemberExpression)memExp.Instance).Member);
        }
        public void BooleanExpressionTest()
        {
            ODataFilterParser parser = new ODataFilterParser("false");

            ODataExpression exp = parser.Parse();

            Assert.IsNotNull(exp);
            Assert.IsTrue(exp.GetType() == typeof(ODataConstantExpression));
            Assert.IsFalse((bool)((ODataConstantExpression)exp).Value);
        }
        public void OrExpressionTest()
        {
            ODataFilterParser parser = new ODataFilterParser("true or false");

            ODataExpression exp = parser.Parse();

            Assert.IsNotNull(exp);
            Assert.IsTrue(exp.GetType() == typeof(ODataBinaryExpression));

            ODataBinaryExpression binExp = (ODataBinaryExpression)exp;
            Assert.AreEqual(ExpressionType.OrElse, binExp.ExpressionType);

            Assert.IsTrue(binExp.Left.GetType() == typeof(ODataConstantExpression));
            Assert.IsTrue((bool)((ODataConstantExpression)binExp.Left).Value);
            Assert.IsTrue(binExp.Right.GetType() == typeof(ODataConstantExpression));
            Assert.IsFalse((bool)((ODataConstantExpression)binExp.Right).Value);
        }
        public void AllMethodCallExpressionTest()
        {
            ODataFilterParser parser = new ODataFilterParser("all(Actors, it/Name eq 'John Belushi')");

            Exception ex = null;
            try
            {
                ODataExpression exp = parser.Parse();
            }
            catch (NotSupportedException e)
            {
                ex = e;
            }

            Assert.IsNotNull(ex);
        }
        public void SubstringOfMethodCallExpressionTest()
        {
            ODataFilterParser parser = new ODataFilterParser("substringof ( IsAvailable, 'Edm.Boolean' )");

            ODataExpression exp = parser.Parse();

            Assert.IsNotNull(exp);
            Assert.IsTrue(exp.GetType() == typeof(ODataFunctionCallExpression));

            ODataFunctionCallExpression unExp = (ODataFunctionCallExpression)exp;
            Assert.AreEqual(ExpressionType.Call, unExp.ExpressionType);

            Assert.AreEqual("substringof", unExp.Name);
            Assert.AreEqual("IsAvailable", unExp.Arguments.Cast<ODataMemberExpression>().First().Member);
            Assert.AreEqual("Edm.Boolean", unExp.Arguments.Skip(1).Cast<ODataConstantExpression>().First().Value);
        }
        public void IndexOfMethodCallExpressionTest()
        {
            ODataFilterParser parser = new ODataFilterParser("indexof ( Exp, 'test' )");

            ODataExpression exp = parser.Parse();

            Assert.IsNotNull(exp);
            Assert.IsTrue(exp.GetType() == typeof(ODataFunctionCallExpression));

            ODataFunctionCallExpression unExp = (ODataFunctionCallExpression)exp;
            Assert.AreEqual(ExpressionType.Call, unExp.ExpressionType);

            Assert.AreEqual("indexof", unExp.Name);
            Assert.AreEqual("Exp", unExp.Arguments.Cast<ODataMemberExpression>().First().Member);
            Assert.AreEqual("test", unExp.Arguments.Skip(1).Cast<ODataConstantExpression>().First().Value);
        }
        public void NotExpressionTest()
        {
            ODataFilterParser parser = new ODataFilterParser("not IsAvailable");

            ODataExpression exp = parser.Parse();

            Assert.IsNotNull(exp);
            Assert.IsTrue(exp.GetType() == typeof(ODataUnaryExpression));

            ODataUnaryExpression unExp = (ODataUnaryExpression)exp;
            Assert.AreEqual(ExpressionType.Not, unExp.ExpressionType);

            ODataMemberExpression binExp = unExp.Operand as ODataMemberExpression;
            Assert.IsNotNull(binExp);
            Assert.AreEqual(ExpressionType.MemberAccess, binExp.ExpressionType);

            Assert.IsNull(binExp.Instance);
            Assert.AreEqual("IsAvailable", binExp.Member);
        }
        public void NegateExpressionTest()
        {
            ODataFilterParser parser = new ODataFilterParser("- (3.0 mod 5)");

            ODataExpression exp = parser.Parse();

            Assert.IsNotNull(exp);
            Assert.IsTrue(exp.GetType() == typeof(ODataUnaryExpression));

            ODataUnaryExpression unExp = (ODataUnaryExpression)exp;
            Assert.AreEqual(ExpressionType.Negate, unExp.ExpressionType);

            ODataBinaryExpression binExp = unExp.Operand as ODataBinaryExpression;
            Assert.IsNotNull(binExp);
            Assert.AreEqual(ExpressionType.Modulo, binExp.ExpressionType);

            Assert.IsTrue(binExp.Left.GetType() == typeof(ODataConstantExpression));
            Assert.AreEqual(3.0, ((ODataConstantExpression)binExp.Left).Value);
            Assert.IsTrue(binExp.Right.GetType() == typeof(ODataConstantExpression));
            Assert.AreEqual(5, ((ODataConstantExpression)binExp.Right).Value);
        }
        public void DivideExpressionTest()
        {
            ODataFilterParser parser = new ODataFilterParser("3.0 div 5");

            ODataExpression exp = parser.Parse();

            Assert.IsNotNull(exp);
            Assert.IsTrue(exp.GetType() == typeof(ODataBinaryExpression));

            ODataBinaryExpression binExp = (ODataBinaryExpression)exp;
            Assert.AreEqual(ExpressionType.Divide, binExp.ExpressionType);

            Assert.IsTrue(binExp.Left.GetType() == typeof(ODataConstantExpression));
            Assert.AreEqual(3.0, ((ODataConstantExpression)binExp.Left).Value);
            Assert.IsTrue(binExp.Right.GetType() == typeof(ODataConstantExpression));
            Assert.AreEqual(5, ((ODataConstantExpression)binExp.Right).Value);
        }
        public void LessThanOrEqualExpressionTest()
        {
            ODataFilterParser parser = new ODataFilterParser("3 le 5L");

            ODataExpression exp = parser.Parse();

            Assert.IsNotNull(exp);
            Assert.IsTrue(exp.GetType() == typeof(ODataBinaryExpression));

            ODataBinaryExpression binExp = (ODataBinaryExpression)exp;
            Assert.AreEqual(ExpressionType.LessThanOrEqual, binExp.ExpressionType);

            Assert.IsTrue(binExp.Left.GetType() == typeof(ODataConstantExpression));
            Assert.AreEqual(3, ((ODataConstantExpression)binExp.Left).Value);
            Assert.IsTrue(binExp.Right.GetType() == typeof(ODataConstantExpression));
            Assert.AreEqual(5L, ((ODataConstantExpression)binExp.Right).Value);
        }