我正在尝试对我的数据访问层对象进行一些集成测试。
我正在使用C#,Nunit3和MySQL 5.7。
这是我的代码。
[TestCase("payee", 0)]
[TestCase("payee", 53)]
[TestCase("payee_to_corp_to_permissions", 0)]
[TestCase("payee_to_corp_to_permissions", 53)]
[Test]
public void AllRecordsToMigrateTest(string tableName, decimal corpId)
{
using (TransactionScope transactionScope = new TransactionScope())
{
List<Payee> payees = new List<Payee>
{
new Payee { payee_id = 1, corp_id = 1 },
new Payee { payee_id = 2, corp_id = 53 },
new Payee { payee_id = 3, corp_id = 22, payee_type_id = 3 },
new Payee { payee_id = 4, corp_id = 1 },
};
using (MySqlConnection mySqlConnection = new MySqlConnection(DstConnectionString))
{
mySqlConnection.Open();
foreach (var payee in payees)
{
payee.Insert(mySqlConnection);
}
PayeeToCorpToPermission payeeToCorpToPermission = new PayeeToCorpToPermission { payee_id = 4, corp_id = 53 };
payeeToCorpToPermission.Insert(mySqlConnection);
}
DataTable result = dbConnect.AllRecordsToMigrate(adilasMySQLTable, 53);
Assert.AreEqual(3, result.Rows.Count);
}
}
如果我分别运行这些案例,它们都可以正确执行,但是当我一起运行它们时,在第一个测试案例之后,对于所有测试案例,在payee_id上都会出现主键冲突。
dbConnect打开它自己与设置代码到同一服务器的连接,但不修改任何内容,只是查询。