Fixes: #U4-1822, #U4-1797 - Is helpers and indexes on result collections using IPublishedContent or DynamicPublishedContent were incorrect,

added unit tests to support issues and fixes.
This commit is contained in:
Shannon Deminick
2013-03-02 01:02:38 +06:00
parent a17a11d50b
commit 010893a73a
16 changed files with 736 additions and 277 deletions

View File

@@ -20,9 +20,9 @@ namespace Umbraco.Web.Models
/// <summary>
/// The base dynamic model for views
/// </summary>
public class DynamicPublishedContent : DynamicObject, IPublishedContent
public class DynamicPublishedContent : DynamicObject, IPublishedContent, IOwnerCollectionAware<IPublishedContent>
{
protected IPublishedContent PublishedContent { get; private set; }
protected internal IPublishedContent PublishedContent { get; private set; }
private DynamicPublishedContentList _cachedChildren;
private readonly ConcurrentDictionary<string, object> _cachedMemberOutput = new ConcurrentDictionary<string, object>();
@@ -36,6 +36,46 @@ namespace Umbraco.Web.Models
#endregion
private IEnumerable<IPublishedContent> _ownersCollection;
/// <summary>
/// Need to get/set the owner collection when an item is returned from the result set of a query
/// </summary>
/// <remarks>
/// Based on this issue here: http://issues.umbraco.org/issue/U4-1797
/// </remarks>
IEnumerable<IPublishedContent> IOwnerCollectionAware<IPublishedContent>.OwnersCollection
{
get
{
var publishedContentBase = PublishedContent as IOwnerCollectionAware<IPublishedContent>;
if (publishedContentBase != null)
{
return publishedContentBase.OwnersCollection;
}
//if the owners collection is null, we'll default to it's siblings
if (_ownersCollection == null)
{
//get the root docs if parent is null
_ownersCollection = this.Siblings();
}
return _ownersCollection;
}
set
{
var publishedContentBase = PublishedContent as IOwnerCollectionAware<IPublishedContent>;
if (publishedContentBase != null)
{
publishedContentBase.OwnersCollection = value;
}
else
{
_ownersCollection = value;
}
}
}
public dynamic AsDynamic()
{
return this;