private static void FiddleWithPropertiesAsFakeProxiedDbDataAdapter(FakeProxiedDbDataAdapter adapter) { { FakeDbCommand cmd = adapter.SelectCommand; adapter.SelectCommand = null; adapter.SelectCommand = cmd; } { FakeDbCommand cmd = adapter.InsertCommand; adapter.InsertCommand = null; adapter.InsertCommand = cmd; } { FakeDbCommand cmd = adapter.DeleteCommand; adapter.DeleteCommand = null; adapter.DeleteCommand = cmd; } { FakeDbCommand cmd = adapter.UpdateCommand; adapter.UpdateCommand = null; adapter.UpdateCommand = cmd; } }
public void FakeDbDataAdapter_properties_should_not_have_infinite_loops_and_stack_overflows() { List <TestTable> randomDataSource = RandomDataGenerator.CreateRandomTables(seed: 1, tableCount: 2, /*allowZeroRowsInTablesByIdx: */ 1, 3); // Test that .Dispose() works (DbDataAdapter clears mutable properties in its disposal method) using (FakeDbConnection connection = new FakeDbConnection(asyncMode: AsyncMode.AllowSync)) using (FakeDbCommand selectCommand = connection.CreateCommand(testTables: randomDataSource)) using (FakeDbDataAdapter adapter = new FakeDbDataAdapter(selectCommand)) { } using (FakeDbConnection connection = new FakeDbConnection(asyncMode: AsyncMode.AllowSync)) using (FakeDbCommand selectCommand1 = connection.CreateCommand(testTables: randomDataSource)) using (FakeDbCommand selectCommand2 = connection.CreateCommand(testTables: randomDataSource)) using (FakeDbDataAdapter adapter = new FakeDbDataAdapter(selectCommand1)) { using (FakeProxiedDbDataAdapter prox = new FakeProxiedDbDataAdapter(selectCommand1)) { FiddleWithPropertiesAsFakeProxiedDbDataAdapter(prox); FiddleWithPropertiesAsFakeDbDataAdapter(prox); FiddleWithPropertiesAsDbDataAdapter(prox); FiddleWithPropertiesAsIDbDataAdapter(prox); } FiddleWithPropertiesAsFakeDbDataAdapter(adapter); FiddleWithPropertiesAsDbDataAdapter(adapter); FiddleWithPropertiesAsIDbDataAdapter(adapter); } }
protected async Task <TResult> DoRunProxiedDbDataAdapterAsync(Int32 seed, Int32 tableCount) { List <TestTable> randomDataSource = RandomDataGenerator.CreateRandomTables(seed: seed, tableCount: tableCount); using (FakeDbConnection connection = new FakeDbConnection(asyncMode: AsyncMode.AwaitAsync)) using (FakeDbCommand selectCommand = connection.CreateCommand(testTables: randomDataSource)) { await connection.OpenAsync(); using (FakeProxiedDbDataAdapter adapter = new FakeProxiedDbDataAdapter(selectCommand)) { return(await this.RunProxiedDbDataAdapterAsync(randomDataSource, adapter)); } } }
protected override async Task <DataSet> RunProxiedDbDataAdapterAsync(List <TestTable> randomDataSource, FakeProxiedDbDataAdapter adapter) { DataSet dataSet = new DataSet(); Int32 rowsInFirstTable = await adapter.Fill2Async(dataSet, srcTable : "Foobar"); rowsInFirstTable.ShouldBe(40); return(dataSet); }
protected override async Task <DataSet> RunProxiedDbDataAdapterAsync(List <TestTable> randomDataSource, FakeProxiedDbDataAdapter adapter) { DataSet dataSet = new DataSet(); Int32 rowsInFirstTable = await adapter.Fill3Async(dataSet, startRecord : 5, maxRecords : 10, srcTable : "Barqux"); rowsInFirstTable.ShouldBe(10); return(dataSet); }
protected override async Task <U1Pair> RunProxiedDbDataAdapterAsync(List <TestTable> randomDataSource, FakeProxiedDbDataAdapter adapter) { using (DbCommandBuilder cmdBuilder = await adapter.CreateCommandBuilderAsync().ConfigureAwait(false)) { DataSet dataSet = new DataSet(); Int32 rowsInFirstTable = await adapter.FillAsync(dataSet); rowsInFirstTable.ShouldBe(40); // Dictionary <String, Int32> rowsModified = DataTableMethods.MutateDataSet(dataSet); List <(String tableName, String command)> executedCommands = new List <(string tableName, string command)>(); // adapter.UpdateCommand = (FakeDbCommand)cmdBuilder.GetUpdateCommand(); adapter.UpdateCommand.NonQueryResultRowCountValue = (cmd) => DataTableMethods.GetUpdateStatementNonQueryResultRowCountValue(expectedTableName: "TODO", adapter, dataSet, cmd, rowsModified, executedCommands); // Int32 updatedRows = await adapter.Update1Async(dataSet); // updatedRows... in first table only? // updatedRows.ShouldBe( rowsModified ); return(dataSet, rowsModified, updatedRows); } }
protected override async Task <FS1Pair> RunProxiedDbDataAdapterAsync(List <TestTable> randomDataSource, FakeProxiedDbDataAdapter adapter) { DataSet dataSet = new DataSet(); DataTable[] schemaTables = await adapter.FillSchema1Async(dataSet, schemaType : this.SchemaType); return(dataSet, schemaTables); }
protected override FS1Pair RunProxiedDbDataAdapter(List <TestTable> randomDataSource, FakeProxiedDbDataAdapter adapter) { DataSet dataSet = new DataSet(); DataTable[] schemaTables = adapter.FillSchema1(dataSet, schemaType: this.SchemaType); return(dataSet, schemaTables); }
protected override async Task <U2Pair> RunProxiedDbDataAdapterAsync(List <TestTable> randomDataSource, FakeProxiedDbDataAdapter 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 = await adapter.FillAsync(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); } }
protected override U4Pair RunProxiedDbDataAdapter(List <TestTable> randomDataSource, FakeProxiedDbDataAdapter adapter) { using (FakeDbCommandBuilder cmdBuilder = new FakeDbCommandBuilder(adapter)) { DataSet dataSet = new DataSet(); // `.Fill` returns the number of rows in the first table, not any subsequent tables. Yes, that's silly. Int32 rowsInFirstTable = adapter.Fill(dataSet); rowsInFirstTable.ShouldBe(40); // Dictionary <String, Int32> rowsModified = DataTableMethods.MutateDataSet(dataSet); // adapter.UpdateCommand = cmdBuilder.GetUpdateCommand(); adapter.UpdateCommand.NonQueryResultRowCountValue = (cmd) => DataTableMethods.GetUpdateStatementNonQueryResultRowCountValue(expectedTableName: "TODO", adapter, dataSet, cmd, rowsModified); Int32 updatedRows = adapter.Update4(dataSet, srcTable: "RandomDataTable_2"); // updatedRows.ShouldBe( rowsModified ); return(dataSet, rowsModified, updatedRows); } }
protected override FS2Pair RunProxiedDbDataAdapter(List <TestTable> randomDataSource, FakeProxiedDbDataAdapter adapter) { DataTable dataTable = new DataTable(); DataTable schemaTables = adapter.FillSchema2(dataTable, schemaType: this.SchemaType); return(dataTable, schemaTables); }
protected override DataSet RunProxiedDbDataAdapter(List <TestTable> randomDataSource, FakeProxiedDbDataAdapter adapter) { DataSet dataSet = new DataSet(); Int32 rowsInFirstTable = adapter.Fill1(dataSet); rowsInFirstTable.ShouldBe(40); return(dataSet); }
protected override async Task <DataTable> RunProxiedDbDataAdapterAsync(List <TestTable> randomDataSource, FakeProxiedDbDataAdapter adapter) { DataTable dataTable = new DataTable(); Int32 rowsInFirstTable = await adapter.Fill4Async(dataTable : dataTable); rowsInFirstTable.ShouldBe(40); return(dataTable); }
protected override async Task <DataTable[]> RunProxiedDbDataAdapterAsync(List <TestTable> randomDataSource, FakeProxiedDbDataAdapter adapter) { DataTable[] tables = new DataTable[5] { new DataTable(tableName: "Foo", tableNamespace: "NS1"), new DataTable(tableName: "Bar", tableNamespace: "NS1"), new DataTable(tableName: "Baz", tableNamespace: "NS1"), new DataTable(tableName: "Qux", tableNamespace: "NS1"), new DataTable(tableName: "Tux", tableNamespace: "NS1") }; Int32 rowsInFirstTable = await adapter.Fill5Async(startRecord : 0, maxRecords : 0, dataTables : tables); rowsInFirstTable.ShouldBe(40); return(tables); }
protected abstract Task <TResult> RunProxiedDbDataAdapterAsync(List <TestTable> randomDataSource, FakeProxiedDbDataAdapter adapter);