コード例 #1
0
        public override void Assert(DbConnection validationConnection, SqlExecutionResult[] results)
        {
            base.Assert(validationConnection, results);
            var result        = results[0];
            var resultSetList = new List <int>();

            try
            {
                if (ResultSets.ToUpper() == "ALL")
                {
                    resultSetList.AddRange(Enumerable.Range(1, result.DataSet.Tables.Count));
                }
                else if (ResultSets.Contains(","))
                {
                    resultSetList.AddRange(ResultSets.Split(',').Select(rs => Convert.ToInt16(rs)).Select(dummy => (int)dummy));
                }
                else if (ResultSets.Contains(":"))
                {
                    var temp = ResultSets.Split(':');
                    resultSetList.AddRange(Enumerable.Range(Convert.ToInt32(temp[0]), Convert.ToInt32(temp[1])));
                }
                else
                {
                    throw new ArgumentException("Invalid specification for result sets");
                }
            }
            catch
            {
                throw new ArgumentException(String.Format("{0} is an invalid result set specification.", ResultSets));
            }

            //validate ResultSetList does not include result sets that do not exist
            foreach (var rs in resultSetList.Where(rs => rs > result.DataSet.Tables.Count))
            {
                throw new ArgumentException(String.Format("Result Set {0} does not exist", rs));
            }

            var currentResultSetId = resultSetList[0];
            var currentColumnSet   = result.DataSet.Tables[currentResultSetId - 1].Columns;

            resultSetList.RemoveAt(0);

            foreach (var rs in resultSetList)
            {
                var comparisonTable = result.DataSet.Tables[rs - 1];

                //verify that the same number of columns is the same for as recorded
                if (comparisonTable.Columns.Count != currentColumnSet.Count)
                {
                    throw new Exception
                          (
                              String.Format
                              (
                                  "Result Set {0}: {1} columns in does not match the {2} columns in Result Set {3}",
                                  rs,
                                  comparisonTable.Columns.Count,
                                  currentColumnSet.Count,
                                  currentResultSetId
                              )
                          );
                }

                //loop through columns and verify the base data type of the columns
                for (var c = 0; c < currentColumnSet.Count; c++)
                {
                    if (String.Compare(currentColumnSet[c].ColumnName, comparisonTable.Columns[c].ColumnName, !IsCaseSensitive) != 0)
                    {
                        throw new Exception
                              (
                                  String.Format
                                  (
                                      "Result Set {0}: Column {1} ({2}) does not match name for column in Result Set {3} ({4})",
                                      rs,
                                      c + 1,
                                      comparisonTable.Columns[c].ColumnName,
                                      currentResultSetId,
                                      currentColumnSet[c].ColumnName
                                  )
                              );
                    }

                    //compare datatypes
                    if (IsLooseComparison)
                    {
                        var currentType    = GetLooseType(currentColumnSet[c].DataType.Name);
                        var comparisonType = GetLooseType(comparisonTable.Columns[c].DataType.Name);

                        if (currentType != comparisonType)
                        {
                            throw new Exception
                                  (
                                      String.Format
                                      (
                                          "Result Set {0} Column {1} ({2}) does not match type for column in Result Set {3} ({4})",
                                          rs,
                                          c + 1,
                                          comparisonTable.Columns[c].DataType,
                                          currentResultSetId,
                                          currentColumnSet[c].DataType
                                      )
                                  );
                        }
                    }
                    else
                    {
                        if (String.Compare(currentColumnSet[c].DataType.ToString(), comparisonTable.Columns[c].DataType.ToString(), !IsCaseSensitive) != 0)
                        {
                            throw new Exception
                                  (
                                      String.Format
                                      (
                                          "Result Set {0} Column {1} ({2}) does not match type for column in Result Set {3} ({4})",
                                          rs,
                                          c + 1,
                                          comparisonTable.Columns[c].DataType,
                                          currentResultSetId,
                                          currentColumnSet[c].DataType
                                      )
                                  );
                        }
                    }
                }
            }
        }
コード例 #2
0
        public override void Assert(DbConnection validationConnection, SqlExecutionResult[] results)
        {
            base.Assert(validationConnection, results);

            var result        = results[0];
            var resultSetList = new List <int>();

            try
            {
                if (ResultSets.ToUpper() == "ALL")
                {
                    resultSetList.AddRange(Enumerable.Range(1, result.DataSet.Tables.Count));
                }
                else if (ResultSets.Contains(","))
                {
                    resultSetList.AddRange(ResultSets.Split(',').Select(rs => Convert.ToInt16(rs)).Select(dummy => (int)dummy));
                }
                else if (ResultSets.Contains(":"))
                {
                    var temp = ResultSets.Split(':');
                    resultSetList.AddRange(Enumerable.Range(Convert.ToInt32(temp[0]), Convert.ToInt32(temp[1])));
                }
                else
                {
                    throw new ArgumentException("Invalid specification for result sets");
                }
            }
            catch
            {
                throw new ArgumentException(String.Format("{0} is an invalid result set specification.", ResultSets));
            }

            foreach (var rs in resultSetList.Where(rs => rs > result.DataSet.Tables.Count))
            {
                throw new ArgumentException(String.Format("Result Set {0} does not exist", rs));
            }

            var currentResultSetId = resultSetList[0];
            var table        = result.DataSet.Tables[currentResultSetId - 1];
            var numberOfRows = table.Rows.Count;

            resultSetList.RemoveAt(0);

            //loop through batches verifying that the column count for each batch is the same
            foreach (var rs in resultSetList)
            {
                //verify resultset exists
                if (result.DataSet.Tables.Count < rs)
                {
                    throw new Exception(String.Format("Result Set {0} does not exist", rs));
                }

                //actual condition verification
                //verify resultset row count matches expected
                table = result.DataSet.Tables[rs - 1];

                if (table.Rows.Count != numberOfRows)
                {
                    throw new Exception
                          (
                              String.Format
                              (
                                  "Result Set {0}: {1} rows does not match the {2} rows in Result Set {3}",
                                  rs,
                                  table.Rows.Count,
                                  numberOfRows,
                                  currentResultSetId
                              )
                          );
                }
            }
        }
コード例 #3
0
        public override void Assert(DbConnection validationConnection, SqlExecutionResult[] results)
        {
            base.Assert(validationConnection, results);

            var result        = results[0];
            var resultSetList = new List <int>();

            try
            {
                if (ResultSets.ToUpper() == "ALL")
                {
                    resultSetList.AddRange(Enumerable.Range(1, result.DataSet.Tables.Count));
                }
                else if (ResultSets.Contains(","))
                {
                    resultSetList.AddRange(ResultSets.Split(',').Select(rs => Convert.ToInt16(rs)).Select(dummy => (int)dummy));
                }
                else if (ResultSets.Contains(":"))
                {
                    var temp = ResultSets.Split(':');
                    resultSetList.AddRange(Enumerable.Range(Convert.ToInt32(temp[0]), Convert.ToInt32(temp[1])));
                }
                else
                {
                    throw new ArgumentException("Invalid specification for result sets");
                }
            }
            catch
            {
                throw new ArgumentException(String.Format("{0} is an invalid result set specification.", ResultSets));
            }

            foreach (var rs in resultSetList.Where(rs => rs > result.DataSet.Tables.Count))
            {
                throw new ArgumentException(String.Format("ResultSet {0} does not exist", rs));
            }

            var currentResultSetId = resultSetList[0];
            var firstTable         = result.DataSet.Tables[currentResultSetId - 1];

            resultSetList.RemoveAt(0);

            //loop through batches verifying that the column count for each batch is the same
            foreach (var rs in resultSetList)
            {
                //verify resultset exists
                if (result.DataSet.Tables.Count < rs)
                {
                    throw new Exception(String.Format("ResultSet {0} does not exist", rs));
                }

                var secondTable = result.DataSet.Tables[rs - 1];

                //verify that the same number of columns is the same for as recorded
                if (firstTable.Columns.Count != secondTable.Columns.Count)
                {
                    throw new Exception
                          (
                              String.Format
                              (
                                  "Result Set {0}: {1} columns in does not match the {2} columns in Result Set {3}",
                                  currentResultSetId,
                                  firstTable.Columns.Count,
                                  secondTable.Columns.Count,
                                  rs
                              )
                          );
                }

                //verify that the number of rows is the same for as recorded
                if (firstTable.Rows.Count != secondTable.Rows.Count)
                {
                    throw new Exception
                          (
                              String.Format
                              (
                                  "Result Set {0}: {1} rows does not match the {2} rows in Result Set {3}",
                                  currentResultSetId,
                                  firstTable.Rows.Count,
                                  secondTable.Rows.Count,
                                  rs
                              )
                          );
                }

                var differenceTable = DataSetComparison.CompareDataTables(firstTable, secondTable, IsCaseSensitive, EnforceOrder);

                if (differenceTable.Rows.Count != 0)
                {
                    throw new Exception
                          (
                              String.Format
                              (
                                  "Result Set {0} and Result Set {2} had {1} mismatched records total",
                                  currentResultSetId,
                                  differenceTable.Rows.Count,
                                  rs
                              )
                          );
                }
            }
        }