Merge
This commit is contained in:
@@ -50,35 +50,90 @@ namespace SqlCE4Umbraco
|
||||
/// </summary>
|
||||
internal void ClearDatabase()
|
||||
{
|
||||
// drop constraints before tables to avoid exceptions
|
||||
// looping on try/catching exceptions was not really nice
|
||||
|
||||
// http://stackoverflow.com/questions/536350/drop-all-the-tables-stored-procedures-triggers-constriants-and-all-the-depend
|
||||
|
||||
var localConnection = new SqlCeConnection(ConnectionString);
|
||||
if (System.IO.File.Exists(ReplaceDataDirectory(localConnection.Database)))
|
||||
{
|
||||
var tables = new List<string>();
|
||||
using (var reader = ExecuteReader("select table_name from information_schema.tables where TABLE_TYPE <> 'VIEW'"))
|
||||
List<string> tables;
|
||||
|
||||
// drop foreign keys
|
||||
// SQL may need "where constraint_catalog=DB_NAME() and ..."
|
||||
tables = new List<string>();
|
||||
using (var reader = ExecuteReader("select table_name from information_schema.table_constraints where constraint_type = 'FOREIGN KEY' order by table_name"))
|
||||
{
|
||||
while (reader.Read())
|
||||
while (reader.Read()) tables.Add(reader.GetString("table_name").Trim());
|
||||
}
|
||||
|
||||
foreach (var table in tables)
|
||||
{
|
||||
var constraints = new List<string>();
|
||||
using (var reader = ExecuteReader("select constraint_name from information_schema.table_constraints where constraint_type = 'FOREIGN KEY' and table_name = '" + table + "' order by constraint_name"))
|
||||
{
|
||||
tables.Add(reader.GetString("TABLE_NAME"));
|
||||
while (reader.Read()) constraints.Add(reader.GetString("constraint_name").Trim());
|
||||
}
|
||||
foreach (var constraint in constraints)
|
||||
{
|
||||
// SQL may need "[dbo].[table]"
|
||||
ExecuteNonQuery("alter table [" + table + "] drop constraint [" + constraint + "]");
|
||||
}
|
||||
}
|
||||
|
||||
while(tables.Any())
|
||||
// drop primary keys
|
||||
// SQL may need "where constraint_catalog=DB_NAME() and ..."
|
||||
tables = new List<string>();
|
||||
using (var reader = ExecuteReader("select table_name from information_schema.table_constraints where constraint_type = 'PRIMARY KEY' order by table_name"))
|
||||
{
|
||||
for (var i = 0; i < tables.Count; i++)
|
||||
{
|
||||
var dropTable = "DROP TABLE " + tables[i];
|
||||
while (reader.Read()) tables.Add(reader.GetString("table_name").Trim());
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
foreach (var table in tables)
|
||||
{
|
||||
var constraints = new List<string>();
|
||||
using (var reader = ExecuteReader("select constraint_name from information_schema.table_constraints where constraint_type = 'PRIMARY KEY' and table_name = '" + table + "' order by constraint_name"))
|
||||
{
|
||||
while (reader.Read()) constraints.Add(reader.GetString("constraint_name").Trim());
|
||||
}
|
||||
foreach (var constraint in constraints)
|
||||
{
|
||||
// SQL may need "[dbo].[table]"
|
||||
ExecuteNonQuery("alter table [" + table + "] drop constraint [" + constraint + "]");
|
||||
}
|
||||
}
|
||||
|
||||
// drop tables
|
||||
tables = new List<string>();
|
||||
using (var reader = ExecuteReader("select table_name from information_schema.tables where table_type <> 'VIEW' order by table_name"))
|
||||
{
|
||||
while (reader.Read()) tables.Add(reader.GetString("table_name").Trim());
|
||||
}
|
||||
|
||||
foreach (var table in tables)
|
||||
{
|
||||
ExecuteNonQuery("drop table [" + table + "]");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Drops all foreign keys on a table.
|
||||
/// </summary>
|
||||
/// <param name="table">The name of the table.</param>
|
||||
/// <remarks>To be used in unit tests.</remarks>
|
||||
internal void DropForeignKeys(string table)
|
||||
{
|
||||
var constraints = new List<string>();
|
||||
using (var reader = ExecuteReader("select constraint_name from information_schema.table_constraints where constraint_type = 'FOREIGN KEY' and table_name = '" + table + "' order by constraint_name"))
|
||||
{
|
||||
while (reader.Read()) constraints.Add(reader.GetString("constraint_name").Trim());
|
||||
}
|
||||
foreach (var constraint in constraints)
|
||||
{
|
||||
// SQL may need "[dbo].[table]"
|
||||
ExecuteNonQuery("alter table [" + table + "] drop constraint [" + constraint + "]");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,10 +35,10 @@ namespace Umbraco.Tests.Models
|
||||
[TearDown]
|
||||
public override void TearDown()
|
||||
{
|
||||
base.TearDown();
|
||||
|
||||
//reset the app context
|
||||
DataTypesResolver.Reset();
|
||||
|
||||
base.TearDown();
|
||||
}
|
||||
[Test]
|
||||
public void Can_Generate_Xml_Representation_Of_Content()
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Xml.Linq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.ObjectResolution;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Tests.TestHelpers.Entities;
|
||||
@@ -16,6 +17,8 @@ namespace Umbraco.Tests.Models
|
||||
[SetUp]
|
||||
public override void Initialize()
|
||||
{
|
||||
Resolution.IsFrozen = false;
|
||||
|
||||
//this ensures its reset
|
||||
PluginManager.Current = new PluginManager();
|
||||
|
||||
@@ -26,6 +29,7 @@ namespace Umbraco.Tests.Models
|
||||
typeof(tinyMCE3dataType).Assembly
|
||||
};
|
||||
|
||||
DataTypesResolver.Reset();
|
||||
DataTypesResolver.Current = new DataTypesResolver(
|
||||
() => PluginManager.Current.ResolveDataTypes());
|
||||
|
||||
@@ -35,10 +39,10 @@ namespace Umbraco.Tests.Models
|
||||
[TearDown]
|
||||
public override void TearDown()
|
||||
{
|
||||
base.TearDown();
|
||||
|
||||
//reset the app context
|
||||
DataTypesResolver.Reset();
|
||||
|
||||
base.TearDown();
|
||||
}
|
||||
[Test]
|
||||
public void Can_Generate_Xml_Representation_Of_Media()
|
||||
|
||||
@@ -17,7 +17,11 @@ namespace Umbraco.Tests.Routing
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
InitializeLanguagesAndDomains();
|
||||
|
||||
// ensure we can create them although the content is not in the database
|
||||
TestHelper.DropForeignKeys("umbracoDomains");
|
||||
|
||||
InitializeLanguagesAndDomains();
|
||||
}
|
||||
|
||||
void InitializeLanguagesAndDomains()
|
||||
|
||||
@@ -14,6 +14,14 @@ namespace Umbraco.Tests.Routing
|
||||
[TestFixture]
|
||||
public class NiceUrlsProviderWithDomainsTests : BaseRoutingTest
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
// ensure we can create them although the content is not in the database
|
||||
TestHelper.DropForeignKeys("umbracoDomains");
|
||||
}
|
||||
|
||||
internal override IRoutesCache GetRoutesCache()
|
||||
{
|
||||
return new DefaultRoutesCache(false);
|
||||
|
||||
@@ -16,33 +16,6 @@ using umbraco.cms.businesslogic.template;
|
||||
|
||||
namespace Umbraco.Tests.Routing
|
||||
{
|
||||
[TestFixture, RequiresSTA]
|
||||
public class PublishedContentRequestBuilderTests : BaseRoutingTest
|
||||
{
|
||||
|
||||
//[Test]
|
||||
//public void Alt_Template()
|
||||
//{
|
||||
// var template = Template.MakeNew("test", new User(0));
|
||||
// var altTemplate = Template.MakeNew("alt", new User(0));
|
||||
// var umbracoContext = GetUmbracoContext("/home?altTemplate=" + altTemplate.Alias, template.Id);
|
||||
// // create the new document request since we're rendering a document on the front-end
|
||||
// var docreq = PublishedContentRequest.CreateForFrontEndRequest(umbracoContext);
|
||||
|
||||
// //create the searcher
|
||||
// var searcher = new PublishedContentRequestBuilder(docreq);
|
||||
// //find domain
|
||||
// searcher.LookupDomain();
|
||||
// // redirect if it has been flagged
|
||||
// Assert.IsFalse(docreq.IsRedirect);
|
||||
|
||||
// //find the document, found will be true if the doc request has found BOTH a node and a template
|
||||
// var found = searcher.LookupDocument();
|
||||
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
[TestFixture, RequiresSTA]
|
||||
public class UmbracoModuleTests : BaseRoutingTest
|
||||
{
|
||||
|
||||
@@ -64,6 +64,14 @@ namespace Umbraco.Tests.Routing
|
||||
//Assert.AreEqual("http://domain1.com/1001-1/1001-1-1", routingContext.NiceUrlProvider.GetNiceUrl(100111, true)); // bad
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
// ensure we can create them although the content is not in the database
|
||||
TestHelper.DropForeignKeys("umbracoDomains");
|
||||
}
|
||||
|
||||
internal override IRoutesCache GetRoutesCache()
|
||||
{
|
||||
return new DefaultRoutesCache(false);
|
||||
|
||||
@@ -31,6 +31,17 @@ namespace Umbraco.Tests.TestHelpers
|
||||
dataHelper.ClearDatabase();
|
||||
}
|
||||
|
||||
public static void DropForeignKeys(string table)
|
||||
{
|
||||
var databaseSettings = ConfigurationManager.ConnectionStrings[Core.Configuration.GlobalSettings.UmbracoConnectionName];
|
||||
var dataHelper = DataLayerHelper.CreateSqlHelper(databaseSettings.ConnectionString, false) as SqlCEHelper;
|
||||
|
||||
if (dataHelper == null)
|
||||
throw new InvalidOperationException("The sql helper for unit tests must be of type SqlCEHelper, check the ensure the connection string used for this test is set to use SQLCE");
|
||||
|
||||
dataHelper.DropForeignKeys(table);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new database
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user