diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs
index 3967afce79..e9af22b968 100644
--- a/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs
+++ b/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs
@@ -44,11 +44,11 @@ namespace Umbraco.Tests.PublishedContent
var propertyTypes = new[]
{
// AutoPublishedContentType will auto-generate other properties
- new PublishedPropertyType("umbracoNaviHide", 0, Constants.PropertyEditors.TrueFalseAlias),
- new PublishedPropertyType("selectedNodes", 0, "?"),
- new PublishedPropertyType("umbracoUrlAlias", 0, "?"),
- new PublishedPropertyType("content", 0, Constants.PropertyEditors.TinyMCEAlias),
- new PublishedPropertyType("testRecursive", 0, "?"),
+ new PublishedPropertyType("umbracoNaviHide", 0, Constants.PropertyEditors.TrueFalseAlias),
+ new PublishedPropertyType("selectedNodes", 0, "?"),
+ new PublishedPropertyType("umbracoUrlAlias", 0, "?"),
+ new PublishedPropertyType("content", 0, Constants.PropertyEditors.TinyMCEAlias),
+ new PublishedPropertyType("testRecursive", 0, "?"),
};
var compositionAliases = new[] {"MyCompositionAlias"};
var type = new AutoPublishedContentType(0, "anything", compositionAliases, propertyTypes);
@@ -73,7 +73,7 @@ namespace Umbraco.Tests.PublishedContent
protected override string GetXmlContent(int templateId)
{
return @"
-
@@ -87,17 +87,17 @@ namespace Umbraco.Tests.PublishedContent
This is some content]]>
-
+
-
+
-
+
1
@@ -211,8 +211,8 @@ namespace Umbraco.Tests.PublishedContent
[PublishedContentModel("Home")]
internal class Home : PublishedContentModel
{
- public Home(IPublishedContent content)
- : base(content)
+ public Home(IPublishedContent content)
+ : base(content)
{}
}
@@ -659,6 +659,28 @@ namespace Umbraco.Tests.PublishedContent
Assert.AreEqual((int)1178, (int)result.Id);
}
+ [Test]
+ public void GetKey()
+ {
+ var key = Guid.Parse("CDB83BBC-A83B-4BA6-93B8-AADEF67D3C09");
+
+ // doc is Home (a model) and GetKey unwraps and works
+ var doc = GetNode(1176);
+ Assert.IsInstanceOf(doc);
+ Assert.AreEqual(key, doc.GetKey());
+
+ // wrapped is PublishedContentWrapped and WithKey unwraps
+ var wrapped = new TestWrapped(doc);
+ Assert.AreEqual(key, wrapped.GetKey());
+ }
+
+ class TestWrapped : PublishedContentWrapped
+ {
+ public TestWrapped(IPublishedContent content)
+ : base(content)
+ { }
+ }
+
[Test]
public void DetachedProperty1()
{
diff --git a/src/Umbraco.Web/PublishedContentExtensions.cs b/src/Umbraco.Web/PublishedContentExtensions.cs
index 9098cdcb0b..a65c353eff 100644
--- a/src/Umbraco.Web/PublishedContentExtensions.cs
+++ b/src/Umbraco.Web/PublishedContentExtensions.cs
@@ -10,6 +10,7 @@ using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.Services;
using Umbraco.Web.Models;
using Umbraco.Core;
+using Umbraco.Core.Logging;
using Umbraco.Web.Routing;
using ContentType = umbraco.cms.businesslogic.ContentType;
@@ -38,7 +39,10 @@ namespace Umbraco.Web
// again
contentWithKey = content as IPublishedContentWithKey;
- return contentWithKey == null ? Guid.Empty : contentWithKey.Key;
+ if (contentWithKey != null) return contentWithKey.Key;
+
+ LogHelper.Debug(typeof(PublishedContentExtensions), "Could not get key for IPublishedContent of type " + content.GetType().FullName);
+ return Guid.Empty;
}
#endregion