Improve handling executing scripts in the tests (#207)

Executing the SQL script to set up the Northwind database was quite slow during debug. This speeds it up
pull/208/head
Christopher Jolly 2 years ago committed by GitHub
parent 7fb522e90f
commit ff8c50a1dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -148,15 +148,17 @@ namespace EntityFrameworkCore.Jet.FunctionalTests.TestUtilities
.Where(b => !string.IsNullOrEmpty(b))
.ToList();
ExecuteBatch(
Connection,
false,
batches,
(command, batch) =>
Execute(
Connection, command =>
{
foreach (var batch in batches)
{
command.CommandText = batch;
command.ExecuteNonQuery();
});
}
return 0;
}, "");
}
public void DeleteDatabase()
@ -250,46 +252,6 @@ namespace EntityFrameworkCore.Jet.FunctionalTests.TestUtilities
},
state => ExecuteCommand(state.connection, state.execute, state.sql, state.useTransaction, state.parameters));
private static void ExecuteBatch<T>(
DbConnection connection, bool useTransaction, IEnumerable<T> items, Action<DbCommand, T> execute)
{
if (connection.State != ConnectionState.Closed)
{
connection.Close();
}
connection.Open();
try
{
using (var transaction = useTransaction
? connection.BeginTransaction()
: null)
{
foreach (var item in items)
{
new TestJetRetryingExecutionStrategy().Execute(
() =>
{
using (var command = CreateCommand(connection))
{
command.Transaction = transaction;
execute(command, item);
}
});
}
transaction?.Commit();
}
}
finally
{
if (connection.State != ConnectionState.Closed)
{
connection.Close();
}
}
}
private static T ExecuteCommand<T>(
DbConnection connection, Func<DbCommand, T> execute, string sql, bool useTransaction, object[] parameters)
{

Loading…
Cancel
Save