Skip to content

Latest commit

 

History

History
56 lines (43 loc) · 1.63 KB

with-rollback.md

File metadata and controls

56 lines (43 loc) · 1.63 KB

With Rollback

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.

Usage

var sqlInstance = new SqlInstance(
    name: "theInstanceName",
    buildTemplate: TestDbBuilder.CreateTable
);

using (var sqlDatabase = await sqlInstance.BuildWithRollback())
{
    var sqlConnection = sqlDatabase.Connection;
    //Use the SqlConnection
}

snippet source / anchor

EntityFramework Usage

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
}

snippet source / anchor