Ejemplo n.º 1
0
        private static void AddTestQuery(List<TestQuery> queryList, TestQuery testQuery, Boolean clientSide)
        {
            if (testQuery == null)
                return;

            if (clientSide && testQuery.IncludesObjectValue)
                return;

            if (clientSide && !testQuery.SingleObjectProjection)
                return;

            if (clientSide && testQuery.SingleObjectPathProjection)
                return;

            queryList.Add(testQuery);
            return;
        }
Ejemplo n.º 2
0
        public static List<TestQuery> ReadQueryListFromFile(String filePath, Boolean startedOnClient, out Int32 counter)
        {
            int localCounter = 0;

            StreamReader reader = null;
            List<TestQuery> queryList = new List<TestQuery>();

            String line = null;
            StringBuilder stringBuilder = null;
            TestQuery testQuery = null;
            Boolean withinCommentBlock = false;

            try
            {
                Db.Transaction(delegate
                {
                    reader = new StreamReader(filePath, Encoding.Unicode);

                    // Stop at end-of-file.
                    while (!reader.EndOfStream)
                    {
                        line = reader.ReadLine().Trim();

                        // Do not consider blocks starting with "/*..." and ending with "...*/".
                        if (line.EndsWith("*/"))
                        {
                            withinCommentBlock = false;
                            continue;
                        }
                        if (line.StartsWith("/*"))
                        {
                            withinCommentBlock = true;
                            continue;
                        }
                        if (withinCommentBlock)
                            continue;

                        // Do not consider lines with comments.
                        if (line.StartsWith("//"))
                            continue;

                        if (line == "<END>")
                            break;

                        if (line == "<NEXT>")
                        {
                            AddTestQuery(queryList, testQuery, startedOnClient);
                            localCounter++;
                            testQuery = new TestQuery();
                            continue;
                        }

                        if (line.StartsWith("Description:"))
                        {
                            testQuery.Description = line.Substring(12).Trim();
                            continue;
                        }

                        if (line.StartsWith("QueryString:"))
                        {
                            testQuery.QueryString = line.Substring(12).Trim();
                            continue;
                        }

                        if (line.StartsWith("VariableValues:"))
                        {
                            testQuery.VariableValuesArr = ParseVariableValues(line.Substring(15).Trim());
                            continue;
                        }

                        if (line.StartsWith("SingleObjectProjection:"))
                        {
                            testQuery.SingleObjectProjection = Boolean.Parse(line.Substring(23).Trim());
                            continue;
                        }

                        if (line.StartsWith("SingleObjectPathProjection:"))
                        {
                            testQuery.SingleObjectPathProjection = Boolean.Parse(line.Substring(27).Trim());
                            continue;
                        }

                        if (line.StartsWith("IncludesLiteral:"))
                        {
                            testQuery.IncludesLiteral = Boolean.Parse(line.Substring(16).Trim());
                            continue;
                        }

                        if (line.StartsWith("IncludesObjectValue:"))
                        {
                            testQuery.IncludesObjectValue = Boolean.Parse(line.Substring(20).Trim());
                            continue;
                        }

                        if (line.StartsWith("DataManipulation:"))
                        {
                            testQuery.DataManipulation = Boolean.Parse(line.Substring(17).Trim());
                            continue;
                        }

                        if (line.StartsWith("ShouldBeReordered:"))
                        {
                            testQuery.ShouldBeReordered = Boolean.Parse(line.Substring(18).Trim());
                            continue;
                        }

                        if (line.StartsWith("UseBisonParser:")) {
                            testQuery.UseBisonParser = Boolean.Parse(line.Substring(15).Trim());
                            continue;
                        }

                        if (line.StartsWith("ExpectedExceptionMessage:"))
                        {
                            testQuery.ExpectedExceptionMessage = line.Substring(25).Trim();
                            continue;
                        }

                        if (line == "ExpectedExecutionPlan:")
                        {
                            stringBuilder = new StringBuilder();
                            while (!reader.EndOfStream && line != "")
                            {
                                line = reader.ReadLine();
                                if (line != "")
                                    stringBuilder.AppendLine(line);
                            }
                            testQuery.ExpectedExecutionPlan = stringBuilder.ToString();
                            continue;
                        }

                        if (line == "ExpectedResult:")
                        {
                            stringBuilder = new StringBuilder();
                            while (!reader.EndOfStream && line != "")
                            {
                                line = reader.ReadLine();
                                if (line != "")
                                    stringBuilder.AppendLine(line);
                            }
                            testQuery.ExpectedResult = stringBuilder.ToString();
                            continue;
                        }
                    }
                });
            }
            finally
            {
                if (reader != null)
                    reader.Close();
            }
            counter = localCounter;
            AddTestQuery(queryList, testQuery, startedOnClient);
            return queryList;
        }