如果我执行以下操作:
public class AIntegrationTests
{
protected TransactionScope transaction = null;
[SetUp]
public void SetUp()
{
transaction = new TransactionScope(TransactionScopeOption.Required);
}
[TearDown]
public void TearDown()
{
transaction.Dispose();
}
}
[TestFixture]
public class UserRepositoryIntegrationTests : AIntegrationTests
{
private UserRepository _sut;
[SetUp]
public void SetUp()
{
_sut = new UserRepository();
}
//tests
}
我收到此错误:
network access for distributed transaction manager (msdtc) has been disabled
Please enable Network DTC access because of qlBulkCopy.WriteToServer(DataTable table)
for particular database
当我从父类中删除事务实例化并将其放回子类中时 我没有错。
public class AIntegrationTests
{
protected TransactionScope transaction = null;
[SetUp]
public void SetUp()
{
}
[TearDown]
public void TearDown()
{
transaction.Dispose();
}
}
[TestFixture]
public class UserRepositoryIntegrationTests : AIntegrationTests
{
private UserRepository _sut;
[SetUp]
public void SetUp()
{
_sut = new UserRepository();
transaction = new TransactionScope(TransactionScopeOption.Required);
}
//tests
}
为什么我不允许在父类中实例化事务。如果我离开Dispose电话 父母一切正常。
答案 0 :(得分:1)
SetUp()
将SetUp()
隐藏在基类中,因此永远不会调用AIntegrationTests
的{{1}}。明确地从SetUp()
的{{1}} ...
UserRepositoryIntegrationTests
由于您可以控制这两个类,因此您应该在基类中创建SetUp()
[TestFixture]
public class UserRepositoryIntegrationTests : AIntegrationTests
{
private UserRepository _sut;
[SetUp]
public void SetUp()
{
_sut = new UserRepository();
base.SetUp();
}
//tests
}
并覆盖它...
SetUp()