Skip to content

Instantly share code, notes, and snippets.

@adamralph
Last active August 29, 2015 14:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamralph/f373d68afc25c6265090 to your computer and use it in GitHub Desktop.
Save adamralph/f373d68afc25c6265090 to your computer and use it in GitHub Desktop.
xBehave.net transaction rollback
[Scenario]
public void MyScenario(..., SqlTransaction transaction)
{
"Given..."
.f(() => ...);
...
"When..."
.f(c =>
{
// Appending .Using(c) will call Dispose() after all steps in the scenario have finished.
// There is no call to Commit(), so the transaction will be rolled back.
transaction = connection.BeginTransaction(IsolationLevel.Serializable).Using(c);
... // mutate the DB
});
"And..."
.f(() => ...); // mutate the DB again
...
"Then..."
.f(() => ...); // assert DB state
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment