예제 #1
0
 public void FilterExpressionTest()
 {
     CombinatorialEngineProvider.RunCombinations(
         ExpressionTestCase.PrimitiveLiteralTestCases()
         .Concat(ExpressionTestCase.BinaryOperatorTestCases())
         .Concat(ExpressionTestCase.UnaryOperatorTestCases())
         .Concat(ExpressionTestCase.PropertyAccessTestCases(ExpressionTestCase.PropertyAccessNames))
         .Concat(ExpressionTestCase.ParenthesisTestCases())
         .Concat(ExpressionTestCase.FunctionCallTestCases()),
         testCase => QueryTokenUtils.VerifyQueryTokensAreEqual(
             testCase.ExpectedToken,
             QueryTokenUtils.ParseQuery("Root", filter: testCase.Expression).Filter,
             this.Assert));
 }
예제 #2
0
        public void ExpandExpressionTest()
        {
            IEnumerable <ExpressionTestCase> expressionTestCases = ExpressionTestCase.PrimitiveLiteralTestCases()
                                                                   .Concat(ExpressionTestCase.BinaryOperatorTestCases())
                                                                   .Concat(ExpressionTestCase.UnaryOperatorTestCases())
                                                                   .Concat(ExpressionTestCase.PropertyAccessTestCases(ExpressionTestCase.PropertyAccessNames))
                                                                   .Concat(ExpressionTestCase.ParenthesisTestCases())
                                                                   .Concat(ExpressionTestCase.FunctionCallTestCases());

            var testCases = expressionTestCases.Select(tc => new ExpandTestCase()
            {
                Expand = tc.Expression,
                ExpectedExpandToken = new ExpandToken(new QueryToken[] { tc.ExpectedToken })
            });

            // All expressions
            testCases.Concat(new ExpandTestCase[] { new ExpandTestCase()
                                                    {
                                                        Expand = string.Join(", ", expressionTestCases.Select(tc => tc.Expression).ToArray()),
                                                        ExpectedExpandToken = new ExpandToken(expressionTestCases.Select(tc => tc.ExpectedToken))
                                                    } });

            this.CombinatorialEngineProvider.RunCombinations(
                testCases,
                (testCase) =>
            {
                SyntacticTree actual   = QueryTokenUtils.ParseQuery("Root", expand: testCase.Expand);
                SyntacticTree expected = new SyntacticTree(
                    new SegmentToken("Root", null, null),
                    null,
                    null,
                    null,
                    testCase.ExpectedExpandToken,
                    null,
                    null,
                    null,
                    null,
                    null);

                QueryTokenUtils.VerifySyntaxTreesAreEqual(
                    expected,
                    actual,
                    this.Assert);
            });
        }
예제 #3
0
        public void UriVariationExpressionsTest()
        {
            IEnumerable<ExpressionTestCase> testCases = new ExpressionTestCase[]
            {
                // Uri query where + instead of space is in Uri text
                new ExpressionTestCase { Expression = "1+lt+2+and+true+ne+false", ExpectedToken = new BinaryOperatorToken(
                    BinaryOperatorKind.And, 
                    new BinaryOperatorToken(BinaryOperatorKind.LessThan, new LiteralToken(1), new LiteralToken(2)),
                    new BinaryOperatorToken(BinaryOperatorKind.NotEqual, new LiteralToken(true), new LiteralToken(false))) }
            };

            CombinatorialEngineProvider.RunCombinations(
                testCases,
                (testCase) =>
                {
                    QueryTokenUtils.VerifyQueryTokensAreEqual(
                        testCase.ExpectedToken,
                        QueryTokenUtils.ParseQuery("Root", filter: testCase.Expression).Filter,
                        this.Assert);
                });
        }
예제 #4
0
        public void UriVariationExpressionsTest()
        {
            IEnumerable <ExpressionTestCase> testCases = new ExpressionTestCase[]
            {
                // Uri query where + instead of space is in Uri text
                new ExpressionTestCase {
                    Expression = "1+lt+2+and+true+ne+false", ExpectedToken = new BinaryOperatorToken(
                        BinaryOperatorKind.And,
                        new BinaryOperatorToken(BinaryOperatorKind.LessThan, new LiteralToken(1), new LiteralToken(2)),
                        new BinaryOperatorToken(BinaryOperatorKind.NotEqual, new LiteralToken(true), new LiteralToken(false)))
                }
            };

            CombinatorialEngineProvider.RunCombinations(
                testCases,
                (testCase) =>
            {
                QueryTokenUtils.VerifyQueryTokensAreEqual(
                    testCase.ExpectedToken,
                    QueryTokenUtils.ParseQuery("Root", filter: testCase.Expression).Filter,
                    this.Assert);
            });
        }
예제 #5
0
        public void OrderByExpressionTest()
        {
            IEnumerable <ExpressionTestCase> expressionTestCases = ExpressionTestCase.PrimitiveLiteralTestCases()
                                                                   .Concat(ExpressionTestCase.BinaryOperatorTestCases())
                                                                   .Concat(ExpressionTestCase.UnaryOperatorTestCases())
                                                                   .Concat(ExpressionTestCase.PropertyAccessTestCases(ExpressionTestCase.PropertyAccessNames))
                                                                   .Concat(ExpressionTestCase.ParenthesisTestCases())
                                                                   .Concat(ExpressionTestCase.FunctionCallTestCases());

            // Use filter expressions first without anything
            var filterWithNoDirection = expressionTestCases.Select(tc => new OrderByTestCase()
            {
                OrderBy = tc.Expression,
                ExpectedOrderByTokens = new OrderByToken[] { new OrderByToken(tc.ExpectedToken, OrderByDirection.Ascending) }
            });

            // Use filter expressions with asc
            var filterWithAscending = expressionTestCases.Select(tc => new OrderByTestCase()
            {
                OrderBy = tc.Expression + " asc",
                ExpectedOrderByTokens = new OrderByToken[] { new OrderByToken(tc.ExpectedToken, OrderByDirection.Ascending) }
            });

            // Use filter expressions with desc
            var filterWithDescending = expressionTestCases.Select(tc => new OrderByTestCase()
            {
                OrderBy = tc.Expression + " desc",
                ExpectedOrderByTokens = new OrderByToken[] { new OrderByToken(tc.ExpectedToken, OrderByDirection.Descending) }
            });

            // And now some order by specific cases with multiple orderbys
            var orderByTestCases = ExpressionTestCase.VariousExpressions().ToList().Variations(3).Select(tc =>
                                                                                                         new OrderByTestCase
            {
                OrderBy = string.Join(",", tc.Select((t, index) => t.Expression + ((index % 3 == 0) ? "" : ((index % 3 == 1) ? " asc" : " desc"))).ToArray()),
                ExpectedOrderByTokens = tc.Select((t, index) => new OrderByToken(
                                                      t.ExpectedToken,
                                                      (index % 3 == 2) ? OrderByDirection.Descending : OrderByDirection.Ascending)).ToArray()
            });

            CombinatorialEngineProvider.RunCombinations(
                filterWithNoDirection
                .Concat(filterWithAscending)
                .Concat(filterWithDescending)
                .Concat(orderByTestCases),
                (testCase) =>
            {
                SyntacticTree actual   = QueryTokenUtils.ParseQuery("Root", orderby: testCase.OrderBy);
                SyntacticTree expected = new SyntacticTree(
                    null,
                    new[] { "Root" },
                    null,
                    testCase.ExpectedOrderByTokens,
                    null,
                    null,
                    null,
                    null,
                    null,
                    null,
                    null);

                QueryTokenUtils.VerifySyntaxTreesAreEqual(
                    expected,
                    actual,
                    this.Assert);
            });
        }
예제 #6
0
        public void KeyValuesTest()
        {
            IEnumerable <KeyValuesTestCase> testCases = new[]
            {
                new KeyValuesTestCase {
                    KeyValues         = "()",
                    ExpectedKeyValues = new NamedValue[0]
                },
                new KeyValuesTestCase {
                    KeyValues         = "(0)",
                    ExpectedKeyValues = new [] { new NamedValue(null, new LiteralToken(0)) }
                },
                new KeyValuesTestCase {
                    KeyValues         = "(0,1)",
                    ExpectedKeyValues = new [] {
                        new NamedValue(null, new LiteralToken(0)),
                        new NamedValue(null, new LiteralToken(1))
                    }
                },
                new KeyValuesTestCase {
                    KeyValues         = "(Key='some')",
                    ExpectedKeyValues = new [] {
                        new NamedValue("Key", new LiteralToken("some")),
                    }
                },
                new KeyValuesTestCase {
                    KeyValues         = "(Key=datetime'2010-12-09T14:10:20')",
                    ExpectedKeyValues = new [] {
                        new NamedValue("Key", new LiteralToken(new DateTime(2010, 12, 9, 14, 10, 20)))
                    }
                },
                new KeyValuesTestCase {
                    KeyValues         = "(Key1=42.42,  Key2=42f)",
                    ExpectedKeyValues = new [] {
                        new NamedValue("Key1", new LiteralToken((double)42.42)),
                        new NamedValue("Key2", new LiteralToken((Single)42))
                    }
                },
                new KeyValuesTestCase {
                    KeyValues         = "(Key=1,Key=2)",
                    ExpectedKeyValues = new [] {
                        new NamedValue("Key", new LiteralToken(1)),
                        new NamedValue("Key", new LiteralToken(2))
                    }
                },
            };

            testCases.Concat(ExpressionTestCase.PrimitiveLiteralTestCases().Select(tc =>
                                                                                   new KeyValuesTestCase()
            {
                KeyValues         = "(" + tc.Expression + ")",
                ExpectedKeyValues = new[] { new NamedValue(null, (LiteralToken)tc.ExpectedToken) }
            }));

            this.CombinatorialEngineProvider.RunCombinations(
                testCases,
                testCase => QueryTokenUtils.VerifyQueryTokensAreEqual(
                    new StartPathToken("Customers", null, testCase.ExpectedKeyValues),
                    QueryTokenUtils.ParseQuery("/Customers" + testCase.KeyValues).Path,
                    this.Assert));
        }