fix UriUtility, fix unit tests

This commit is contained in:
Stephan
2012-10-01 09:52:32 -02:00
parent 656c61d1e2
commit dea22f22cb
3 changed files with 41 additions and 19 deletions

View File

@@ -19,39 +19,56 @@ namespace Umbraco.Tests.Routing
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")]
[TestCase("/sub1")]
[TestCase("/sub1.aspx")]
public void Match_Document_By_Url_Hide_Top_Level(string urlAsString)
[TestCase("/", 1046)]
[TestCase("/default.aspx", 1046)] //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", 1173)]
[TestCase("/sub1", 1173)]
[TestCase("/sub1.aspx", 1173)]
[TestCase("/home/sub1", -1)] // should fail
// these two are special. getNiceUrl(1046) returns "/" but getNiceUrl(1172) cannot also return "/" so
// we've made it return "/test-page" => we have to support that url back in the lookup...
[TestCase("/home", 1046)]
[TestCase("/test-page", 1172)]
public void Match_Document_By_Url_Hide_Top_Level(string urlString, int expectedId)
{
var routingContext = GetRoutingContext(urlAsString);
var routingContext = GetRoutingContext(urlString);
var url = routingContext.UmbracoContext.UmbracoUrl; //very important to use the cleaned up umbraco url
var docRequest = new DocumentRequest(url, routingContext);
var docreq = new DocumentRequest(url, routingContext);
var lookup = new LookupByNiceUrl();
ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", "true");
var result = lookup.TrySetDocument(docRequest);
var result = lookup.TrySetDocument(docreq);
Assert.IsTrue(result);
if (expectedId > 0)
{
Assert.IsTrue(result);
Assert.AreEqual(expectedId, docreq.DocumentId);
}
else
{
Assert.IsFalse(result);
}
}
[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("/home/Sub1")]
[TestCase("/Home/Sub1")] //different cases
[TestCase("/home/Sub1.aspx")]
public void Match_Document_By_Url(string urlAsString)
[TestCase("/", 1046)]
[TestCase("/default.aspx", 1046)] //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", 1046)]
[TestCase("/home/Sub1", 1173)]
[TestCase("/Home/Sub1", 1173)] //different cases
[TestCase("/home/Sub1.aspx", 1173)]
public void Match_Document_By_Url(string urlString, int expectedId)
{
var routingContext = GetRoutingContext(urlAsString);
var routingContext = GetRoutingContext(urlString);
var url = routingContext.UmbracoContext.UmbracoUrl; //very important to use the cleaned up umbraco url
var docRequest = new DocumentRequest(url, routingContext);
var docreq = new DocumentRequest(url, routingContext);
var lookup = new LookupByNiceUrl();
var result = lookup.TrySetDocument(docRequest);
var result = lookup.TrySetDocument(docreq);
Assert.IsTrue(result);
Assert.AreEqual(expectedId, docreq.DocumentId);
}
}

View File

@@ -43,6 +43,8 @@ namespace Umbraco.Tests
public void Uri_To_Umbraco(string sourceUrl, string expectedUrl)
{
UriUtility.SetAppDomainAppVirtualPath("/");
var expectedUri = new Uri(expectedUrl);
var sourceUri = new Uri(sourceUrl);
var resultUri = UriUtility.UriToUmbraco(sourceUri);
@@ -74,6 +76,7 @@ namespace Umbraco.Tests
{
ConfigurationManager.AppSettings.Set("umbracoUseDirectoryUrls", directoryUrls ? "true" : "false");
Umbraco.Core.Configuration.UmbracoSettings.AddTrailingSlash = trailingSlash;
UriUtility.SetAppDomainAppVirtualPath("/");
var expectedUri = NewUri(expectedUrl);
var sourceUri = NewUri(sourceUrl);

View File

@@ -54,6 +54,8 @@ namespace Umbraco.Web
{
if (virtualPath.StartsWith(_appPathPrefix))
virtualPath = virtualPath.Substring(_appPathPrefix.Length);
if (virtualPath.Length == 0)
virtualPath = "/";
return virtualPath;
}