我的测试中有以下基础对象
[TestClass]
public abstract class TestClassBase
{
private TransactionScope _transactionScope;
[TestInitialize]
public virtual void TestInitialize()
{
_transactionScope = new TransactionScope(TransactionScopeOption.RequiresNew, new TransactionOptions { Timeout = new TimeSpan(0, 10, 0) });
}
[TestCleanup]
public virtual void TestCleanup()
{
_transactionScope.Dispose();
}
}
我有一个执行以下操作的测试
[TestMethod]
public void SaveToDatebaseTest(
{
Program program = new Program();
program.Name = "Unit Test Program, I should not exists, when Test is done";
ProgramManager programManager = new ProgramManager()
programManager.Save(program);
}
当我运行测试时,记录仍然存在于数据库中。
我想避免在每个测试方法中使用 TransactionScope