Tests.Routing - fix tests that were failing
due to Models.ITemplate, Resolution, database constraints...
This commit is contained in:
@@ -118,6 +118,25 @@ namespace SqlCE4Umbraco
|
||||
}
|
||||
}
|
||||
|
||||
/// <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 + "]");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Replaces the data directory with a local path.
|
||||
/// </summary>
|
||||
|
||||
@@ -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.Reset();
|
||||
|
||||
//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_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.Reset();
|
||||
|
||||
//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()
|
||||
|
||||
@@ -15,6 +15,14 @@ namespace Umbraco.Tests.Routing
|
||||
Umbraco.Core.Configuration.UmbracoSettings.UseLegacyXmlSchema = false;
|
||||
}
|
||||
|
||||
Template CreateTemplate(string alias)
|
||||
{
|
||||
var template = new Template(alias, alias, alias);
|
||||
template.Content = ""; // else saving throws with a dirty internal error
|
||||
ApplicationContext.Services.FileService.SaveTemplate(template);
|
||||
return template;
|
||||
}
|
||||
|
||||
[TestCase("/blah")]
|
||||
[TestCase("/default.aspx/blah")] //this one is actually rather important since this is the path that comes through when we are running in pre-IIS 7 for the root document '/' !
|
||||
[TestCase("/home/Sub1/blah")]
|
||||
@@ -22,10 +30,8 @@ namespace Umbraco.Tests.Routing
|
||||
[TestCase("/home/Sub1.aspx/blah")]
|
||||
public void Match_Document_By_Url_With_Template(string urlAsString)
|
||||
{
|
||||
var template = new Template("test");
|
||||
ApplicationContext.Services.FileService.SaveTemplate(template);
|
||||
var altTemplate = new Template("blah");
|
||||
ApplicationContext.Services.FileService.SaveTemplate(altTemplate);
|
||||
var template = CreateTemplate("test");
|
||||
var altTemplate = CreateTemplate("blah");
|
||||
var routingContext = GetRoutingContext(urlAsString, template);
|
||||
var url = routingContext.UmbracoContext.CleanedUmbracoUrl; //very important to use the cleaned up umbraco url
|
||||
var docRequest = new PublishedContentRequest(url, routingContext);
|
||||
|
||||
@@ -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();
|
||||
Umbraco.Core.Configuration.UmbracoSettings.UseLegacyXmlSchema = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
public override void TearDown()
|
||||
{
|
||||
base.TearDown();
|
||||
|
||||
@@ -16,7 +16,6 @@ namespace Umbraco.Tests.Routing
|
||||
[TestFixture]
|
||||
public class RenderRouteHandlerTests : BaseRoutingTest
|
||||
{
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
//this ensures its reset
|
||||
@@ -44,14 +43,21 @@ namespace Umbraco.Tests.Routing
|
||||
SurfaceControllerResolver.Reset();
|
||||
}
|
||||
|
||||
Template CreateTemplate(string alias)
|
||||
{
|
||||
var template = new Template(alias, alias, alias);
|
||||
template.Content = ""; // else saving throws with a dirty internal error
|
||||
ApplicationContext.Services.FileService.SaveTemplate(template);
|
||||
return template;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Will route to the default controller and action since no custom controller is defined for this node route
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Umbraco_Route_Umbraco_Defined_Controller_Action()
|
||||
{
|
||||
var template = new Template("homePage");
|
||||
ApplicationContext.Current.Services.FileService.SaveTemplate(template);
|
||||
var template = CreateTemplate("homePage");
|
||||
var route = RouteTable.Routes["Umbraco_default"];
|
||||
var routeData = new RouteData() { Route = route };
|
||||
var routingContext = GetRoutingContext("~/dummy-page", template.Id, routeData);
|
||||
@@ -79,8 +85,7 @@ namespace Umbraco.Tests.Routing
|
||||
[TestCase("homePage")]
|
||||
public void Umbraco_Route_User_Defined_Controller_Action(string templateName)
|
||||
{
|
||||
var template = new Template(templateName);
|
||||
ApplicationContext.Current.Services.FileService.SaveTemplate(template);
|
||||
var template = CreateTemplate(templateName);
|
||||
var route = RouteTable.Routes["Umbraco_default"];
|
||||
var routeData = new RouteData() {Route = route};
|
||||
var routingContext = GetRoutingContext("~/dummy-page", template.Id, routeData);
|
||||
|
||||
@@ -63,6 +63,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");
|
||||
}
|
||||
|
||||
public override void TearDown()
|
||||
{
|
||||
base.TearDown();
|
||||
|
||||
@@ -33,6 +33,7 @@ namespace Umbraco.Tests.TestHelpers
|
||||
public virtual void Initialize()
|
||||
{
|
||||
TestHelper.SetupLog4NetForTests();
|
||||
Resolution.Reset();
|
||||
TestHelper.InitializeContentDirectories();
|
||||
|
||||
string path = TestHelper.CurrentAssemblyDirectory;
|
||||
|
||||
@@ -32,6 +32,8 @@ namespace Umbraco.Tests.TestHelpers
|
||||
public virtual void Initialize()
|
||||
{
|
||||
TestHelper.SetupLog4NetForTests();
|
||||
Resolution.Reset();
|
||||
RepositoryResolver.Reset();
|
||||
TestHelper.InitializeContentDirectories();
|
||||
|
||||
string path = TestHelper.CurrentAssemblyDirectory;
|
||||
|
||||
@@ -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