Exemple #1
0
        public void SmartFilterLambdaBuilder_OnlyWordsPattern()
        {
            var target = new SmartFilterLambdaBuilder <LambdaTestClass>(
                "or",
                "and",
                "not");

            var lambda   = target.BuildExpressionTree("teste");
            var compiled = lambda.Compile();
            var obj      = new LambdaTestClass()
            {
                StringVal = "teste"
            };

            Assert.IsTrue(compiled.Invoke(obj));
            obj.StringVal = "other";
            Assert.IsFalse(compiled.Invoke(obj));
            obj.StringArray = new[] { "temp", "Isto é um teste" };
            Assert.IsTrue(compiled.Invoke(obj));
            obj.StringArray[1] = "other";
            Assert.IsFalse(compiled.Invoke(obj));

            lambda   = target.BuildExpressionTree("teste1   teste2\n\n\r\nteste3");
            compiled = lambda.Compile();
            obj      = new LambdaTestClass()
            {
                StringVal = "teste1 teste2 teste3"
            };
            Assert.IsTrue(compiled.Invoke(obj));
            obj.StringVal = null;
            Assert.IsFalse(compiled.Invoke(obj));
            obj.StringArray = new[] { "teste", "teste1" };
            Assert.IsTrue(compiled.Invoke(obj));
        }
Exemple #2
0
        public void SmartFilterLambdaBuilder_EmptyPattern()
        {
            var target = new SmartFilterLambdaBuilder <LambdaTestClass>(
                "or",
                "and",
                "not");
            var lambda = target.BuildExpressionTree(string.Empty);

            // Verifica o resultado da compilação da expressão.
            var compiled = lambda.Compile();
            var obj      = new LambdaTestClass();

            Assert.IsTrue(compiled.Invoke(obj));
            this.AssertParameter(lambda);

            var body = lambda.Body;

            Assert.AreEqual(ExpressionType.Constant, body.NodeType);
            var constant = (bool)((ConstantExpression)body).Value;

            Assert.IsTrue(constant);

            // Expressão vazia
            lambda   = target.BuildExpressionTree(" \n\r\n  ");
            compiled = lambda.Compile();
            obj      = new LambdaTestClass();
            Assert.IsTrue(compiled.Invoke(obj));
            this.AssertParameter(lambda);

            body = lambda.Body;
            Assert.AreEqual(ExpressionType.Constant, body.NodeType);
            constant = (bool)((ConstantExpression)body).Value;
            Assert.IsTrue(constant);
        }