/// <summary>
        /// Overloaded Execute method for SubSteps.
        /// </summary>
        /// <param name="value">Value from Parent step needed to update substep query if required</param>
        /// <param name="context">Context</param>
        public void Execute(string value, Context context)
        {
            context.LogInfo("Using database connection string: {0}", ConnectionString);
            string sqlQueryToExecute = SQLQuery.GetFormattedSqlQuery(context);

            sqlQueryToExecute = sqlQueryToExecute.Replace("@param", value);

            // Sleep for delay seconds...
            if (0 < DelayBeforeCheck)
            {
                context.LogInfo("Sleeping for: {0} seconds", DelayBeforeCheck);
                System.Threading.Thread.Sleep(DelayBeforeCheck * 1000);
            }

            context.LogInfo("Executing database query: {0}", sqlQueryToExecute);
            DataSet ds = FillDataSet(ConnectionString, sqlQueryToExecute);

            if (IsRowValidation)
            {
                if (NumberOfRowsExpected != ds.Tables[0].Rows.Count)
                {
                    throw new ApplicationException(string.Format("Number of rows expected to be returned by the query does not match the value specified in the teststep. Number of rows the NnumberOfRowsExpected were: {0}, actual: {1}", NumberOfRowsExpected, ds.Tables[0].Rows.Count));
                }

                context.LogInfo("NumberOfRowsExpected: {0}, actual number returned: {1}", NumberOfRowsExpected, ds.Tables[0].Rows.Count);
                _stepCompleted = true;
            }
        }
Exemple #2
0
        /// <summary>
        /// Execute()
        /// </summary>
        /// <param name='context'>The context for the test, this holds state that is passed beteen tests</param>
        public override void Execute(Context context)
        {
            context.LogInfo("Using database connection string: {0}", ConnectionString);
            string sqlQueryToExecute = SQLQuery.GetFormattedSqlQuery(context);

            // Sleep for delay seconds...
            if (0 < DelayBeforeCheck)
            {
                context.LogInfo("Sleeping for: {0} seconds", DelayBeforeCheck);
                System.Threading.Thread.Sleep(DelayBeforeCheck * 1000);
            }

            context.LogInfo("Executing database query: {0}", sqlQueryToExecute);
            DataSet ds = FillDataSet(ConnectionString, sqlQueryToExecute);

            if (NumberOfRowsExpected != ds.Tables[0].Rows.Count)
            {
                throw new ApplicationException(string.Format("Number of rows expected to be returned by the query does not match the value specified in the teststep. Number of rows the NnumberOfRowsExpected were: {0}, actual: {1}", NumberOfRowsExpected, ds.Tables[0].Rows.Count));
            }

            context.LogInfo("NumberOfRowsExpected: {0}, actual number returned: {1}", NumberOfRowsExpected, ds.Tables[0].Rows.Count);

            if (0 == NumberOfRowsExpected)
            {
                return;
            }

            if (0 < DbRowsToValidate.Count)
            {
                int rowCount = 0;

                foreach (var dbRowToValidate in DbRowsToValidate)
                {
                    context.LogInfo("Validating row number: {0}", rowCount);

                    var resultRow = ds.Tables[0].Rows[rowCount];;
                    var cells     = dbRowToValidate.Cells;

                    foreach (DbCellToValidate cell in cells)
                    {
                        object dbData            = resultRow[cell.ColumnName];
                        var    dbDataStringValue = string.Empty;

                        if (0 == ValidateData(dbData, cell.ExpectedValue, ref dbDataStringValue))
                        {
                            context.LogInfo("Validation succeeded for field: {0}. Expected value: {1}", cell.ColumnName, dbDataStringValue);
                        }
                        else
                        {
                            throw new Exception(String.Format("Validation failed for field: {0}. Expected value: {1}, actual value: {2}", cell.ColumnName, cell.ExpectedValue, dbDataStringValue));
                        }
                    }

                    rowCount++;
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Execute()
        /// </summary>
        /// <param name='context'>The context for the test, this holds state that is passed beteen tests</param>
        public override void Execute(Context context)
        {
            context.LogInfo("Using database connection string: {0}", ConnectionString);

            string sqlQueryToExecute;

            if (SQLQuery is SqlQueryExtended)
            {
                sqlQueryToExecute = ((SqlQueryExtended)SQLQuery).GetFormattedSqlQuery(context);
            }
            else
            {
                sqlQueryToExecute = SQLQuery.GetFormattedSqlQuery(context);
            }

            var    cont = true;
            string errorMessage;
            var    now = DateTime.Now;

            do
            {
                // Sleep for delay seconds...
                if (0 < DelayBeforeCheck)
                {
                    context.LogInfo("Sleeping for: {0} seconds", DelayBeforeCheck);
                    System.Threading.Thread.Sleep(DelayBeforeCheck * 1000);
                }

                context.LogInfo("Executing database query: {0}", sqlQueryToExecute);
                var ds = FillDataSet(ConnectionString, sqlQueryToExecute);

                if (CheckData(context, ds, out errorMessage))
                {
                    cont = false;
                }
            } while (cont && (now.AddMilliseconds(Timeout).CompareTo(DateTime.Now) > 0));

            if (!string.IsNullOrEmpty(errorMessage))
            {
                throw new Exception(errorMessage);
            }
        }
        /// <summary>
        /// Execute()
        /// </summary>
        /// <param name='context'>The context for the test, this holds state that is passed beteen tests</param>
        public override void Execute(Context context)
        {
            context.LogInfo("Using database connection string: {0}", ConnectionString);
            string sqlQueryToExecute = SQLQuery.GetFormattedSqlQuery(context);

            // Sleep for delay seconds...
            if (0 < DelayBeforeCheck)
            {
                context.LogInfo("Sleeping for: {0} seconds", DelayBeforeCheck);
                System.Threading.Thread.Sleep(DelayBeforeCheck * 1000);
            }

            context.LogInfo("Executing database query: {0}", sqlQueryToExecute);
            DataSet ds = FillDataSet(ConnectionString, sqlQueryToExecute);

            if (IsDbUpdate)
            {
                context.LogInfo("DB Updated.");
                _stepCompleted = true;
            }

            if (IsRowValidation)
            {
                if (NumberOfRowsExpected != ds.Tables[0].Rows.Count)
                {
                    throw new ApplicationException(string.Format("Number of rows expected to be returned by the query does not match the value specified in the teststep. Number of rows the NnumberOfRowsExpected were: {0}, actual: {1}", NumberOfRowsExpected, ds.Tables[0].Rows.Count));
                }

                context.LogInfo("NumberOfRowsExpected: {0}, actual number returned: {1}", NumberOfRowsExpected, ds.Tables[0].Rows.Count);
                _stepCompleted = true;
            }

            if (IsValueValidation)
            {
                if (ds.Tables[0].Rows.Count == 1)
                {
                    _actualValue = ds.Tables[0].Rows[0][0].ToString().Trim();
                    if (ExpectedDbValue != _actualValue)
                    {
                        throw new ApplicationException(string.Format("The value returned by the query does not match the value specified in the teststep. Expected value was: {0}, Actual: {1}", ExpectedDbValue, _actualValue));
                    }
                    context.LogInfo("Expecte Value: {0}, Actual Value Returned: {1}", ExpectedDbValue, _actualValue);
                }
                else if (ds.Tables[0].Rows.Count > 1)
                {
                    throw new ApplicationException(string.Format("More than one rows returned!"));
                }
                else
                {
                    throw new ApplicationException(string.Format("No row returned!"));
                }
                _stepCompleted = true;
            }

            if (0 < DbRowsToValidate.Count)
            {
                int rowCount = 0;

                foreach (var dbRowToValidate in DbRowsToValidate)
                {
                    context.LogInfo("Validating row number: {0}", rowCount);

                    var resultRow = ds.Tables[0].Rows[rowCount];
                    var cells     = dbRowToValidate.Cells;

                    foreach (DbCellToValidate cell in cells)
                    {
                        object dbData            = resultRow[cell.ColumnName];
                        var    dbDataStringValue = string.Empty;

                        if (0 == ValidateData(dbData, cell.ExpectedValue, ref dbDataStringValue))
                        {
                            context.LogInfo("Validation succeeded for field: {0}. Expected value: {1}", cell.ColumnName, dbDataStringValue);
                        }
                        else
                        {
                            throw new Exception(String.Format("Validation failed for field: {0}. Expected value: {1}, actual value: {2}", cell.ColumnName, cell.ExpectedValue, dbDataStringValue));
                        }
                    }

                    rowCount++;
                }
                _stepCompleted = true;
            }

            foreach (var subStep in _subSteps)
            {
                try
                {
                    // Try the validation and catch the exception
                    subStep.Execute(_actualValue, context);
                }
                catch (Exception ex)
                {
                    context.LogException(ex);
                    throw;
                }
            }

            if (!_stepCompleted)
            {
                throw new ApplicationException(string.Format("No Test Action Selected for DbValidationStep!"));
            }
        }
Exemple #5
0
        /// <summary>
        /// </summary>
        public void Execute(Context context)
        {
            context.LogInfo("Using database connection string: {0}", ConnectionString);
            var sqlQueryToExecute = SQLQuery.GetFormattedSqlQuery();

            context.LogInfo("Executing database query: {0}", sqlQueryToExecute);

            // Sleep for delay seconds...
            Thread.Sleep(DelayBeforeExecution * 1000);


            var ds = FillDataSet(ConnectionString, sqlQueryToExecute);

            if (NumberOfRowsExpected != ds.Tables[0].Rows.Count)
            {
                throw new InvalidOperationException(
                          string.Format(
                              "Number of rows expected to be returned by the query does not match the value specified in the teststep. Number of rows the NnumberOfRowsExpected were: {0}, actual: {1}",
                              NumberOfRowsExpected, ds.Tables[0].Rows.Count));
            }

            context.LogInfo("NumberOfRowsExpected: {0}, actual number returned: {1}", NumberOfRowsExpected,
                            ds.Tables[0].Rows.Count);

            if (0 == NumberOfRowsExpected)
            {
                return;
            }

            if (null != DBRowsToValidate.RowsToValidate)
            {
                foreach (var row in DBRowsToValidate.RowsToValidate)
                {
                    DataRow bamDbRow;

                    // Get the element which has the unique flag on...
                    var uniqueCell = row.UniqueCell;
                    if (null != uniqueCell)
                    {
                        var bamDbRowArray =
                            ds.Tables[0].Select(
                                string.Format("{0} = '{1}'", uniqueCell.ColumnName, uniqueCell.ExpectedValue));
                        bamDbRow = bamDbRowArray[0];
                    }
                    else
                    {
                        bamDbRow = ds.Tables[0].Rows[0];
                    }

                    var cells = row.Cells;
                    foreach (var cell in cells)
                    {
                        var dbData            = bamDbRow[cell.ColumnName];
                        var dbDataStringValue = "";
                        if (0 == ValidateData(dbData, cell.ExpectedValue, ref dbDataStringValue))
                        {
                            context.LogInfo("Validation succeeded for field: {0} equals: {1}", cell.ColumnName,
                                            dbDataStringValue);
                        }
                        else
                        {
                            throw new InvalidOperationException(
                                      string.Format(
                                          "Validation failed for field: {0}. Expected value: {1}, actual value: {2}",
                                          cell.ColumnName, cell.ExpectedValue, dbDataStringValue));
                        }
                    }
                }
            }
        }