public void InvalidValueHandling()
        {
            var compiler = new FilterExpressionCompiler <Structs>(false);

            Assert.Equal("False", compiler.Compile(new[] { "byte", "-3" }).Body.ToString());
            Assert.Equal("False", compiler.Compile(new[] { "byte", "257" }).Body.ToString());
            Assert.Equal("False", compiler.Compile(new[] { "int", "not-int" }).Body.ToString());
        }
        public void Dynamic()
        {
            var compiler = new FilterExpressionCompiler <dynamic>(true, true);
            var expr     = compiler.Compile(new object[] {
                new[] { "this", "startswith", "1" },
                "or",
                new[] { "this", "B" },
                "or",
                new[] { "this", ">=", "C" }
            });

            var expectedExpr = "(((IIF((obj == null), null, obj.ToString().ToLower()) ?? '').StartsWith('1')"
                               + " OrElse (DynamicCompare(obj, 'b', True) == 0))"
                               + " OrElse (DynamicCompare(obj, 'c', True) >= 0))";

            Assert.Equal(
                expectedExpr.Replace("'", "\""),
                expr.Body.ToString()
                );

            var method = expr.Compile();

            Assert.True((bool)method.DynamicInvoke(1));
            Assert.True((bool)method.DynamicInvoke("B"));
            Assert.True((bool)method.DynamicInvoke('C'));
        }
        public void NoToStringForNumbers()
        {
            var compiler = new FilterExpressionCompiler(typeof(object), false);

            void Case(IList clientFilter, string expectedExpr, object trueTestValue)
            {
                var expr = compiler.Compile(clientFilter);

                Assert.Equal(expectedExpr, expr.Body.ToString());
                Assert.True((bool)expr.Compile().DynamicInvoke(trueTestValue));
            }

            Case(
                new object[] { "this", ">", new JValue(9) },
                "(DynamicCompare(obj, 9, False) > 0)",
                10
                );
        }
        void AssertEvaluation <T>(T dataItem, params object[] clientFilter)
        {
            var expr = new FilterExpressionCompiler <T>(false).Compile(clientFilter);

            Assert.True((bool)expr.Compile().DynamicInvoke(dataItem));
        }