Got ApplicationTests working with new unit test project.
Had to fix the ApplicationTree and Application classes to lazily call the Cache method (which is no renamed to EnsureCache) so that we could set the config location in the unit tests. This should also improve performance a teeny bit and allow for better error handling if required.
This commit is contained in:
@@ -18,3 +18,5 @@ using System.Runtime.InteropServices;
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("04436b0a-1dc6-4ee1-9d96-4c04f1a9f429")]
|
||||
|
||||
[assembly: InternalsVisibleTo("Umbraco.Tests")]
|
||||
|
||||
@@ -7,8 +7,10 @@
|
||||
***********************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlServerCe;
|
||||
using System.Linq;
|
||||
using System.Xml;
|
||||
using System.Diagnostics;
|
||||
using umbraco.DataLayer;
|
||||
@@ -44,6 +46,44 @@ namespace SqlCE4Umbraco
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Most likely only will be used for unit tests but will remove all tables from the database
|
||||
/// </summary>
|
||||
internal void ClearDatabase()
|
||||
{
|
||||
var localConnection = new SqlCeConnection(ConnectionString);
|
||||
var dbFile = localConnection.Database;
|
||||
if (System.IO.File.Exists(dbFile))
|
||||
{
|
||||
var tables = new List<string>();
|
||||
using (var reader = ExecuteReader("select table_name from information_schema.tables where TABLE_TYPE <> 'VIEW'"))
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
tables.Add(reader.GetString("TABLE_NAME"));
|
||||
}
|
||||
}
|
||||
|
||||
while(tables.Any())
|
||||
{
|
||||
for (var i = 0; i < tables.Count; i++)
|
||||
{
|
||||
var dropTable = "DROP TABLE " + tables[i];
|
||||
|
||||
try
|
||||
{
|
||||
ExecuteNonQuery(dropTable);
|
||||
tables.Remove(tables[i]);
|
||||
}
|
||||
catch (SqlHelperException ex)
|
||||
{
|
||||
//this will occur because there is no cascade option, so we just wanna try the next one
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new parameter for use with this specific implementation of ISqlHelper.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user