I am looking for a quick way to clear the data from my tables performing integration tests with EF.
It seems that all transactions flow around with their testing method and delete the transaction after the test.
Thus, data is never written to the table.
Things like the new automatic IDs for inserts still work, but I ask myself how reliable is this method compared to .commit () transaction.
Are there any flaws in using this approach that do not seem to be a real integration test since the database never gets under way ...
Or, in other words, faulty scripts arise that do not appear as exceptions using a transaction without commit ()?
UPDATE
public abstract class IntegrationTestsBase { protected TransactionScope TransactionScope; public abstract void TestSetup(); protected void InitTestSetupOnTable(string tableName) { TransactionScope = new TransactionScope(); using (var context = new TGBContext()) { var cmdCommand = string.Format("DBCC CHECKIDENT ({0}, RESEED, 1)", tableName); context.Database.ExecuteSqlCommand(cmdCommand); context.SaveChanges(); } } [TestCleanup] public void TestCleanup() { TransactionScope.Dispose(); } } [TestClass] public class MyTests : IntegrationTestsBase { [TestInitialize] public override void TestSetup() { base.InitTestSetupOnTable("MyTableName"); } }
source share