diff --git a/src/Umbraco.Tests/PublishedContent/DynamicDocumentTestsBase.cs b/src/Umbraco.Tests/PublishedContent/DynamicDocumentTestsBase.cs index 86a47aea86..792b0eb444 100644 --- a/src/Umbraco.Tests/PublishedContent/DynamicDocumentTestsBase.cs +++ b/src/Umbraco.Tests/PublishedContent/DynamicDocumentTestsBase.cs @@ -43,6 +43,7 @@ namespace Umbraco.Tests.PublishedContent 1 + This is some content]]> @@ -78,6 +79,38 @@ namespace Umbraco.Tests.PublishedContent /// protected abstract dynamic GetDynamicNode(int id); + [Test] + public void Recursive_Property() + { + var doc = GetDynamicNode(1174); + var prop = doc.GetProperty("siteTitle", true); + Assert.IsNotNull(prop); + Assert.AreEqual("This is my site", prop.Value); + prop = doc.GetProperty("_siteTitle"); //test with underscore prefix + Assert.IsNotNull(prop); + Assert.AreEqual("This is my site", prop.Value); + Assert.AreEqual("This is my site", doc._siteTitle); + } + + /// + /// Tests the internal instance level caching of returning properties + /// + /// + /// http://issues.umbraco.org/issue/U4-1824 + /// http://issues.umbraco.org/issue/U4-1825 + /// + [Test] + public void Can_Return_Property_And_Value() + { + var doc = GetDynamicNode(1173); + + Assert.IsTrue(doc.HasProperty("umbracoUrlAlias")); + var prop = doc.GetProperty("umbracoUrlAlias"); + Assert.IsNotNull(prop); + Assert.AreEqual("page2/alias, 2ndpagealias", prop.Value); + Assert.AreEqual("page2/alias, 2ndpagealias", doc.umbracoUrlAlias); + } + /// /// Tests the IsLast method with the result set from a Where statement /// diff --git a/src/Umbraco.Web/Models/DynamicPublishedContent.cs b/src/Umbraco.Web/Models/DynamicPublishedContent.cs index 0cf3ed24a8..fc43675f2b 100644 --- a/src/Umbraco.Web/Models/DynamicPublishedContent.cs +++ b/src/Umbraco.Web/Models/DynamicPublishedContent.cs @@ -653,7 +653,14 @@ namespace Umbraco.Web.Models public IPublishedContentProperty GetProperty(string alias) { - return GetProperty(alias, false); + var prop = GetProperty(alias, false); + if (prop == null && alias.StartsWith("_")) + { + //if it is prefixed and the first result failed, try to get it by recursive + var recursiveAlias = alias.Substring(1, alias.Length - 1); + return GetProperty(recursiveAlias, true); + } + return prop; } public IPublishedContentProperty GetProperty(string alias, bool recursive) { diff --git a/src/umbraco.MacroEngines/RazorDynamicNode/DynamicNode.cs b/src/umbraco.MacroEngines/RazorDynamicNode/DynamicNode.cs index 6482e99014..13ac75f00c 100644 --- a/src/umbraco.MacroEngines/RazorDynamicNode/DynamicNode.cs +++ b/src/umbraco.MacroEngines/RazorDynamicNode/DynamicNode.cs @@ -1364,6 +1364,12 @@ namespace umbraco.MacroEngines prop = n.GetProperty(alias); } } + if (prop == null && alias.StartsWith("_")) + { + //if the prop is still null but it starts with an _ then we'll check recursively + var recursiveAlias = alias.Substring(1, alias.Length - 1); + prop = n.GetProperty(recursiveAlias, true); + } } catch (Exception) {