protected override async Task <U2Pair> RunBatchingProxiedDbDataAdapterAsync(List <TestTable> randomDataSource, BatchingFakeProxiedDbDataAdapter adapter) { using (DbCommandBuilder <FakeDbCommand> cmdBuilder = await adapter.CreateCommandBuilderAsync().ConfigureAwait(false)) { DataTable dataTable = new DataTable(); // `.Fill` returns the number of rows in the first table, not any subsequent tables. Yes, that's silly. Int32 rowsInFirstTable = adapter.Fill(dataTable); rowsInFirstTable.ShouldBe(40); // Dictionary <String, Int32> rowsModified = DataTableMethods.MutateDataTable(dataTable); // adapter.UpdateCommand = cmdBuilder.GetUpdateCommand(); adapter.UpdateCommand.NonQueryResultRowCountValue = (cmd) => DataTableMethods.GetUpdateStatementNonQueryResultRowCountValue(expectedTableName: "TODO", adapter, dataTable, cmd, rowsModified); DataRow[] rows = dataTable.Rows.Cast <DataRow>().ToArray(); Int32 updatedRows = await adapter.Update2Async(rows); // updatedRows.ShouldBe( rowsModified ); return(rows, rowsModified, updatedRows); } }
public void Proxy_Fill_should_work_identically_to_DbDataReader_Fill() { List <TestTable> randomDataSource = RandomDataGenerator.CreateRandomTables(seed: 1234, tableCount: 5, /*allowZeroRowsInTablesByIdx: */ 1, 3); // Part 1: Use proxy DataSet dataSetFromProxy; { using (FakeDbConnection connection = new FakeDbConnection(asyncMode: AsyncMode.AllowSync)) using (FakeDbCommand selectCommand = connection.CreateCommand(testTables: randomDataSource)) { connection.Open(); using (BatchingFakeProxiedDbDataAdapter adpt = new BatchingFakeProxiedDbDataAdapter(selectCommand)) { dataSetFromProxy = new DataSet(); // `.Fill` returns the number of rows in the first table, not any subsequent tables. Yes, that's silly. Int32 rowsInFirstTable = adpt.Fill(dataSetFromProxy); rowsInFirstTable.ShouldBe(40); } } } // Part 2: Use real DataSet dataSetFromReal; { using (FakeDbConnection connection = new FakeDbConnection(asyncMode: AsyncMode.AllowSync)) using (FakeDbCommand selectCommand = connection.CreateCommand(testTables: randomDataSource)) { connection.Open(); using (FakeDbDataAdapter adpt = new FakeDbDataAdapter(selectCommand)) { dataSetFromReal = new DataSet(); Int32 rowsInFirstTable = adpt.Fill(dataSetFromReal); rowsInFirstTable.ShouldBe(40); } } } // Assert equality: DataTableMethods.DataSetEquals(dataSetFromProxy, dataSetFromReal, out String diffs).ShouldBeTrue(customMessage: diffs); }
public void Proxy_Update_should_work_identically_to_Update() { List <TestTable> randomDataSource = RandomDataGenerator.CreateRandomTables(seed: 1234, tableCount: 5, /*allowZeroRowsInTablesByIdx: */ 1, 3); // TODO: Multiple table UPDATE support is... complicated: https://stackoverflow.com/questions/16218856/how-to-update-two-tables-with-one-dataset // Part 1: Use proxy DataSet dataSetFromProxy; { using (FakeDbConnection connection = new FakeDbConnection(asyncMode: AsyncMode.AllowSync)) using (FakeDbCommand selectCommand = connection.CreateCommand(testTables: randomDataSource)) { connection.Open(); using (BatchingFakeProxiedDbDataAdapter adapter = new BatchingFakeProxiedDbDataAdapter(selectCommand)) using (FakeDbCommandBuilder cmdBuilder = new FakeDbCommandBuilder(adapter)) { dataSetFromProxy = new DataSet(); // `.Fill` returns the number of rows in the first table, not any subsequent tables. Yes, that's silly. Int32 rowsInFirstTable = adapter.Fill(dataSetFromProxy); rowsInFirstTable.ShouldBe(40); // Dictionary <String, Int32> rowsModified = DataTableMethods.MutateDataSet(dataSetFromProxy); // adapter.UpdateCommand = cmdBuilder.GetUpdateCommand(); adapter.UpdateCommand.NonQueryResultRowCountValue = (cmd) => DataTableMethods.GetUpdateStatementNonQueryResultRowCountValue(expectedTableName: "TODO", adapter, dataSetFromProxy, cmd, rowsModified); Int32 updatedRows = adapter.Update(dataSetFromProxy); // updatedRows... in first table only? // updatedRows.ShouldBe( rowsModified ); } } } // Part 2: Use real DataSet dataSetFromReal; { using (FakeDbConnection connection = new FakeDbConnection(asyncMode: AsyncMode.AllowSync)) using (FakeDbCommand selectCommand = connection.CreateCommand(testTables: randomDataSource)) { connection.Open(); using (FakeDbDataAdapter adapter = new FakeDbDataAdapter(selectCommand)) using (FakeDbCommandBuilder cmdBuilder = adapter.CreateCommandBuilder()) { dataSetFromReal = new DataSet(); // `.Fill` returns the number of rows in the first table, not any subsequent tables. Yes, that's silly. Int32 rowsInFirstTable = adapter.Fill(dataSetFromReal); rowsInFirstTable.ShouldBe(40); // Dictionary <String, Int32> rowsModified = DataTableMethods.MutateDataSet(dataSetFromReal); // adapter.UpdateCommand = cmdBuilder.GetUpdateCommand(); adapter.UpdateCommand.NonQueryResultRowCountValue = (cmd) => DataTableMethods.GetUpdateStatementNonQueryResultRowCountValue(expectedTableName: "TODO", adapter, dataSetFromReal, cmd, rowsModified); Int32 updatedRows = adapter.Update(dataSetFromReal); // updatedRows... in first table only? // updatedRows.ShouldBe( rowsModified ); } } } // Assert equality: DataTableMethods.DataSetEquals(dataSetFromProxy, dataSetFromReal, out String diffs).ShouldBeTrue(customMessage: diffs); }