I started using TransactionScope to help with my unit tests in order to return the previous state to the test base. Using this with SpecFlow, I have a base class:
public class TransactionScopedFeature
{
private TransactionScope Scope { get; set; }
[BeforeScenario]
public void BaseSetup()
{
this.Scope = new TransactionScope(TransactionScopeOption.RequiresNew);
}
[AfterScenario]
public void BaseCleanup()
{
if (this.Scope != null)
{
this.Scope.Dispose();
}
}
}
All of the above works, when I add records to the database, when I then query the tables after the tests are completed, these tables are empty. Great stuff and very smart!
My question relates to the identity columns in these tables. I noticed that when running multiple tests, the identifier column of my test table increases by 1. I assumed that since TransactionScope will roll back the changes, the identity seed will also be thrown back.
- , ? , SQL script , :
DBCC CHECKIDENT ('dbo.Items', reseed, 0)
, - , .
.
.