Started writing NiceUrlProvider unit tests as there are a bunch of issues with it. Have fixed one of them.
Updated unit test hierarchy of classes so that if one doesn't require a db it can opt out and thus it runs much much faster.
This commit is contained in:
@@ -23,11 +23,21 @@ namespace Umbraco.Tests.Routing
|
||||
base.TearDown();
|
||||
|
||||
ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", "");
|
||||
}
|
||||
}
|
||||
|
||||
protected RoutingContext GetRoutingContext(string url, Template template, RouteData routeData = null)
|
||||
/// <summary>
|
||||
/// Return a new RoutingContext
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="templateId">
|
||||
/// The template Id to insert into the Xml cache file for each node, this is helpful for unit testing with templates but you
|
||||
/// should normally create the template in the database with this id
|
||||
///</param>
|
||||
/// <param name="routeData"></param>
|
||||
/// <returns></returns>
|
||||
protected RoutingContext GetRoutingContext(string url, int templateId, RouteData routeData = null)
|
||||
{
|
||||
var umbracoContext = GetUmbracoContext(url, template, routeData);
|
||||
var umbracoContext = GetUmbracoContext(url, templateId, routeData);
|
||||
var contentStore = new XmlPublishedContentStore();
|
||||
var niceUrls = new NiceUrlProvider(contentStore, umbracoContext);
|
||||
var routingRequest = new RoutingContext(
|
||||
@@ -39,6 +49,29 @@ namespace Umbraco.Tests.Routing
|
||||
return routingRequest;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return a new RoutingContext
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="template"></param>
|
||||
/// <param name="routeData"></param>
|
||||
/// <returns></returns>
|
||||
protected RoutingContext GetRoutingContext(string url, Template template, RouteData routeData = null)
|
||||
{
|
||||
return GetRoutingContext(url, template.Id, routeData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return a new RoutingContext that doesn't require testing based on template
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="routeData"></param>
|
||||
/// <returns></returns>
|
||||
protected RoutingContext GetRoutingContext(string url, RouteData routeData = null)
|
||||
{
|
||||
return GetRoutingContext(url, 1234, routeData);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,15 @@ namespace Umbraco.Tests.Routing
|
||||
[TestFixture]
|
||||
public class LookupByAliasTests : BaseRoutingTest
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// We don't need a db for this test, will run faster without one
|
||||
/// </summary>
|
||||
protected override bool RequiresDbSetup
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
[TestCase("/this/is/my/alias", 1046)]
|
||||
[TestCase("/anotheralias", 1046)]
|
||||
[TestCase("/page2/alias", 1173)]
|
||||
@@ -16,8 +25,7 @@ namespace Umbraco.Tests.Routing
|
||||
[TestCase("/ONLY/one/Alias", 1174)]
|
||||
public void Lookup_By_Url_Alias(string urlAsString, int nodeMatch)
|
||||
{
|
||||
var template = Template.MakeNew("test", new User(0));
|
||||
var routingContext = GetRoutingContext(urlAsString, template);
|
||||
var routingContext = GetRoutingContext(urlAsString);
|
||||
var url = routingContext.UmbracoContext.UmbracoUrl; //very important to use the cleaned up umbraco url
|
||||
var docRequest = new DocumentRequest(url, routingContext);
|
||||
var lookup = new LookupByAlias();
|
||||
|
||||
@@ -8,12 +8,19 @@ namespace Umbraco.Tests.Routing
|
||||
[TestFixture]
|
||||
public class LookupByIdTests : BaseRoutingTest
|
||||
{
|
||||
/// <summary>
|
||||
/// We don't need a db for this test, will run faster without one
|
||||
/// </summary>
|
||||
protected override bool RequiresDbSetup
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
[TestCase("/1046", 1046)]
|
||||
[TestCase("/1046.aspx", 1046)]
|
||||
public void Lookup_By_Id(string urlAsString, int nodeMatch)
|
||||
{
|
||||
var template = Template.MakeNew("test", new User(0));
|
||||
var routingContext = GetRoutingContext(urlAsString, template);
|
||||
var routingContext = GetRoutingContext(urlAsString);
|
||||
var url = routingContext.UmbracoContext.UmbracoUrl; //very important to use the cleaned up umbraco url
|
||||
var docRequest = new DocumentRequest(url, routingContext);
|
||||
var lookup = new LookupByIdPath();
|
||||
|
||||
@@ -10,6 +10,14 @@ namespace Umbraco.Tests.Routing
|
||||
public class LookupByNiceUrlTests : BaseRoutingTest
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// We don't need a db for this test, will run faster without one
|
||||
/// </summary>
|
||||
protected override bool RequiresDbSetup
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
[TestCase("/")]
|
||||
[TestCase("/default.aspx")] //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("/Sub1")]
|
||||
@@ -17,8 +25,7 @@ namespace Umbraco.Tests.Routing
|
||||
[TestCase("/sub1.aspx")]
|
||||
public void Match_Document_By_Url_Hide_Top_Level(string urlAsString)
|
||||
{
|
||||
var template = Template.MakeNew("test", new User(0));
|
||||
var routingContext = GetRoutingContext(urlAsString, template);
|
||||
var routingContext = GetRoutingContext(urlAsString);
|
||||
var url = routingContext.UmbracoContext.UmbracoUrl; //very important to use the cleaned up umbraco url
|
||||
var docRequest = new DocumentRequest(url, routingContext);
|
||||
var lookup = new LookupByNiceUrl();
|
||||
@@ -37,8 +44,7 @@ namespace Umbraco.Tests.Routing
|
||||
[TestCase("/home/Sub1.aspx")]
|
||||
public void Match_Document_By_Url(string urlAsString)
|
||||
{
|
||||
var template = Template.MakeNew("test", new User(0));
|
||||
var routingContext = GetRoutingContext(urlAsString, template);
|
||||
var routingContext = GetRoutingContext(urlAsString);
|
||||
var url = routingContext.UmbracoContext.UmbracoUrl; //very important to use the cleaned up umbraco url
|
||||
var docRequest = new DocumentRequest(url, routingContext);
|
||||
var lookup = new LookupByNiceUrl();
|
||||
|
||||
@@ -9,18 +9,22 @@ namespace Umbraco.Tests.Routing
|
||||
[TestFixture]
|
||||
public class LookupByPageIdQueryTests : BaseRoutingTest
|
||||
{
|
||||
/// <summary>
|
||||
/// We don't need a db for this test, will run faster without one
|
||||
/// </summary>
|
||||
protected override bool RequiresDbSetup
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
[TestCase("/?umbPageId=1046", 1046)]
|
||||
[TestCase("/?UMBPAGEID=1046", 1046)]
|
||||
[TestCase("/default.aspx?umbPageId=1046", 1046)] //TODO: Should this match??
|
||||
[TestCase("/some/other/page?umbPageId=1046", 1046)] //TODO: Should this match??
|
||||
[TestCase("/some/other/page.aspx?umbPageId=1046", 1046)] //TODO: Should this match??
|
||||
public void Lookup_By_Page_Id(string urlAsString, int nodeMatch)
|
||||
{
|
||||
|
||||
|
||||
|
||||
var template = Template.MakeNew("test", new User(0));
|
||||
var routingContext = GetRoutingContext(urlAsString, template);
|
||||
{
|
||||
var routingContext = GetRoutingContext(urlAsString);
|
||||
var url = routingContext.UmbracoContext.UmbracoUrl; //very important to use the cleaned up umbraco url
|
||||
var docRequest = new DocumentRequest(url, routingContext);
|
||||
var lookup = new LookupByPageIdQuery();
|
||||
|
||||
85
src/Umbraco.Tests/Routing/NiceUrlProviderTests.cs
Normal file
85
src/Umbraco.Tests/Routing/NiceUrlProviderTests.cs
Normal file
@@ -0,0 +1,85 @@
|
||||
using System.Configuration;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Umbraco.Tests.Routing
|
||||
{
|
||||
[TestFixture]
|
||||
public class NiceUrlProviderTests : BaseRoutingTest
|
||||
{
|
||||
|
||||
[TestCase(1046, "/home.aspx")]
|
||||
[TestCase(1173, "/home/sub1.aspx")]
|
||||
[TestCase(1174, "/home/sub1/sub2.aspx")]
|
||||
[TestCase(1176, "/home/sub1/sub-3.aspx")]
|
||||
[TestCase(1177, "/home/sub1/custom-sub-1.aspx")]
|
||||
[TestCase(1178, "/home/sub1/custom-sub-2.aspx")]
|
||||
[TestCase(1175, "/home/sub-2.aspx")]
|
||||
[TestCase(1172, "/test-page.aspx")]
|
||||
public void Get_Nice_Url_Not_Hiding_Top_Level_No_Directory_Urls(int nodeId, string niceUrlMatch)
|
||||
{
|
||||
var routingContext = GetRoutingContext("/test", 1111);
|
||||
|
||||
var result = routingContext.NiceUrlProvider.GetNiceUrl(nodeId);
|
||||
|
||||
Assert.AreEqual(niceUrlMatch, result);
|
||||
}
|
||||
|
||||
[TestCase(1046, "/home")]
|
||||
[TestCase(1173, "/home/sub1")]
|
||||
[TestCase(1174, "/home/sub1/sub2")]
|
||||
[TestCase(1176, "/home/sub1/sub-3")]
|
||||
[TestCase(1177, "/home/sub1/custom-sub-1")]
|
||||
[TestCase(1178, "/home/sub1/custom-sub-2")]
|
||||
[TestCase(1175, "/home/sub-2")]
|
||||
[TestCase(1172, "/test-page")]
|
||||
public void Get_Nice_Url_Not_Hiding_Top_Level_With_Directory_Urls(int nodeId, string niceUrlMatch)
|
||||
{
|
||||
var routingContext = GetRoutingContext("/test", 1111);
|
||||
|
||||
ConfigurationManager.AppSettings.Set("umbracoUseDirectoryUrls", "true");
|
||||
|
||||
var result = routingContext.NiceUrlProvider.GetNiceUrl(nodeId);
|
||||
|
||||
Assert.AreEqual(niceUrlMatch, result);
|
||||
}
|
||||
|
||||
[TestCase(1046, "/")]
|
||||
[TestCase(1173, "/sub1.aspx")]
|
||||
[TestCase(1174, "/sub1/sub2.aspx")]
|
||||
[TestCase(1176, "/sub1/sub-3.aspx")]
|
||||
[TestCase(1177, "/sub1/custom-sub-1.aspx")]
|
||||
[TestCase(1178, "/sub1/custom-sub-2.aspx")]
|
||||
[TestCase(1175, "/sub-2.aspx")]
|
||||
[TestCase(1172, "/test-page.aspx")]
|
||||
public void Get_Nice_Url_Hiding_Top_Level_No_Directory_Urls(int nodeId, string niceUrlMatch)
|
||||
{
|
||||
var routingContext = GetRoutingContext("/test", 1111);
|
||||
|
||||
ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", "true");
|
||||
|
||||
var result = routingContext.NiceUrlProvider.GetNiceUrl(nodeId);
|
||||
|
||||
Assert.AreEqual(niceUrlMatch, result);
|
||||
}
|
||||
|
||||
[TestCase(1046, "/")]
|
||||
[TestCase(1173, "/sub1")]
|
||||
[TestCase(1174, "/sub1/sub2")]
|
||||
[TestCase(1176, "/sub1/sub-3")]
|
||||
[TestCase(1177, "/sub1/custom-sub-1")]
|
||||
[TestCase(1178, "/sub1/custom-sub-2")]
|
||||
[TestCase(1175, "/sub-2")]
|
||||
[TestCase(1172, "/test-page")]
|
||||
public void Get_Nice_Url_Hiding_Top_Level_With_Directory_Urls(int nodeId, string niceUrlMatch)
|
||||
{
|
||||
var routingContext = GetRoutingContext("/test", 1111);
|
||||
|
||||
ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", "true");
|
||||
ConfigurationManager.AppSettings.Set("umbracoUseDirectoryUrls", "true");
|
||||
|
||||
var result = routingContext.NiceUrlProvider.GetNiceUrl(nodeId);
|
||||
|
||||
Assert.AreEqual(niceUrlMatch, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user