示例#1
0
        private bool CheckRowCount(int rows, SqlSync.SprocTest.Configuration.ExpectedResult expected, out string message)
        {
            message = "";
            bool passed = true;

            if (expected.RowCountSpecified)
            {
                if (!expected.RowCountOperatorSpecified)
                {
                    expected.RowCountOperator = SqlSync.SprocTest.Configuration.RowCountOperator.EqualTo;
                }

                switch (expected.RowCountOperator)
                {
                case SqlSync.SprocTest.Configuration.RowCountOperator.GreaterThan:
                    if (rows <= expected.RowCount)
                    {
                        message += "Invalid Row Count. Expected Greater Than " + expected.RowCount.ToString() + ", Retrieved " + rows;
                        passed   = false;
                    }
                    else
                    {
                        message += " Row Count Passed. Expected Greater Than " + expected.RowCount.ToString() + ", Retrieved " + rows;
                    }
                    break;

                case SqlSync.SprocTest.Configuration.RowCountOperator.LessThan:
                    if (rows >= expected.RowCount)
                    {
                        message += "Invalid Row Count. Expected Less Than " + expected.RowCount.ToString() + ", Retrieved " + rows;
                        passed   = false;
                    }
                    else
                    {
                        message += " Row Count Passed. Expected Less Than " + expected.RowCount.ToString() + ", Retrieved " + rows;
                    }
                    break;

                case SqlSync.SprocTest.Configuration.RowCountOperator.EqualTo:
                default:
                    if (rows != expected.RowCount)
                    {
                        message += "Invalid Row Count. Expected " + expected.RowCount.ToString() + ", Retrieved " + rows;
                        passed   = false;
                    }
                    else
                    {
                        message += "Row Count Passed. Expected " + expected.RowCount.ToString() + ", Retrieved " + rows;
                    }

                    break;
                }
            }
            return(passed);
        }
示例#2
0
 private bool CheckColumnCount(int columnCount, SqlSync.SprocTest.Configuration.ExpectedResult expected, out string message)
 {
     if (expected.ColumnCountSpecified == false)
     {
         message = "";
         return(true);
     }
     if (columnCount != expected.ColumnCount)
     {
         message = "Invalid Column Count. Expected " + expected.ColumnCount + ", Retrieved " + columnCount;
         return(false);
     }
     else
     {
         message = "Column Count Passed. Expected " + expected.ColumnCount + ", Retrieved " + columnCount;
         return(true);
     }
 }
示例#3
0
        private bool ExecuteScalarTest(SqlCommand cmd, SqlSync.SprocTest.Configuration.ExpectedResult expected, out string message)
        {
            bool passed = true;

            message = "";
            try
            {
                if (cmd.Connection.State == ConnectionState.Closed)
                {
                    cmd.Connection.Open();
                }

                cmd.Transaction = cmd.Connection.BeginTransaction();
                object val = cmd.ExecuteScalar();
                cmd.Transaction.Rollback();

                if (expected.OutputResult != null && expected.OutputResult.Length > 0)
                {
                    if (val == null || expected.OutputResult[0].Value.ToString().Trim().ToLower() != val.ToString().Trim().ToLower())
                    {
                        message = "Invalid Value Returned for Scalar. Expected: '" + expected.OutputResult[0].Value + "', Retrieved: '" + ((val == null) ? "NULL" : val.ToString()) + "'";
                        passed  = false;
                    }
                    else
                    {
                        message += "Scalar Value Passed. Expected: '" + expected.OutputResult[0].Value + "', Retrieved: '" + ((val == null) ? "NULL" : val.ToString()) + "'";
                    }
                }
            }
            catch (SqlException exe)
            {
                return(CheckSqlException(expected, exe, out message));
            }
            catch (Exception ex)
            {
                message = ex.ToString();
                passed  = false;
            }

            return(passed);
        }
示例#4
0
        private bool ExecuteNonQueryTest(SqlCommand cmd, SqlSync.SprocTest.Configuration.ExpectedResult expected, out string message)
        {
            bool passed = true;

            try
            {
                if (cmd.Connection.State == ConnectionState.Closed)
                {
                    cmd.Connection.Open();
                }

                cmd.Transaction = cmd.Connection.BeginTransaction();
                int rowCount = cmd.ExecuteNonQuery();
                cmd.Transaction.Rollback();

                //string countMessage;
                passed = CheckRowCount(rowCount, expected, out message);
                return(passed);
            }
            catch (SqlException exe)
            {
                return(CheckSqlException(expected, exe, out message));
            }
            catch (Exception ex)
            {
                message = ex.ToString();
                return(false);
            }
            finally
            {
                if (cmd.Transaction != null)
                {
                    cmd.Transaction.Rollback();
                }

                cmd.Connection.Close();
            }
        }
示例#5
0
 private bool CheckColumnCount(DataTable tbl, SqlSync.SprocTest.Configuration.ExpectedResult expected, out string message)
 {
     return(CheckColumnCount(tbl.Columns.Count, expected, out message));
 }
示例#6
0
        private bool ExecuteDataSetTest(SqlCommand cmd, SqlSync.SprocTest.Configuration.ExpectedResult expected, out string message)
        {
            message = "";
            List <string> messages        = new List <string>();
            bool          passed          = true;
            bool          outputPassed    = true;
            bool          rowCountPass    = true;
            bool          columnCountPass = true;


            try
            {
                SqlDataAdapter adapt = new SqlDataAdapter(cmd);
                if (cmd.Connection.State == ConnectionState.Closed)
                {
                    cmd.Connection.Open();
                }
                cmd.Transaction = cmd.Connection.BeginTransaction();
                DataSet ds = new DataSet();
                adapt.Fill(ds);
                cmd.Transaction.Rollback();
                if (ds.Tables == null || ds.Tables.Count == 0)
                {
                    outputPassed = false;
                    messages.Add("No DataTables were populated.");
                }
                else
                {
                    string countMessage;
                    rowCountPass = CheckRowCount(ds.Tables[0].Rows.Count, expected, out countMessage);
                    messages.Add(countMessage);

                    string columnMessage;
                    columnCountPass = CheckColumnCount(ds.Tables[0], expected, out columnMessage);
                    messages.Add(columnMessage);


                    if (expected.OutputResult != null && expected.OutputResult.Length > 0)
                    {
                        string outputMessage;

                        for (int i = 0; i < expected.OutputResult.Length; i++)
                        {
                            if (expected.OutputResult[i].RowNumberSpecified && expected.OutputResult[i].RowNumber > ds.Tables[0].Rows.Count)
                            {
                                passed = false;
                                messages.Add("Output result Row Number exceeds actual row count. Expected " + expected.OutputResult[i].RowNumber.ToString() + ", Returned " + ds.Tables[i].Rows.Count.ToString());
                                continue;
                            }

                            //Row should be set in a non-developer centric 1 based value, vs. developer 0 based value
                            int row = (expected.OutputResult[i].RowNumberSpecified) ? expected.OutputResult[i].RowNumber : 1;
                            if (row == 0)
                            {
                                row = 1;
                            }
                            try
                            {
                                if (!CheckOutputValue(ds.Tables[0].Rows[row - 1], expected.OutputResult[i], row, out outputMessage))
                                {
                                    outputPassed = false;
                                }
                                messages.Add(outputMessage);
                            }
                            catch (IndexOutOfRangeException)
                            {
                                messages.Add("Expected output row #" + row + " does not exist");
                                outputPassed = false;
                            }
                        }
                    }
                }

                if (!rowCountPass || !outputPassed || !columnCountPass)
                {
                    passed = false;
                }

                for (int i = 0; i < messages.Count; i++)
                {
                    if (messages[i].Trim().Length > 0)
                    {
                        message += messages[i].Trim() + "\r\n";
                    }
                }
            }
            catch (SqlException exe)
            {
                return(CheckSqlException(expected, exe, out message));
            }
            catch (Exception ex)
            {
                message = ex.ToString();
                passed  = false;
            }

            return(passed);
        }