예제 #1
0
        public void Execute(Context context)
        {
            context.LogInfo("Using database connection string: {0}", _connectionString);
            context.LogInfo("Executing query: {0}", _sqlQuery.GetFormattedSqlQuery());

            // Sleep for delay seconds...
            System.Threading.Thread.Sleep(_delayBeforeExecution * 1000);

            int rowCount = DatabaseHelper.ExecuteNonQuery(_connectionString, _sqlQuery.GetFormattedSqlQuery());

            if (_numberOfRowsAffected != -1)
            {
                if (rowCount != _numberOfRowsAffected)
                {
                    throw new Exception("Number of rows affected by the query does not match the value specified in the teststep. Number of rows affected was " + rowCount + " and value specified was " + _numberOfRowsAffected);
                }
            }
            else
            {
                context.LogInfo("The number of rows affected by the query matched the value specified in the test step. " + rowCount + "  rows were affected");
            }
        }
예제 #2
0
        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...
            System.Threading.Thread.Sleep(_delayBeforeCheck * 1000);


            var 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 (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 Exception(
                                      String.Format(
                                          "Validation failed for field: {0}. Expected value: {1}, actual value: {2}",
                                          cell.ColumnName, cell.ExpectedValue, dbDataStringValue));
                        }
                    }
                }
            }
        }