public static void Compare(SqlTableDefinition definition, ExpectedTable expectedTable) { Assert.Equal(expectedTable.Name, definition.TableName); Assert.Equal(expectedTable.Columns.Count, definition.Columns.Count); if (expectedTable.Columns.All(s => !s.IsRowId)) { Assert.Null(definition.RowIdColumn); } for (int i = 0; i < expectedTable.Columns.Count; i++) { SqlTableColumn actual = definition.Columns.ElementAt(i); ExpectedColumn expected = expectedTable.Columns[i]; Assert.Equal(expected.ClrType, actual.DetectedType); Assert.Equal(expected.Name, actual.Name); Assert.Equal(expected.SqlType, actual.TypeName); Assert.Equal(expected.IsPrimaryKey, actual.IsPartOfPrimaryKey); if (expected.IsRowId) { Assert.Same(actual, definition.RowIdColumn); } } }
/// <summary>Execute cell comparisons for a data row</summary> /// <param name="row">the index of the row to be compared</param> /// <returns>the list of cell comparisons that didn't pass (empty list if all passed)</returns> private List <CellComparison> RowErrors(int row) { var currentRow = row < ExpectedTable.RowCount ? ExpectedTable.DataCell(row, 0) : ActualTable.DataCell(row, 0); var result = new List <CellComparison>(); var maxColumns = Math.Max(ExpectedTable.Row(row).Length, ActualTable.Row(row).Length); for (var column = 0; column < maxColumns; column++) { var currentColumn = ExpectedTable.Header(column); var expectedValue = ExpectedTable.DataCell(row, column); var actualValue = ActualTable.DataCell(row, column); // reset tolerance range to force recalculating per comparison _tolerance.DataRange = null; var comparison = new CellComparison( row, currentRow, column, currentColumn, expectedValue, actualValue, _tolerance ); if (!comparison.Cell.IsOk()) { result.Add(comparison); } } return(result); }
/// <summary>Execute cell comparison for the header row</summary> /// <returns>the list of cell comparisons that didn't pass (empty list if all passed)</returns> private List <CellComparison> HeaderErrors() { const int headerRowNo = -1; var maxColumns = Math.Max(ExpectedTable.ColumnCount, ActualTable.ColumnCount); var result = new List <CellComparison>(); var rowName = ExpectedTable.Header(0); for (var column = 0; column < maxColumns; column++) { var columnName = ExpectedTable.Header(column); var comparison = new CellComparison( headerRowNo, rowName, column, columnName, columnName, ActualTable.Header(column), _tolerance ); if (!comparison.Cell.IsOk()) { result.Add(comparison); } } return(result); }
private static void CreateTableWithOneRecord(SupportsAttribute support, IDatabase db, bool onPrimaryKey) { // add expectation const string expectedContent = "Something"; var expectedTable = new ExpectedTable(string.Format(CultureInfo.InvariantCulture, "Mig4 {0}Identity {1}", onPrimaryKey ? "PK-" : string.Empty, support.DbType), "Id", "Content"); ExpectedTables.Add(expectedTable); expectedTable.Add(1, expectedContent); // create table var table = db.CreateTable(expectedTable.Name); var identityColumn = onPrimaryKey ? table.WithPrimaryKeyColumn("Id", support.DbType).AsIdentity() : table.WithNotNullableColumn("Id", support.DbType).AsIdentity(); identityColumn.OfSize(support.MaximumSize, support.MaximumScale); table.WithNotNullableColumn("Content", DbType.String).OfSize(255); // insert one record to see if Identity works db.Execute(string.Format(CultureInfo.InvariantCulture, @"INSERT INTO ""{0}"" (""{1}"") VALUES ('{2}')", expectedTable.Name, "Content", expectedContent)); }