diff --git a/src/Umbraco.Tests/Routing/RoutesCacheTests.cs b/src/Umbraco.Tests/Routing/RoutesCacheTests.cs
new file mode 100644
index 0000000000..80bdcb3b7f
--- /dev/null
+++ b/src/Umbraco.Tests/Routing/RoutesCacheTests.cs
@@ -0,0 +1,42 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using NUnit.Framework;
+using Umbraco.Tests.TestHelpers;
+using Umbraco.Web.PublishedCache.XmlPublishedCache;
+
+namespace Umbraco.Tests.Routing
+{
+ [DatabaseTestBehavior(DatabaseBehavior.NewDbFileAndSchemaPerFixture)]
+ [TestFixture]
+ public class RoutesCacheTests : BaseRoutingTest
+ {
+ [Test]
+ public void U4_7939()
+ {
+ //var routingContext = GetRoutingContext("/test", 1111);
+ var umbracoContext = GetUmbracoContext("/test", 0);
+ var cache = umbracoContext.ContentCache.InnerCache as PublishedContentCache;
+ if (cache == null) throw new Exception("Unsupported IPublishedContentCache, only the Xml one is supported.");
+
+ PublishedContentCache.UnitTesting = false; // else does not write to routes cache
+ Assert.IsFalse(PublishedContentCache.UnitTesting);
+
+ var z = cache.GetByRoute(umbracoContext, false, "/home/sub1");
+ Assert.IsNotNull(z);
+ Assert.AreEqual(1173, z.Id);
+
+ var routes = cache.RoutesCache.GetCachedRoutes();
+ Assert.AreEqual(1, routes.Count);
+
+ // before the fix, the following assert would fail because the route would
+ // have been stored as { 0, "/home/sub1" } - essentially meaning we were NOT
+ // storing anything in the route cache!
+
+ Assert.AreEqual(1173, routes.Keys.First());
+ Assert.AreEqual("/home/sub1", routes.Values.First());
+ }
+ }
+}
diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj
index 2f048f12b5..234591da37 100644
--- a/src/Umbraco.Tests/Umbraco.Tests.csproj
+++ b/src/Umbraco.Tests/Umbraco.Tests.csproj
@@ -193,6 +193,7 @@
+
diff --git a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedContentCache.cs b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedContentCache.cs
index 71c27f2bee..d16133f170 100644
--- a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedContentCache.cs
+++ b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedContentCache.cs
@@ -57,12 +57,12 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
if (content != null && preview == false)
{
var domainRootNodeId = route.StartsWith("/") ? -1 : int.Parse(route.Substring(0, route.IndexOf('/')));
- var iscanon =
- UnitTesting == false
+ var iscanon =
+ UnitTesting == false
&& DomainHelper.ExistsDomainInPath(umbracoContext.Application.Services.DomainService.GetAll(false), content.Path, domainRootNodeId) == false;
// and only if this is the canonical url (the one GetUrl would return)
if (iscanon)
- _routesCache.Store(contentId, route);
+ _routesCache.Store(content.Id, route);
}
return content;
@@ -159,7 +159,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
// we add this check - we look for the document matching "/" and if it's not us, then
// we do not hide the top level path
// it has to be taken care of in GetByRoute too so if
- // "/foo" fails (looking for "/*/foo") we try also "/foo".
+ // "/foo" fails (looking for "/*/foo") we try also "/foo".
// this does not make much sense anyway esp. if both "/foo/" and "/bar/foo" exist, but
// that's the way it works pre-4.10 and we try to be backward compat for the time being
if (node.Parent == null)
@@ -244,8 +244,8 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
private static IPublishedContent ConvertToDocument(XmlNode xmlNode, bool isPreviewing)
{
- return xmlNode == null
- ? null
+ return xmlNode == null
+ ? null
: (new XmlPublishedContent(xmlNode, isPreviewing)).CreateModel();
}
@@ -398,7 +398,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
if (startNodeId > 0)
{
// if in a domain then use the root node of the domain
- xpath = string.Format(XPathStringsDefinition.Root + XPathStrings.DescendantDocumentById, startNodeId);
+ xpath = string.Format(XPathStringsDefinition.Root + XPathStrings.DescendantDocumentById, startNodeId);
}
else
{
@@ -409,7 +409,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
// umbraco does not consistently guarantee that sortOrder starts with 0
// so the one that we want is the one with the smallest sortOrder
// read http://stackoverflow.com/questions/1128745/how-can-i-use-xpath-to-find-the-minimum-value-of-an-attribute-in-a-set-of-elemen
-
+
// so that one does not work, because min(@sortOrder) maybe 1
// xpath = "/root/*[@isDoc and @sortOrder='0']";
@@ -453,7 +453,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
else
{
xpathBuilder.AppendFormat(XPathStrings.ChildDocumentByUrlName, part);
-
+
}
}