Multiple actions a targeted to the same database and changes are rolled back instead of being committed.
Characteristics:
- Better performance that the standard API.
- If a test fails, it is not possible to look at the current database state.
If a test has failed, to debug the database state, temporarily switch back to the standard API.
var sqlInstance = new SqlInstance(
name: "theInstanceName",
buildTemplate: TestDbBuilder.CreateTable
);
using (var sqlDatabase = await sqlInstance.BuildWithRollback())
{
var sqlConnection = sqlDatabase.Connection;
//Use the SqlConnection
}
var sqlInstance = new SqlInstance<TheDbContext>(
constructInstance: builder => new TheDbContext(builder.Options));
using (var sqlDatabase = await sqlInstance.BuildWithRollback())
{
var sqlConnection = sqlDatabase.Connection;
var dbContext = sqlDatabase.Context;
//Use the SqlConnection or TheDbContext
}