Exemplo n.º 1
0
        /// <summary>
        /// Execute the test case represented by the object, and store execution results and/or outcome.
        /// </summary>
        public override void Execute()
        {
            // User supplied parameters will override internal parameters
            Boolean containsLiterals = ContainsLiterals.HasValue && ContainsLiterals.Value ||
                                       InternalParam.ContainsLiterals.HasValue && InternalParam.ContainsLiterals.Value && !ContainsLiterals.HasValue;
            Boolean singleObjectProj = SingleObjectProjection.HasValue && SingleObjectProjection.Value ||
                                       InternalParam.SingleObjectProjection.HasValue && InternalParam.SingleObjectProjection.Value && !SingleObjectProjection.HasValue;

            SqlEnumerator <dynamic> resultEnumerator = null;

            try
            {
                if (!InternalParam.ContainsLiterals.HasValue && !ContainsLiterals.HasValue)
                {
                    try
                    {
                        resultEnumerator = Db.SQL(Statement, Values).GetEnumerator() as SqlEnumerator <dynamic>;
                        InternalParam.ContainsLiterals = false;
                    }
                    catch (SqlException e)
                    {
                        throw e;
                    }
                    catch (Exception e) // Catches ScErrUnsupportLiteral error
                    {
                        //Console.WriteLine("Execute statement: " + e.Message);
                        // TODO: Match unsupported literal exception, throw otherwise.
                        //       Also removes the need for the SqlException above
                        resultEnumerator = Db.SlowSQL(Statement, Values).GetEnumerator() as SqlEnumerator <dynamic>;
                        InternalParam.ContainsLiterals = true;
                    }
                }
                else if (containsLiterals)
                {
                    resultEnumerator = Db.SlowSQL(Statement, Values).GetEnumerator() as SqlEnumerator <dynamic>;
                }
                else
                {
                    resultEnumerator = Db.SQL(Statement, Values).GetEnumerator() as SqlEnumerator <dynamic>;
                }

                string result;
                if (!InternalParam.SingleObjectProjection.HasValue && !SingleObjectProjection.HasValue)
                {
                    try
                    {
                        result = Utilities.GetResults(resultEnumerator, hasOrderByClause());
                        InternalParam.SingleObjectProjection = false;
                    }
                    catch (NullReferenceException e) // Exception indicating that the result set contains single element rows
                    {
                        //Console.WriteLine("GetResults: " + e.Message);
                        result = Utilities.GetSingleElementResults(resultEnumerator, hasOrderByClause());
                        InternalParam.SingleObjectProjection = true;
                    }
                }
                else if (singleObjectProj)
                {
                    result = Utilities.GetSingleElementResults(resultEnumerator, hasOrderByClause());
                }
                else
                {
                    result = Utilities.GetResults(resultEnumerator, hasOrderByClause());
                }

                ActualResults.Add(result);
                ActualExecutionPlan.Add(resultEnumerator.ToString());
                ActuallyUsesBisonParser.Add(resultEnumerator.IsBisonParserUsed);
            }
            catch (Exception exception) // Catch actual exceptions when executing queries
            {
                //Console.WriteLine("Actual exception: " + exception.Message);
                String exceptionMessage = exception.Message;
                if (exceptionMessage.Contains("\r"))
                {
                    exceptionMessage = exceptionMessage.Substring(0, exceptionMessage.IndexOf("\r"));
                }
                if (exceptionMessage.Contains("\n"))
                {
                    exceptionMessage = exceptionMessage.Substring(0, exceptionMessage.IndexOf("\n"));
                }

                ActualException.Add(exceptionMessage);
            }

            finally
            {
                if (resultEnumerator != null)
                {
                    resultEnumerator.Dispose();
                }
            }
        }