Skip to content
This repository has been archived by the owner on Dec 13, 2021. It is now read-only.

Commit

Permalink
Merge pull request #118 from leekelleher/hotfix-0.8.3
Browse files Browse the repository at this point in the history
Custom PublishedContent property nullifies value
  • Loading branch information
leekelleher committed Sep 25, 2015
2 parents a29a0f8 + 0362db6 commit f7b1005
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,16 @@ public override object ResolveValue()
if (!umbracoPropertyName.IsNullOrWhiteSpace())
{
var contentProperty = contentType.GetProperty(umbracoPropertyName, BindingFlags.Public | BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.Static);
propertyValue = contentProperty != null
? contentProperty.GetValue(content, null)
: content.GetPropertyValue(umbracoPropertyName, recursive);

if (contentProperty != null)
{
propertyValue = contentProperty.GetValue(content, null);
}

if (propertyValue == null)
{
propertyValue = content.GetPropertyValue(umbracoPropertyName, recursive);
}
}

// Try fetching the alt value.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
namespace Our.Umbraco.Ditto.Tests
{
using Mocks;
using NUnit.Framework;

[TestFixture]
public class CustomPublishedContentPropertyTests
{
public class CustomPublishedContentMock : PublishedContentMock
{
public string MyProperty { get; set; }
}

public class MyModel
{
public string MyProperty { get; set; }
}

[Test]
public void CustomPublishedContent_Property_IsMapped()
{
var value = "myValue";

var property = new PublishedContentPropertyMock
{
Alias = "myProperty",
Value = value
};

var content = new CustomPublishedContentMock
{
Properties = new[] { property }
};

var model = content.As<MyModel>();

Assert.That(model.MyProperty, Is.EqualTo(value));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@
<Compile Include="BasicMappingTests.cs" />
<Compile Include="CastableInterfaceTests.cs" />
<Compile Include="ClassLevelTypeConverterTests.cs" />
<Compile Include="CustomPublishedContentPropertyTests.cs" />
<Compile Include="CustomTypeConverterTests.cs" />
<Compile Include="ConversionHandlerTests.cs" />
<Compile Include="CustomValueResolverTests.cs" />
Expand Down

0 comments on commit f7b1005

Please sign in to comment.