Exemple #1
0
        public QueryComparison CompareQueryOutputs(ComparisonInput comparisonInput)
        {
            var resultSetComparisons = new List <ResultSetComparisonResult>();

            using (var command1 = _commandFactory.CreateCommand(comparisonInput.Query1))
                using (var command2 = _commandFactory.CreateCommand(comparisonInput.Query2))
                {
                    ConfigureCommand(command1, comparisonInput.QueryParameters);
                    ConfigureCommand(command2, comparisonInput.QueryParameters);

                    var command1ResultSets = ReadOutput(command1);
                    var command2ResultSets = ReadOutput(command2);

                    var leastResultSets = Math.Min(command1ResultSets.Count, command2ResultSets.Count);

                    for (var set = 0; set < leastResultSets; set++)
                    {
                        var command1ResultSet = command1ResultSets[set];
                        var command2ResultSet = command2ResultSets[set];

                        var summary = new ResultSetComparisonSummary
                        {
                            ColumnsAreSame      = true,
                            ResultsAreIdentical = true
                        };

                        var comparisonOutput = new ResultSetComparisonResult
                        {
                            Output1          = command1ResultSet,
                            Output2          = command2ResultSet,
                            ResultSetSummary = summary
                        };

                        CompareColumnHeadersAndApplyToSummary(command1ResultSet, command2ResultSet, summary);
                        CompareDataAndApplyToSummary(command1ResultSet, command2ResultSet, summary);

                        resultSetComparisons.Add(comparisonOutput);
                    }

                    var allResultSetsIdentical = resultSetComparisons.TrueForAll(r => r.ResultSetSummary.ResultsAreIdentical);
                    var resultSetCountMismatch = command1ResultSets.Count != command2ResultSets.Count;

                    return(new QueryComparison
                    {
                        ResultsAreIdentical = allResultSetsIdentical && !resultSetCountMismatch,
                        ResultSetComparisons = resultSetComparisons,
                        ResultSetCountsAreNotSame = resultSetCountMismatch
                    });
                }
        }
Exemple #2
0
        private static void CompareColumnHeadersAndApplyToSummary(ResultSet command1Output, ResultSet command2Output,
                                                                  ResultSetComparisonSummary summary)
        {
            var command1ColumnCount = command1Output.Columns.Count;
            var command2ColumnCount = command2Output.Columns.Count;
            var fewestColumns       = Math.Min(command1ColumnCount, command2ColumnCount);

            for (var c = 0; c < fewestColumns; c++)
            {
                var command1ColumnHeader         = command1Output.Columns[c];
                var command2ColumnHeader         = command2Output.Columns[c];
                var columnNameIsDifferent        = command1ColumnHeader.Name != command2ColumnHeader.Name;
                var columnDataTypeIsDifferent    = command1ColumnHeader.SqlDataType != command2ColumnHeader.SqlDataType;
                var columnNullabilityIsDifferent = command1ColumnHeader.IsNullable != command2ColumnHeader.IsNullable;
                var sizeIsDifferent = command1ColumnHeader.Size != command2ColumnHeader.Size;

                if (columnNameIsDifferent ||
                    columnDataTypeIsDifferent ||
                    columnNullabilityIsDifferent ||
                    sizeIsDifferent)
                {
                    summary.ResultsAreIdentical = false;
                    summary.ColumnsAreSame      = false;
                    summary.ColumnDifferences.Add(new ColumnDifference
                    {
                        Index                  = c,
                        NameIsDifferent        = columnNameIsDifferent,
                        TypeIsDifferent        = columnDataTypeIsDifferent,
                        NullabilityIsDifferent = columnNullabilityIsDifferent,
                        SizeIsDifferent        = sizeIsDifferent
                    });
                }
            }

            if (command1ColumnCount != command2ColumnCount)
            {
                summary.ResultsAreIdentical = false;
                summary.ColumnsAreSame      = false;
                summary.ColumnCountMismatch = true;
            }
        }
Exemple #3
0
        private static void CompareDataAndApplyToSummary(ResultSet command1Output, ResultSet command2Output,
                                                         ResultSetComparisonSummary summary)
        {
            var smallestRows = Math.Min(command1Output.Rows.Count, command2Output.Rows.Count);

            for (var rowIndex = 0; rowIndex < smallestRows; rowIndex++)
            {
                var row1 = command1Output.Rows[rowIndex];
                var row2 = command2Output.Rows[rowIndex];
                for (var columnIndex = 0; columnIndex < row1.Values.Count; columnIndex++)
                {
                    var result1       = row1.Values[columnIndex];
                    var result2       = row2.Values[columnIndex];
                    var valuesAreSame = AreOutputsSame(result1, result2);
                    if (!valuesAreSame)
                    {
                        summary.ResultsAreIdentical = false;
                        var rowDifference = new RowDifference
                        {
                            RowIndex = rowIndex
                        };
                        rowDifference.CellDifferences.Add(new CellDifference
                        {
                            ColumnIndex = columnIndex
                        });
                        summary.DataDifferences.Add(rowDifference);
                    }
                }

                if (command1Output.Rows.Count != command2Output.Rows.Count)
                {
                    summary.ResultsAreIdentical = false;
                    summary.RowCountMismatch    = true;
                }
            }
        }