私は統合テストを実行しています。テストを開始する前に、私はデータベースを削除し、再度作成しました。最初のテストは成功です。しかし、2番目のテストの開始時に、私は例外が発生します。実行時の統合テストでSqlExceptionがスローされる
SetUp:System.Data.SqlClient.SqlException:データベース "Test"は現在使用中であるため、削除できません。
Сode:
[TestFixture]
class Class1
{
public SqlConnection Repository;
[SetUp]
public void LocInit()
{
Repository = new SqlConnection(@"Data Source=.\SQLEXPRESS; Integrated Security=true;");
Repository.Open();
Repository.Execute("USE master;");
Repository.Execute("DROP DATABASE Test;");
Repository.Execute("USE master; CREATE DATABASE Test;");
Repository.Execute("USE Test;");
}
[Test]
public void Test1()
{
using (var repository = new SqlConnection(@"Data Source=.\SQLEXPRESS; Integrated Security=true;"))
repository.Execute("USE Test; SELECT 10");
}
[Test]
public void Test2()
{
using (var repository = new SqlConnection(@"Data Source=.\SQLEXPRESS; Integrated Security=true;"))
repository.Execute("USE Test; SELECT 10");
}
[TearDown]
public void LocalTearDown()
{
Repository.Dispose();
}
}
は、なぜ私はこの例外を得るのですか?
これは複数の備品に適用されますか? –
これで 'マスター'を見ると、生きている地獄が私を怖がらせます。 –