Working with unit tests and making a few corrections around ContentTypes.

This commit is contained in:
Morten Christensen
2012-11-30 09:34:09 -01:00
parent 2f83e5ba31
commit 152c8e810d
25 changed files with 362 additions and 157 deletions

View File

@@ -13,112 +13,112 @@ namespace Umbraco.Core.Models
[DataContract(IsReference = true)]
public abstract class ContentTypeCompositionBase : ContentTypeBase, IContentTypeComposition
{
private List<IContentTypeComposition> _contentTypeComposition;
private List<IContentTypeComposition> _contentTypeComposition = new List<IContentTypeComposition>();
protected ContentTypeCompositionBase(int parentId) : base(parentId)
{
_contentTypeComposition = new List<IContentTypeComposition>();
}
private static readonly PropertyInfo ContentTypeCompositionSelector = ExpressionHelper.GetPropertyInfo<ContentTypeCompositionBase, List<IContentTypeComposition>>(x => x.ContentTypeComposition);
private static readonly PropertyInfo ContentTypeCompositionSelector =
ExpressionHelper.GetPropertyInfo<ContentTypeCompositionBase, IEnumerable<IContentTypeComposition>>(
x => x.ContentTypeComposition);
/// <summary>
/// List of ContentTypes that make up a composition of PropertyGroups and PropertyTypes for the current ContentType
/// </summary>
[DataMember]
public List<IContentTypeComposition> ContentTypeComposition
{
get { return _contentTypeComposition; }
set
{
_contentTypeComposition = value;
OnPropertyChanged(ContentTypeCompositionSelector);
}
}
/// <summary>
/// List of ContentTypes that make up a composition of PropertyGroups and PropertyTypes for the current ContentType
/// </summary>
[DataMember]
public IEnumerable<IContentTypeComposition> ContentTypeComposition
{
get { return _contentTypeComposition; }
}
/// <summary>
/// Returns a list of <see cref="PropertyGroup"/> objects from the composition
/// </summary>
[IgnoreDataMember]
public IEnumerable<PropertyGroup> CompositionPropertyGroups
{
get
{
var groups = PropertyGroups.Union(ContentTypeComposition.SelectMany(x => x.CompositionPropertyGroups));
return groups;
}
}
/// <summary>
/// Returns a list of <see cref="PropertyGroup"/> objects from the composition
/// </summary>
[IgnoreDataMember]
public IEnumerable<PropertyGroup> CompositionPropertyGroups
{
get
{
var groups = PropertyGroups.Union(ContentTypeComposition.SelectMany(x => x.CompositionPropertyGroups));
return groups;
}
}
/// <summary>
/// Returns a list of <see cref="PropertyType"/> objects from the composition
/// </summary>
[IgnoreDataMember]
public IEnumerable<PropertyType> CompositionPropertyTypes
{
get
{
var propertyTypes = PropertyTypes.Union(ContentTypeComposition.SelectMany(x => x.CompositionPropertyTypes));
return propertyTypes;
}
}
/// <summary>
/// Returns a list of <see cref="PropertyType"/> objects from the composition
/// </summary>
[IgnoreDataMember]
public IEnumerable<PropertyType> CompositionPropertyTypes
{
get
{
var propertyTypes =
PropertyTypes.Union(ContentTypeComposition.SelectMany(x => x.CompositionPropertyTypes));
return propertyTypes;
}
}
/// <summary>
/// Adds a new ContentType to the list of composite ContentTypes
/// </summary>
/// <param name="contentType"><see cref="ContentType"/> to add</param>
/// <returns>True if ContentType was added, otherwise returns False</returns>
public bool AddContentType(IContentTypeComposition contentType)
{
if (contentType.ContentTypeComposition.Any(x => x.CompositionAliases().Any(ContentTypeCompositionExists)))
return false;
/// <summary>
/// Adds a new ContentType to the list of composite ContentTypes
/// </summary>
/// <param name="contentType"><see cref="ContentType"/> to add</param>
/// <returns>True if ContentType was added, otherwise returns False</returns>
public bool AddContentType(IContentTypeComposition contentType)
{
if (contentType.ContentTypeComposition.Any(x => x.CompositionAliases().Any(ContentTypeCompositionExists)))
return false;
if (!ContentTypeCompositionExists(contentType.Alias))
{
ContentTypeComposition.Add(contentType);
return true;
}
return false;
}
if (!ContentTypeCompositionExists(contentType.Alias))
{
_contentTypeComposition.Add(contentType);
OnPropertyChanged(ContentTypeCompositionSelector);
return true;
}
return false;
}
/// <summary>
/// Removes a ContentType with the supplied alias from the the list of composite ContentTypes
/// </summary>
/// <param name="alias">Alias of a <see cref="ContentType"/></param>
/// <returns>True if ContentType was removed, otherwise returns False</returns>
public bool RemoveContentType(string alias)
{
if (!ContentTypeCompositionExists(alias))
{
var contentTypeComposition = ContentTypeComposition.First(x => x.Alias == alias);
return ContentTypeComposition.Remove(contentTypeComposition);
}
return false;
}
/// <summary>
/// Removes a ContentType with the supplied alias from the the list of composite ContentTypes
/// </summary>
/// <param name="alias">Alias of a <see cref="ContentType"/></param>
/// <returns>True if ContentType was removed, otherwise returns False</returns>
public bool RemoveContentType(string alias)
{
if (!ContentTypeCompositionExists(alias))
{
var contentTypeComposition = ContentTypeComposition.First(x => x.Alias == alias);
return _contentTypeComposition.Remove(contentTypeComposition);
}
return false;
}
/// <summary>
/// Checks if a ContentType with the supplied alias exists in the list of composite ContentTypes
/// </summary>
/// <param name="alias">Alias of a <see cref="ContentType"/></param>
/// <returns>True if ContentType with alias exists, otherwise returns False</returns>
public bool ContentTypeCompositionExists(string alias)
{
if (ContentTypeComposition.Any(x => x.Alias.Equals(alias)))
return true;
/// <summary>
/// Checks if a ContentType with the supplied alias exists in the list of composite ContentTypes
/// </summary>
/// <param name="alias">Alias of a <see cref="ContentType"/></param>
/// <returns>True if ContentType with alias exists, otherwise returns False</returns>
public bool ContentTypeCompositionExists(string alias)
{
if (ContentTypeComposition.Any(x => x.Alias.Equals(alias)))
return true;
if (ContentTypeComposition.Any(x => x.ContentTypeCompositionExists(alias)))
return true;
if (ContentTypeComposition.Any(x => x.ContentTypeCompositionExists(alias)))
return true;
return false;
}
return false;
}
/// <summary>
/// Gets a list of ContentType aliases from the current composition
/// </summary>
/// <returns></returns>
/// <remarks>Does not contain the alias of the Current ContentType</remarks>
public IEnumerable<string> CompositionAliases()
{
return ContentTypeComposition.Select(x => x.Alias).Union(ContentTypeComposition.SelectMany(x => x.CompositionAliases()));
}
/// <summary>
/// Gets a list of ContentType aliases from the current composition
/// </summary>
/// <returns></returns>
/// <remarks>Does not contain the alias of the Current ContentType</remarks>
public IEnumerable<string> CompositionAliases()
{
return ContentTypeComposition
.Select(x => x.Alias)
.Union(ContentTypeComposition.SelectMany(x => x.CompositionAliases()));
}
}
}

View File

@@ -10,7 +10,7 @@ namespace Umbraco.Core.Models
/// <summary>
/// Gets a list of ContentTypes that make up a composition of PropertyGroups and PropertyTypes for the current ContentType
/// </summary>
List<IContentTypeComposition> ContentTypeComposition { get; }
IEnumerable<IContentTypeComposition> ContentTypeComposition { get; }
/// <summary>
/// Gets a list of <see cref="PropertyGroup"/> objects from the composition

View File

@@ -9,9 +9,11 @@ namespace Umbraco.Core.Models.Rdbms
{
[Column("parentContentTypeId")]
[PrimaryKeyColumn(AutoIncrement = false, Clustered = true, Name = "PK_cmsContentType2ContentType", OnColumns = "parentContentTypeId, childContentTypeId")]
[ForeignKey(typeof(NodeDto), Name = "FK_cmsContentType2ContentType_umbracoNode_parent")]
public int ParentId { get; set; }
[Column("childContentTypeId")]
[ForeignKey(typeof(NodeDto), Name = "FK_cmsContentType2ContentType_umbracoNode_child")]
public int ChildId { get; set; }
}
}

View File

@@ -13,7 +13,7 @@ namespace Umbraco.Core.Models.Rdbms
public int Id { get; set; }
[Column("datatypeNodeId")]
[ForeignKey(typeof(DataTypeDto))]
[ForeignKey(typeof(DataTypeDto), Column = "nodeId")]
public int DataTypeNodeId { get; set; }
[Column("value")]