我有一些方法用於初始化和清理我用我的測試使用的數據庫,但是我的方法的屬性AssemblyInitialize和AssemblyCleanup沒有觸發。AssemblyCleanup not firing
任何想法?
[TestInitialize]
public void Init()
{
LoadData();
}
[AssemblyInitialize]
public void AssemblyInit()
{
}
public void LoadData(string testDataFileName = "TestData.xml")
{
connectionString = ConfigurationManager.ConnectionStrings["NDbUnit"].ConnectionString;
mySqlDatabase = new NDbUnit.Core.SqlClient.SqlDbUnitTest(connectionString);
mySqlDatabase.ReadXmlSchema("DataSet.xsd");
mySqlDatabase.ReadXml(testDataFileName);
mySqlDatabase.PerformDbOperation(NDbUnit.Core.DbOperationFlag.CleanInsertIdentity);
dataSet = mySqlDatabase.CopyDataSet();
}
[AssemblyCleanup]
public void RemoveDatabases()
{
List<string> databasesToDelete = new List<string>();
ServerConnection serverConnection = new ServerConnection(new SqlConnection(connectionString));
Server server = new Server(serverConnection);
foreach (Database db in server.Databases)
{
if (db.Name.ToLower().Contains(testDatabaseIdentifier))
{
databasesToDelete.Add(db.Name);
}
}
databasesToDelete.ForEach(x =>
{
Database db = new Database(server, x);
db.Refresh();
db.Drop();
});
}
[TestCleanup]
public void CleanUpData()
{
mySqlDatabase.PerformDbOperation(NDbUnit.Core.DbOperationFlag.DeleteAll);
}
你能告訴我們你的代碼的一部分? – 2011-03-02 18:08:40
我可以。這將只需要幾分鐘 – khr055 2011-03-02 18:09:24
順便說一句,我必須提到,我真的想通過AssemblyCleanup屬性來刪除這些數據庫。這不是我失去了我的想法。 – khr055 2011-03-02 18:13:11