Migrated content, media and member type tests into new unit tests project and builder pattern.
This commit is contained in:
@@ -0,0 +1,157 @@
|
||||
using System;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Tests.Common.Builders.Interfaces;
|
||||
|
||||
namespace Umbraco.Tests.Common.Builders
|
||||
{
|
||||
public class ContentBuilder
|
||||
: BuilderBase<Content>,
|
||||
IBuildContentTypes,
|
||||
IWithIdBuilder,
|
||||
IWithKeyBuilder,
|
||||
IWithParentIdBuilder,
|
||||
IWithCreatorIdBuilder,
|
||||
IWithCreateDateBuilder,
|
||||
IWithUpdateDateBuilder,
|
||||
IWithNameBuilder,
|
||||
IWithTrashedBuilder,
|
||||
IWithLevelBuilder,
|
||||
IWithPathBuilder,
|
||||
IWithSortOrderBuilder
|
||||
{
|
||||
private ContentTypeBuilder _contentTypeBuilder;
|
||||
private GenericDictionaryBuilder<ContentBuilder, string, object> _propertyDataBuilder;
|
||||
|
||||
private int? _id;
|
||||
private Guid? _key;
|
||||
private DateTime? _createDate;
|
||||
private DateTime? _updateDate;
|
||||
private int? _parentId;
|
||||
private string _name;
|
||||
private int? _creatorId;
|
||||
private int? _level;
|
||||
private string _path;
|
||||
private int? _sortOrder;
|
||||
private bool? _trashed;
|
||||
|
||||
public ContentTypeBuilder AddContentType()
|
||||
{
|
||||
var builder = new ContentTypeBuilder(this);
|
||||
_contentTypeBuilder = builder;
|
||||
return builder;
|
||||
}
|
||||
|
||||
public override Content Build()
|
||||
{
|
||||
var id = _id ?? 1;
|
||||
var key = _key ?? Guid.NewGuid();
|
||||
var parentId = _parentId ?? -1;
|
||||
var createDate = _createDate ?? DateTime.Now;
|
||||
var updateDate = _updateDate ?? DateTime.Now;
|
||||
var name = _name ?? Guid.NewGuid().ToString();
|
||||
var creatorId = _creatorId ?? 1;
|
||||
var level = _level ?? 1;
|
||||
var path = _path ?? "-1";
|
||||
var sortOrder = _sortOrder ?? 0;
|
||||
var trashed = _trashed ?? false;
|
||||
|
||||
if (_contentTypeBuilder == null)
|
||||
{
|
||||
throw new InvalidOperationException("A member cannot be constructed without providing a member type. Use AddContentType().");
|
||||
}
|
||||
|
||||
var memberType = _contentTypeBuilder.Build();
|
||||
|
||||
var member = new Content(name, parentId, memberType)
|
||||
{
|
||||
Id = id,
|
||||
Key = key,
|
||||
CreateDate = createDate,
|
||||
UpdateDate = updateDate,
|
||||
CreatorId = creatorId,
|
||||
Level = level,
|
||||
Path = path,
|
||||
SortOrder = sortOrder,
|
||||
Trashed = trashed,
|
||||
};
|
||||
|
||||
if (_propertyDataBuilder != null)
|
||||
{
|
||||
var propertyData = _propertyDataBuilder.Build();
|
||||
foreach (var kvp in propertyData)
|
||||
{
|
||||
member.SetValue(kvp.Key, kvp.Value);
|
||||
}
|
||||
|
||||
member.ResetDirtyProperties(false);
|
||||
}
|
||||
|
||||
return member;
|
||||
}
|
||||
|
||||
int? IWithIdBuilder.Id
|
||||
{
|
||||
get => _id;
|
||||
set => _id = value;
|
||||
}
|
||||
|
||||
Guid? IWithKeyBuilder.Key
|
||||
{
|
||||
get => _key;
|
||||
set => _key = value;
|
||||
}
|
||||
|
||||
int? IWithCreatorIdBuilder.CreatorId
|
||||
{
|
||||
get => _creatorId;
|
||||
set => _creatorId = value;
|
||||
}
|
||||
|
||||
DateTime? IWithCreateDateBuilder.CreateDate
|
||||
{
|
||||
get => _createDate;
|
||||
set => _createDate = value;
|
||||
}
|
||||
|
||||
DateTime? IWithUpdateDateBuilder.UpdateDate
|
||||
{
|
||||
get => _updateDate;
|
||||
set => _updateDate = value;
|
||||
}
|
||||
|
||||
string IWithNameBuilder.Name
|
||||
{
|
||||
get => _name;
|
||||
set => _name = value;
|
||||
}
|
||||
|
||||
bool? IWithTrashedBuilder.Trashed
|
||||
{
|
||||
get => _trashed;
|
||||
set => _trashed = value;
|
||||
}
|
||||
|
||||
int? IWithLevelBuilder.Level
|
||||
{
|
||||
get => _level;
|
||||
set => _level = value;
|
||||
}
|
||||
|
||||
string IWithPathBuilder.Path
|
||||
{
|
||||
get => _path;
|
||||
set => _path = value;
|
||||
}
|
||||
|
||||
int? IWithSortOrderBuilder.SortOrder
|
||||
{
|
||||
get => _sortOrder;
|
||||
set => _sortOrder = value;
|
||||
}
|
||||
int? IWithParentIdBuilder.ParentId
|
||||
{
|
||||
get => _parentId;
|
||||
set => _parentId = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,201 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Strings;
|
||||
using Umbraco.Tests.Common.Builders.Extensions;
|
||||
using Umbraco.Tests.Common.Builders.Interfaces;
|
||||
|
||||
namespace Umbraco.Tests.Common.Builders
|
||||
{
|
||||
public abstract class ContentTypeBaseBuilder<TParent, TType>
|
||||
: ChildBuilderBase<TParent, TType>,
|
||||
IBuildPropertyGroups,
|
||||
IWithIdBuilder,
|
||||
IWithKeyBuilder,
|
||||
IWithAliasBuilder,
|
||||
IWithNameBuilder,
|
||||
IWithParentIdBuilder,
|
||||
IWithPathBuilder,
|
||||
IWithLevelBuilder,
|
||||
IWithSortOrderBuilder,
|
||||
IWithCreatorIdBuilder,
|
||||
IWithCreateDateBuilder,
|
||||
IWithUpdateDateBuilder,
|
||||
IWithDescriptionBuilder,
|
||||
IWithIconBuilder,
|
||||
IWithThumbnailBuilder,
|
||||
IWithTrashedBuilder,
|
||||
IWithIsContainerBuilder where TParent : IBuildContentTypes
|
||||
{
|
||||
private int? _id;
|
||||
private Guid? _key;
|
||||
private string _alias;
|
||||
private string _name;
|
||||
private int? _parentId;
|
||||
private int? _level;
|
||||
private string _path;
|
||||
private int? _sortOrder;
|
||||
private int? _creatorId;
|
||||
private DateTime? _createDate;
|
||||
private DateTime? _updateDate;
|
||||
private string _description;
|
||||
private string _icon;
|
||||
private string _thumbnail;
|
||||
private bool? _trashed;
|
||||
private bool? _isContainer;
|
||||
|
||||
protected IShortStringHelper ShortStringHelper => new DefaultShortStringHelper(new DefaultShortStringHelperConfig());
|
||||
|
||||
public ContentTypeBaseBuilder(TParent parentBuilder) : base(parentBuilder)
|
||||
{
|
||||
}
|
||||
|
||||
protected int GetId() => _id ?? 1;
|
||||
|
||||
protected Guid GetKey() => _key ?? Guid.NewGuid();
|
||||
|
||||
protected DateTime GetCreateDate() => _createDate ?? DateTime.Now;
|
||||
|
||||
protected DateTime GetUpdateDate() => _updateDate ?? DateTime.Now;
|
||||
|
||||
protected string GetName() => _name ?? Guid.NewGuid().ToString();
|
||||
|
||||
protected string GetAlias() => _alias ?? GetName().ToCamelCase();
|
||||
|
||||
protected int GetParentId() => _parentId ?? -1;
|
||||
|
||||
protected int GetLevel() => _level ?? 0;
|
||||
|
||||
protected string GetPath() => _path ?? string.Empty;
|
||||
|
||||
protected int GetSortOrder() => _sortOrder ?? 0;
|
||||
|
||||
protected string GetDescription() => _description ?? string.Empty;
|
||||
|
||||
protected string GetIcon() => _icon ?? string.Empty;
|
||||
|
||||
protected string GetThumbnail() => _thumbnail ?? string.Empty;
|
||||
|
||||
protected int GetCreatorId() => _creatorId ?? 0;
|
||||
|
||||
protected bool GetTrashed() => _trashed ?? false;
|
||||
|
||||
protected bool GetIsContainer() => _isContainer ?? false;
|
||||
|
||||
protected void BuildPropertyGroups(ContentTypeCompositionBase contentType, IEnumerable<PropertyGroup> propertyGroups)
|
||||
{
|
||||
foreach (var propertyGroup in propertyGroups)
|
||||
{
|
||||
contentType.PropertyGroups.Add(propertyGroup);
|
||||
}
|
||||
}
|
||||
|
||||
protected void BuildPropertyTypeIds(ContentTypeCompositionBase contentType, int? propertyTypeIdsIncrementingFrom)
|
||||
{
|
||||
if (propertyTypeIdsIncrementingFrom.HasValue)
|
||||
{
|
||||
var i = propertyTypeIdsIncrementingFrom.Value;
|
||||
foreach (var propertyType in contentType.PropertyTypes)
|
||||
{
|
||||
propertyType.Id = ++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int? IWithIdBuilder.Id
|
||||
{
|
||||
get => _id;
|
||||
set => _id = value;
|
||||
}
|
||||
|
||||
Guid? IWithKeyBuilder.Key
|
||||
{
|
||||
get => _key;
|
||||
set => _key = value;
|
||||
}
|
||||
|
||||
string IWithAliasBuilder.Alias
|
||||
{
|
||||
get => _alias;
|
||||
set => _alias = value;
|
||||
}
|
||||
|
||||
string IWithNameBuilder.Name
|
||||
{
|
||||
get => _name;
|
||||
set => _name = value;
|
||||
}
|
||||
|
||||
int? IWithParentIdBuilder.ParentId
|
||||
{
|
||||
get => _parentId;
|
||||
set => _parentId = value;
|
||||
}
|
||||
|
||||
int? IWithLevelBuilder.Level
|
||||
{
|
||||
get => _level;
|
||||
set => _level = value;
|
||||
}
|
||||
|
||||
string IWithPathBuilder.Path
|
||||
{
|
||||
get => _path;
|
||||
set => _path = value;
|
||||
}
|
||||
|
||||
int? IWithSortOrderBuilder.SortOrder
|
||||
{
|
||||
get => _sortOrder;
|
||||
set => _sortOrder = value;
|
||||
}
|
||||
|
||||
int? IWithCreatorIdBuilder.CreatorId
|
||||
{
|
||||
get => _creatorId;
|
||||
set => _creatorId = value;
|
||||
}
|
||||
|
||||
DateTime? IWithCreateDateBuilder.CreateDate
|
||||
{
|
||||
get => _createDate;
|
||||
set => _createDate = value;
|
||||
}
|
||||
|
||||
DateTime? IWithUpdateDateBuilder.UpdateDate
|
||||
{
|
||||
get => _updateDate;
|
||||
set => _updateDate = value;
|
||||
}
|
||||
|
||||
string IWithDescriptionBuilder.Description
|
||||
{
|
||||
get => _description;
|
||||
set => _description = value;
|
||||
}
|
||||
|
||||
string IWithIconBuilder.Icon
|
||||
{
|
||||
get => _icon;
|
||||
set => _icon = value;
|
||||
}
|
||||
|
||||
string IWithThumbnailBuilder.Thumbnail
|
||||
{
|
||||
get => _thumbnail;
|
||||
set => _thumbnail = value;
|
||||
}
|
||||
|
||||
bool? IWithTrashedBuilder.Trashed
|
||||
{
|
||||
get => _trashed;
|
||||
set => _trashed = value;
|
||||
}
|
||||
|
||||
bool? IWithIsContainerBuilder.IsContainer
|
||||
{
|
||||
get => _isContainer;
|
||||
set => _isContainer = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Tests.Common.Builders.Interfaces;
|
||||
|
||||
namespace Umbraco.Tests.Common.Builders
|
||||
{
|
||||
public class ContentTypeBuilder
|
||||
: ContentTypeBaseBuilder<ContentBuilder, IContentType>,
|
||||
IWithPropertyTypeIdsIncrementingFrom
|
||||
{
|
||||
private List<PropertyGroupBuilder<ContentTypeBuilder>> _propertyGroupBuilders = new List<PropertyGroupBuilder<ContentTypeBuilder>>();
|
||||
private List<TemplateBuilder> _templateBuilders = new List<TemplateBuilder>();
|
||||
private List<ContentTypeSortBuilder> _allowedContentTypeBuilders = new List<ContentTypeSortBuilder>();
|
||||
|
||||
private int? _propertyTypeIdsIncrementingFrom;
|
||||
private int? _defaultTemplateId;
|
||||
|
||||
public ContentTypeBuilder() : base(null)
|
||||
{
|
||||
}
|
||||
|
||||
public ContentTypeBuilder(ContentBuilder parentBuilder) : base(parentBuilder)
|
||||
{
|
||||
}
|
||||
|
||||
public ContentTypeBuilder WithDefaultTemplateId(int templateId)
|
||||
{
|
||||
_defaultTemplateId = templateId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PropertyGroupBuilder<ContentTypeBuilder> AddPropertyGroup()
|
||||
{
|
||||
var builder = new PropertyGroupBuilder<ContentTypeBuilder>(this);
|
||||
_propertyGroupBuilders.Add(builder);
|
||||
return builder;
|
||||
}
|
||||
|
||||
public TemplateBuilder AddAllowedTemplate()
|
||||
{
|
||||
var builder = new TemplateBuilder(this);
|
||||
_templateBuilders.Add(builder);
|
||||
return builder;
|
||||
}
|
||||
|
||||
public ContentTypeSortBuilder AddAllowedContentType()
|
||||
{
|
||||
var builder = new ContentTypeSortBuilder(this);
|
||||
_allowedContentTypeBuilders.Add(builder);
|
||||
return builder;
|
||||
}
|
||||
|
||||
public override IContentType Build()
|
||||
{
|
||||
var contentType = new ContentType(ShortStringHelper, GetParentId())
|
||||
{
|
||||
Id = GetId(),
|
||||
Key = GetKey(),
|
||||
CreateDate = GetCreateDate(),
|
||||
UpdateDate = GetUpdateDate(),
|
||||
Alias = GetAlias(),
|
||||
Name = GetName(),
|
||||
Level = GetLevel(),
|
||||
Path = GetPath(),
|
||||
SortOrder = GetSortOrder(),
|
||||
Description = GetDescription(),
|
||||
Icon = GetIcon(),
|
||||
Thumbnail = GetThumbnail(),
|
||||
CreatorId = GetCreatorId(),
|
||||
Trashed = GetTrashed(),
|
||||
IsContainer = GetIsContainer(),
|
||||
};
|
||||
|
||||
BuildPropertyGroups(contentType, _propertyGroupBuilders.Select(x => x.Build()));
|
||||
BuildPropertyTypeIds(contentType, _propertyTypeIdsIncrementingFrom);
|
||||
|
||||
contentType.AllowedTemplates = _templateBuilders.Select(x => x.Build());
|
||||
contentType.AllowedContentTypes = _allowedContentTypeBuilders.Select(x => x.Build());
|
||||
|
||||
if (_defaultTemplateId.HasValue)
|
||||
{
|
||||
contentType.SetDefaultTemplate(contentType.AllowedTemplates
|
||||
.SingleOrDefault(x => x.Id == _defaultTemplateId.Value));
|
||||
}
|
||||
|
||||
contentType.ResetDirtyProperties(false);
|
||||
|
||||
return contentType;
|
||||
}
|
||||
|
||||
int? IWithPropertyTypeIdsIncrementingFrom.PropertyTypeIdsIncrementingFrom
|
||||
{
|
||||
get => _propertyTypeIdsIncrementingFrom;
|
||||
set => _propertyTypeIdsIncrementingFrom = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Tests.Common.Builders.Extensions;
|
||||
using Umbraco.Tests.Common.Builders.Interfaces;
|
||||
|
||||
namespace Umbraco.Tests.Common.Builders
|
||||
{
|
||||
public class ContentTypeSortBuilder
|
||||
: ChildBuilderBase<ContentTypeBuilder, ContentTypeSort>,
|
||||
IWithIdBuilder,
|
||||
IWithAliasBuilder,
|
||||
IWithSortOrderBuilder
|
||||
{
|
||||
private int? _id;
|
||||
private string _alias;
|
||||
private int? _sortOrder;
|
||||
|
||||
public ContentTypeSortBuilder() : base(null)
|
||||
{
|
||||
}
|
||||
|
||||
public ContentTypeSortBuilder(ContentTypeBuilder parentBuilder) : base(parentBuilder)
|
||||
{
|
||||
}
|
||||
|
||||
public override ContentTypeSort Build()
|
||||
{
|
||||
var id = _id ?? 1;
|
||||
var alias = _alias ?? Guid.NewGuid().ToString().ToCamelCase();
|
||||
var sortOrder = _sortOrder ?? 0;
|
||||
|
||||
return new ContentTypeSort(new Lazy<int>(() => id), sortOrder, alias);
|
||||
}
|
||||
|
||||
int? IWithIdBuilder.Id
|
||||
{
|
||||
get => _id;
|
||||
set => _id = value;
|
||||
}
|
||||
|
||||
string IWithAliasBuilder.Alias
|
||||
{
|
||||
get => _alias;
|
||||
set => _alias = value;
|
||||
}
|
||||
|
||||
int? IWithSortOrderBuilder.SortOrder
|
||||
{
|
||||
get => _sortOrder;
|
||||
set => _sortOrder = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -178,5 +178,19 @@ namespace Umbraco.Tests.Common.Builders.Extensions
|
||||
builder.LastPasswordChangeDate = lastPasswordChangeDate;
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static T WithPropertyTypeIdsIncrementingFrom<T>(this T builder, int propertyTypeIdsIncrementingFrom)
|
||||
where T : IWithPropertyTypeIdsIncrementingFrom
|
||||
{
|
||||
builder.PropertyTypeIdsIncrementingFrom = propertyTypeIdsIncrementingFrom;
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static T WithIsContainer<T>(this T builder, bool isContainer)
|
||||
where T : IWithIsContainerBuilder
|
||||
{
|
||||
builder.IsContainer = isContainer;
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Umbraco.Tests.Common.Builders.Interfaces
|
||||
{
|
||||
public interface IBuildContentTypes
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Umbraco.Tests.Common.Builders.Interfaces
|
||||
{
|
||||
public interface IWithIsContainerBuilder
|
||||
{
|
||||
bool? IsContainer { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Umbraco.Tests.Common.Builders.Interfaces
|
||||
{
|
||||
public interface IWithPropertyTypeIdsIncrementingFrom
|
||||
{
|
||||
int? PropertyTypeIdsIncrementingFrom { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
using System;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Tests.Common.Builders.Interfaces;
|
||||
|
||||
namespace Umbraco.Tests.Common.Builders
|
||||
{
|
||||
public class MediaBuilder
|
||||
: BuilderBase<Media>,
|
||||
IBuildContentTypes,
|
||||
IWithIdBuilder,
|
||||
IWithKeyBuilder,
|
||||
IWithParentIdBuilder,
|
||||
IWithCreatorIdBuilder,
|
||||
IWithCreateDateBuilder,
|
||||
IWithUpdateDateBuilder,
|
||||
IWithNameBuilder,
|
||||
IWithTrashedBuilder,
|
||||
IWithLevelBuilder,
|
||||
IWithPathBuilder,
|
||||
IWithSortOrderBuilder
|
||||
{
|
||||
private MediaTypeBuilder _mediaTypeBuilder;
|
||||
private GenericDictionaryBuilder<MediaBuilder, string, object> _propertyDataBuilder;
|
||||
|
||||
private int? _id;
|
||||
private Guid? _key;
|
||||
private DateTime? _createDate;
|
||||
private DateTime? _updateDate;
|
||||
private int? _parentId;
|
||||
private string _name;
|
||||
private int? _creatorId;
|
||||
private int? _level;
|
||||
private string _path;
|
||||
private int? _sortOrder;
|
||||
private bool? _trashed;
|
||||
|
||||
public MediaTypeBuilder AddMediaType()
|
||||
{
|
||||
var builder = new MediaTypeBuilder(this);
|
||||
_mediaTypeBuilder = builder;
|
||||
return builder;
|
||||
}
|
||||
|
||||
public override Media Build()
|
||||
{
|
||||
var id = _id ?? 1;
|
||||
var key = _key ?? Guid.NewGuid();
|
||||
var parentId = _parentId ?? -1;
|
||||
var createDate = _createDate ?? DateTime.Now;
|
||||
var updateDate = _updateDate ?? DateTime.Now;
|
||||
var name = _name ?? Guid.NewGuid().ToString();
|
||||
var creatorId = _creatorId ?? 1;
|
||||
var level = _level ?? 1;
|
||||
var path = _path ?? "-1";
|
||||
var sortOrder = _sortOrder ?? 0;
|
||||
var trashed = _trashed ?? false;
|
||||
|
||||
if (_mediaTypeBuilder == null)
|
||||
{
|
||||
throw new InvalidOperationException("A member cannot be constructed without providing a member type. Use AddMediaType().");
|
||||
}
|
||||
|
||||
var memberType = _mediaTypeBuilder.Build();
|
||||
|
||||
var member = new Media(name, parentId, memberType)
|
||||
{
|
||||
Id = id,
|
||||
Key = key,
|
||||
CreateDate = createDate,
|
||||
UpdateDate = updateDate,
|
||||
CreatorId = creatorId,
|
||||
Level = level,
|
||||
Path = path,
|
||||
SortOrder = sortOrder,
|
||||
Trashed = trashed,
|
||||
};
|
||||
|
||||
if (_propertyDataBuilder != null)
|
||||
{
|
||||
var propertyData = _propertyDataBuilder.Build();
|
||||
foreach (var kvp in propertyData)
|
||||
{
|
||||
member.SetValue(kvp.Key, kvp.Value);
|
||||
}
|
||||
|
||||
member.ResetDirtyProperties(false);
|
||||
}
|
||||
|
||||
return member;
|
||||
}
|
||||
|
||||
int? IWithIdBuilder.Id
|
||||
{
|
||||
get => _id;
|
||||
set => _id = value;
|
||||
}
|
||||
|
||||
Guid? IWithKeyBuilder.Key
|
||||
{
|
||||
get => _key;
|
||||
set => _key = value;
|
||||
}
|
||||
|
||||
int? IWithCreatorIdBuilder.CreatorId
|
||||
{
|
||||
get => _creatorId;
|
||||
set => _creatorId = value;
|
||||
}
|
||||
|
||||
DateTime? IWithCreateDateBuilder.CreateDate
|
||||
{
|
||||
get => _createDate;
|
||||
set => _createDate = value;
|
||||
}
|
||||
|
||||
DateTime? IWithUpdateDateBuilder.UpdateDate
|
||||
{
|
||||
get => _updateDate;
|
||||
set => _updateDate = value;
|
||||
}
|
||||
|
||||
string IWithNameBuilder.Name
|
||||
{
|
||||
get => _name;
|
||||
set => _name = value;
|
||||
}
|
||||
|
||||
bool? IWithTrashedBuilder.Trashed
|
||||
{
|
||||
get => _trashed;
|
||||
set => _trashed = value;
|
||||
}
|
||||
|
||||
int? IWithLevelBuilder.Level
|
||||
{
|
||||
get => _level;
|
||||
set => _level = value;
|
||||
}
|
||||
|
||||
string IWithPathBuilder.Path
|
||||
{
|
||||
get => _path;
|
||||
set => _path = value;
|
||||
}
|
||||
|
||||
int? IWithSortOrderBuilder.SortOrder
|
||||
{
|
||||
get => _sortOrder;
|
||||
set => _sortOrder = value;
|
||||
}
|
||||
int? IWithParentIdBuilder.ParentId
|
||||
{
|
||||
get => _parentId;
|
||||
set => _parentId = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Tests.Common.Builders.Extensions;
|
||||
using Umbraco.Tests.Common.Builders.Interfaces;
|
||||
|
||||
namespace Umbraco.Tests.Common.Builders
|
||||
{
|
||||
public class MediaTypeBuilder
|
||||
: ContentTypeBaseBuilder<MediaBuilder, IMediaType>,
|
||||
IWithPropertyTypeIdsIncrementingFrom
|
||||
{
|
||||
private List<PropertyGroupBuilder<MediaTypeBuilder>> _propertyGroupBuilders = new List<PropertyGroupBuilder<MediaTypeBuilder>>();
|
||||
private int? _propertyTypeIdsIncrementingFrom;
|
||||
|
||||
public MediaTypeBuilder() : base(null)
|
||||
{
|
||||
}
|
||||
|
||||
public MediaTypeBuilder(MediaBuilder parentBuilder) : base(parentBuilder)
|
||||
{
|
||||
}
|
||||
|
||||
public MediaTypeBuilder WithMediaPropertyGroup()
|
||||
{
|
||||
var builder = new PropertyGroupBuilder<MediaTypeBuilder>(this)
|
||||
.WithId(99)
|
||||
.WithName("Media")
|
||||
.WithSortOrder(1)
|
||||
.AddPropertyType()
|
||||
.WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.UploadField)
|
||||
.WithValueStorageType(ValueStorageType.Nvarchar)
|
||||
.WithAlias(Constants.Conventions.Media.File)
|
||||
.WithName("File")
|
||||
.WithSortOrder(1)
|
||||
.WithDataTypeId(-90)
|
||||
.Done()
|
||||
.AddPropertyType()
|
||||
.WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.Label)
|
||||
.WithValueStorageType(ValueStorageType.Integer)
|
||||
.WithAlias(Constants.Conventions.Media.Width)
|
||||
.WithName("Width")
|
||||
.WithSortOrder(2)
|
||||
.WithDataTypeId(Constants.System.DefaultLabelDataTypeId)
|
||||
.Done()
|
||||
.AddPropertyType()
|
||||
.WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.Label)
|
||||
.WithValueStorageType(ValueStorageType.Integer)
|
||||
.WithAlias(Constants.Conventions.Media.Height)
|
||||
.WithName("Height")
|
||||
.WithSortOrder(3)
|
||||
.WithDataTypeId(Constants.System.DefaultLabelDataTypeId)
|
||||
.Done()
|
||||
.AddPropertyType()
|
||||
.WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.Label)
|
||||
.WithValueStorageType(ValueStorageType.Integer)
|
||||
.WithAlias(Constants.Conventions.Media.Bytes)
|
||||
.WithName("Bytes")
|
||||
.WithSortOrder(4)
|
||||
.WithDataTypeId(Constants.System.DefaultLabelDataTypeId)
|
||||
.Done()
|
||||
.AddPropertyType()
|
||||
.WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.Label)
|
||||
.WithValueStorageType(ValueStorageType.Nvarchar)
|
||||
.WithAlias(Constants.Conventions.Media.Extension)
|
||||
.WithName("File Extension")
|
||||
.WithSortOrder(4)
|
||||
.WithDataTypeId(Constants.System.DefaultLabelDataTypeId)
|
||||
.Done();
|
||||
_propertyGroupBuilders.Add(builder);
|
||||
return this;
|
||||
}
|
||||
|
||||
public PropertyGroupBuilder<MediaTypeBuilder> AddPropertyGroup()
|
||||
{
|
||||
var builder = new PropertyGroupBuilder<MediaTypeBuilder>(this);
|
||||
_propertyGroupBuilders.Add(builder);
|
||||
return builder;
|
||||
}
|
||||
|
||||
public override IMediaType Build()
|
||||
{
|
||||
var mediaType = new MediaType(ShortStringHelper, GetParentId())
|
||||
{
|
||||
Id = GetId(),
|
||||
Key = GetKey(),
|
||||
CreateDate = GetCreateDate(),
|
||||
UpdateDate = GetUpdateDate(),
|
||||
Alias = GetAlias(),
|
||||
Name = GetName(),
|
||||
Level = GetLevel(),
|
||||
Path = GetPath(),
|
||||
SortOrder = GetSortOrder(),
|
||||
Description = GetDescription(),
|
||||
Icon = GetIcon(),
|
||||
Thumbnail = GetThumbnail(),
|
||||
CreatorId = GetCreatorId(),
|
||||
Trashed = GetTrashed(),
|
||||
IsContainer = GetIsContainer(),
|
||||
};
|
||||
|
||||
BuildPropertyGroups(mediaType, _propertyGroupBuilders.Select(x => x.Build()));
|
||||
BuildPropertyTypeIds(mediaType, _propertyTypeIdsIncrementingFrom);
|
||||
|
||||
mediaType.ResetDirtyProperties(false);
|
||||
|
||||
return mediaType;
|
||||
}
|
||||
|
||||
int? IWithPropertyTypeIdsIncrementingFrom.PropertyTypeIdsIncrementingFrom
|
||||
{
|
||||
get => _propertyTypeIdsIncrementingFrom;
|
||||
set => _propertyTypeIdsIncrementingFrom = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ namespace Umbraco.Tests.Common.Builders
|
||||
{
|
||||
public class MemberBuilder
|
||||
: BuilderBase<Member>,
|
||||
IBuildContentTypes,
|
||||
IWithIdBuilder,
|
||||
IWithKeyBuilder,
|
||||
IWithCreatorIdBuilder,
|
||||
|
||||
@@ -3,38 +3,23 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Strings;
|
||||
using Umbraco.Tests.Common.Builders.Extensions;
|
||||
using Umbraco.Tests.Common.Builders.Interfaces;
|
||||
|
||||
namespace Umbraco.Tests.Common.Builders
|
||||
{
|
||||
public class MemberTypeBuilder
|
||||
: ChildBuilderBase<MemberBuilder, IMemberType>,
|
||||
IBuildPropertyGroups,
|
||||
IWithIdBuilder,
|
||||
IWithAliasBuilder,
|
||||
IWithNameBuilder,
|
||||
IWithParentIdBuilder,
|
||||
IWithSortOrderBuilder,
|
||||
IWithCreatorIdBuilder,
|
||||
IWithDescriptionBuilder,
|
||||
IWithIconBuilder,
|
||||
IWithThumbnailBuilder,
|
||||
IWithTrashedBuilder
|
||||
: ContentTypeBaseBuilder<MemberBuilder, IMemberType>,
|
||||
IWithPropertyTypeIdsIncrementingFrom
|
||||
{
|
||||
private readonly List<PropertyGroupBuilder<MemberTypeBuilder>> _propertyGroupBuilders = new List<PropertyGroupBuilder<MemberTypeBuilder>>();
|
||||
private List<PropertyGroupBuilder<MemberTypeBuilder>> _propertyGroupBuilders = new List<PropertyGroupBuilder<MemberTypeBuilder>>();
|
||||
private Dictionary<string, bool> _memberCanEditProperties = new Dictionary<string, bool>();
|
||||
private Dictionary<string, bool> _memberCanViewProperties = new Dictionary<string, bool>();
|
||||
private int? _propertyTypeIdsIncrementingFrom;
|
||||
|
||||
private int? _id;
|
||||
private string _alias;
|
||||
private string _name;
|
||||
private int? _parentId;
|
||||
private int? _sortOrder;
|
||||
private int? _creatorId;
|
||||
private string _description;
|
||||
private string _icon;
|
||||
private string _thumbnail;
|
||||
private bool? _trashed;
|
||||
public MemberTypeBuilder() : base(null)
|
||||
{
|
||||
}
|
||||
|
||||
public MemberTypeBuilder(MemberBuilder parentBuilder) : base(parentBuilder)
|
||||
{
|
||||
@@ -92,6 +77,18 @@ namespace Umbraco.Tests.Common.Builders
|
||||
return this;
|
||||
}
|
||||
|
||||
public MemberTypeBuilder WithMemberCanEditProperty(string alias, bool canEdit)
|
||||
{
|
||||
_memberCanEditProperties.Add(alias, canEdit);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MemberTypeBuilder WithMemberCanViewProperty(string alias, bool canView)
|
||||
{
|
||||
_memberCanViewProperties.Add(alias, canView);
|
||||
return this;
|
||||
}
|
||||
|
||||
public PropertyGroupBuilder<MemberTypeBuilder> AddPropertyGroup()
|
||||
{
|
||||
var builder = new PropertyGroupBuilder<MemberTypeBuilder>(this);
|
||||
@@ -101,35 +98,36 @@ namespace Umbraco.Tests.Common.Builders
|
||||
|
||||
public override IMemberType Build()
|
||||
{
|
||||
var id = _id ?? 1;
|
||||
var name = _name ?? Guid.NewGuid().ToString();
|
||||
var alias = _alias ?? name.ToCamelCase();
|
||||
var parentId = _parentId ?? -1;
|
||||
var sortOrder = _sortOrder ?? 0;
|
||||
var description = _description ?? string.Empty;
|
||||
var icon = _icon ?? string.Empty;
|
||||
var thumbnail = _thumbnail ?? string.Empty;
|
||||
var creatorId = _creatorId ?? 0;
|
||||
var trashed = _trashed ?? false;
|
||||
|
||||
var shortStringHelper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig());
|
||||
|
||||
var memberType = new MemberType(shortStringHelper, parentId)
|
||||
var memberType = new MemberType(ShortStringHelper, GetParentId())
|
||||
{
|
||||
Id = id,
|
||||
Alias = alias,
|
||||
Name = name,
|
||||
SortOrder = sortOrder,
|
||||
Description = description,
|
||||
Icon = icon,
|
||||
Thumbnail = thumbnail,
|
||||
CreatorId = creatorId,
|
||||
Trashed = trashed,
|
||||
Id = GetId(),
|
||||
Key = GetKey(),
|
||||
CreateDate = GetCreateDate(),
|
||||
UpdateDate = GetUpdateDate(),
|
||||
Alias = GetAlias(),
|
||||
Name = GetName(),
|
||||
Level = GetLevel(),
|
||||
Path = GetPath(),
|
||||
SortOrder = GetSortOrder(),
|
||||
Description = GetDescription(),
|
||||
Icon = GetIcon(),
|
||||
Thumbnail = GetThumbnail(),
|
||||
CreatorId = GetCreatorId(),
|
||||
Trashed = GetTrashed(),
|
||||
IsContainer = GetIsContainer(),
|
||||
};
|
||||
|
||||
foreach (var propertyGroup in _propertyGroupBuilders.Select(x => x.Build()))
|
||||
BuildPropertyGroups(memberType, _propertyGroupBuilders.Select(x => x.Build()));
|
||||
BuildPropertyTypeIds(memberType, _propertyTypeIdsIncrementingFrom);
|
||||
|
||||
foreach (var kvp in _memberCanEditProperties)
|
||||
{
|
||||
memberType.PropertyGroups.Add(propertyGroup);
|
||||
memberType.SetMemberCanEditProperty(kvp.Key, kvp.Value);
|
||||
}
|
||||
|
||||
foreach (var kvp in _memberCanViewProperties)
|
||||
{
|
||||
memberType.SetMemberCanViewProperty(kvp.Key, kvp.Value);
|
||||
}
|
||||
|
||||
memberType.ResetDirtyProperties(false);
|
||||
@@ -137,64 +135,10 @@ namespace Umbraco.Tests.Common.Builders
|
||||
return memberType;
|
||||
}
|
||||
|
||||
int? IWithIdBuilder.Id
|
||||
int? IWithPropertyTypeIdsIncrementingFrom.PropertyTypeIdsIncrementingFrom
|
||||
{
|
||||
get => _id;
|
||||
set => _id = value;
|
||||
}
|
||||
|
||||
string IWithAliasBuilder.Alias
|
||||
{
|
||||
get => _alias;
|
||||
set => _alias = value;
|
||||
}
|
||||
|
||||
string IWithNameBuilder.Name
|
||||
{
|
||||
get => _name;
|
||||
set => _name = value;
|
||||
}
|
||||
|
||||
int? IWithParentIdBuilder.ParentId
|
||||
{
|
||||
get => _parentId;
|
||||
set => _parentId = value;
|
||||
}
|
||||
|
||||
int? IWithSortOrderBuilder.SortOrder
|
||||
{
|
||||
get => _sortOrder;
|
||||
set => _sortOrder = value;
|
||||
}
|
||||
|
||||
int? IWithCreatorIdBuilder.CreatorId
|
||||
{
|
||||
get => _creatorId;
|
||||
set => _creatorId = value;
|
||||
}
|
||||
|
||||
string IWithDescriptionBuilder.Description
|
||||
{
|
||||
get => _description;
|
||||
set => _description = value;
|
||||
}
|
||||
|
||||
string IWithIconBuilder.Icon
|
||||
{
|
||||
get => _icon;
|
||||
set => _icon = value;
|
||||
}
|
||||
|
||||
string IWithThumbnailBuilder.Thumbnail
|
||||
{
|
||||
get => _thumbnail;
|
||||
set => _thumbnail = value;
|
||||
}
|
||||
|
||||
bool? IWithTrashedBuilder.Trashed
|
||||
{
|
||||
get => _trashed;
|
||||
set => _trashed = value;
|
||||
get => _propertyTypeIdsIncrementingFrom;
|
||||
set => _propertyTypeIdsIncrementingFrom = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ using Umbraco.Tests.Common.Builders.Interfaces;
|
||||
namespace Umbraco.Tests.Common.Builders
|
||||
{
|
||||
public class TemplateBuilder
|
||||
: BuilderBase<Template>,
|
||||
: ChildBuilderBase<ContentTypeBuilder, ITemplate>,
|
||||
IWithIdBuilder,
|
||||
IWithKeyBuilder,
|
||||
IWithAliasBuilder,
|
||||
@@ -28,6 +28,14 @@ namespace Umbraco.Tests.Common.Builders
|
||||
private string _masterTemplateAlias;
|
||||
private Lazy<int> _masterTemplateId;
|
||||
|
||||
public TemplateBuilder() : base(null)
|
||||
{
|
||||
}
|
||||
|
||||
public TemplateBuilder(ContentTypeBuilder parentBuilder) : base(parentBuilder)
|
||||
{
|
||||
}
|
||||
|
||||
public TemplateBuilder WithContent(string content)
|
||||
{
|
||||
_content = content;
|
||||
@@ -42,7 +50,7 @@ namespace Umbraco.Tests.Common.Builders
|
||||
return this;
|
||||
}
|
||||
|
||||
public override Template Build()
|
||||
public override ITemplate Build()
|
||||
{
|
||||
var id = _id ?? 0;
|
||||
var key = _key ?? Guid.NewGuid();
|
||||
|
||||
@@ -0,0 +1,424 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Entities;
|
||||
using Umbraco.Tests.Common.Builders;
|
||||
using Umbraco.Tests.Common.Builders.Extensions;
|
||||
|
||||
namespace Umbraco.Tests.UnitTests.Umbraco.Infrastructure.Models
|
||||
{
|
||||
[TestFixture]
|
||||
public class ContentTypeTests
|
||||
{
|
||||
[Test]
|
||||
[Ignore("Ignoring this test until we actually enforce this, see comments in ContentTypeBase.PropertyTypesChanged")]
|
||||
public void Cannot_Add_Duplicate_Property_Aliases()
|
||||
{
|
||||
var contentType = (ContentType)BuildContentType();
|
||||
|
||||
var propertyTypeBuilder = new PropertyTypeBuilder();
|
||||
var additionalPropertyType = propertyTypeBuilder
|
||||
.WithAlias("title")
|
||||
.Build();
|
||||
|
||||
Assert.Throws<InvalidOperationException>(() =>
|
||||
contentType.PropertyTypeCollection.Add(additionalPropertyType));
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Ignore("Ignoring this test until we actually enforce this, see comments in ContentTypeBase.PropertyTypesChanged")]
|
||||
public void Cannot_Update_Duplicate_Property_Aliases()
|
||||
{
|
||||
var contentType = (ContentType)BuildContentType();
|
||||
|
||||
var propertyTypeBuilder = new PropertyTypeBuilder();
|
||||
var additionalPropertyType = propertyTypeBuilder
|
||||
.WithAlias("title")
|
||||
.Build();
|
||||
|
||||
contentType.PropertyTypeCollection.Add(additionalPropertyType);
|
||||
|
||||
var toUpdate = contentType.PropertyTypeCollection["myPropertyType2"];
|
||||
|
||||
Assert.Throws<InvalidOperationException>(() => toUpdate.Alias = "myPropertyType");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Deep_Clone_Content_Type_Sort()
|
||||
{
|
||||
var contentType = BuildContentTypeSort();
|
||||
var clone = (ContentTypeSort)contentType.DeepClone();
|
||||
Assert.AreNotSame(clone, contentType);
|
||||
Assert.AreEqual(clone, contentType);
|
||||
Assert.AreEqual(clone.Id.Value, contentType.Id.Value);
|
||||
Assert.AreEqual(clone.SortOrder, contentType.SortOrder);
|
||||
Assert.AreEqual(clone.Alias, contentType.Alias);
|
||||
}
|
||||
|
||||
private ContentTypeSort BuildContentTypeSort()
|
||||
{
|
||||
var builder = new ContentTypeSortBuilder();
|
||||
return builder
|
||||
.WithId(3)
|
||||
.WithSortOrder(4)
|
||||
.WithAlias("test")
|
||||
.Build();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Deep_Clone_Content_Type_With_Reset_Identities()
|
||||
{
|
||||
var contentType = BuildContentType();
|
||||
|
||||
var clone = (ContentType)contentType.DeepCloneWithResetIdentities("newAlias");
|
||||
|
||||
Assert.AreEqual("newAlias", clone.Alias);
|
||||
Assert.AreNotEqual("newAlias", contentType.Alias);
|
||||
Assert.IsFalse(clone.HasIdentity);
|
||||
|
||||
foreach (var propertyGroup in clone.PropertyGroups)
|
||||
{
|
||||
Assert.IsFalse(propertyGroup.HasIdentity);
|
||||
foreach (var propertyType in propertyGroup.PropertyTypes)
|
||||
Assert.IsFalse(propertyType.HasIdentity);
|
||||
}
|
||||
|
||||
foreach (var propertyType in clone.PropertyTypes.Where(x => x.HasIdentity))
|
||||
Assert.IsFalse(propertyType.HasIdentity);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Deep_Clone_Content_Type()
|
||||
{
|
||||
// Arrange
|
||||
var contentType = BuildContentType();
|
||||
|
||||
// Act
|
||||
var clone = (ContentType)contentType.DeepClone();
|
||||
|
||||
// Assert
|
||||
Assert.AreNotSame(clone, contentType);
|
||||
Assert.AreEqual(clone, contentType);
|
||||
Assert.AreEqual(clone.Id, contentType.Id);
|
||||
Assert.AreEqual(clone.AllowedTemplates.Count(), contentType.AllowedTemplates.Count());
|
||||
for (var index = 0; index < contentType.AllowedTemplates.Count(); index++)
|
||||
{
|
||||
Assert.AreNotSame(clone.AllowedTemplates.ElementAt(index), contentType.AllowedTemplates.ElementAt(index));
|
||||
Assert.AreEqual(clone.AllowedTemplates.ElementAt(index), contentType.AllowedTemplates.ElementAt(index));
|
||||
}
|
||||
Assert.AreNotSame(clone.PropertyGroups, contentType.PropertyGroups);
|
||||
Assert.AreEqual(clone.PropertyGroups.Count, contentType.PropertyGroups.Count);
|
||||
for (var index = 0; index < contentType.PropertyGroups.Count; index++)
|
||||
{
|
||||
Assert.AreNotSame(clone.PropertyGroups[index], contentType.PropertyGroups[index]);
|
||||
Assert.AreEqual(clone.PropertyGroups[index], contentType.PropertyGroups[index]);
|
||||
}
|
||||
Assert.AreNotSame(clone.PropertyTypes, contentType.PropertyTypes);
|
||||
Assert.AreEqual(clone.PropertyTypes.Count(), contentType.PropertyTypes.Count());
|
||||
Assert.AreEqual(0, clone.NoGroupPropertyTypes.Count());
|
||||
for (var index = 0; index < contentType.PropertyTypes.Count(); index++)
|
||||
{
|
||||
Assert.AreNotSame(clone.PropertyTypes.ElementAt(index), contentType.PropertyTypes.ElementAt(index));
|
||||
Assert.AreEqual(clone.PropertyTypes.ElementAt(index), contentType.PropertyTypes.ElementAt(index));
|
||||
}
|
||||
|
||||
Assert.AreEqual(clone.CreateDate, contentType.CreateDate);
|
||||
Assert.AreEqual(clone.CreatorId, contentType.CreatorId);
|
||||
Assert.AreEqual(clone.Key, contentType.Key);
|
||||
Assert.AreEqual(clone.Level, contentType.Level);
|
||||
Assert.AreEqual(clone.Path, contentType.Path);
|
||||
Assert.AreEqual(clone.SortOrder, contentType.SortOrder);
|
||||
Assert.AreNotSame(clone.DefaultTemplate, contentType.DefaultTemplate);
|
||||
Assert.AreEqual(clone.DefaultTemplate, contentType.DefaultTemplate);
|
||||
Assert.AreEqual(clone.DefaultTemplateId, ((ContentType)contentType).DefaultTemplateId);
|
||||
Assert.AreEqual(clone.Trashed, contentType.Trashed);
|
||||
Assert.AreEqual(clone.UpdateDate, contentType.UpdateDate);
|
||||
Assert.AreEqual(clone.Thumbnail, contentType.Thumbnail);
|
||||
Assert.AreEqual(clone.Icon, contentType.Icon);
|
||||
Assert.AreEqual(clone.IsContainer, contentType.IsContainer);
|
||||
|
||||
//This double verifies by reflection
|
||||
var allProps = clone.GetType().GetProperties();
|
||||
foreach (var propertyInfo in allProps)
|
||||
Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(contentType, null));
|
||||
|
||||
//need to ensure the event handlers are wired
|
||||
|
||||
var asDirty = (ICanBeDirty)clone;
|
||||
|
||||
Assert.IsFalse(asDirty.IsPropertyDirty("PropertyTypes"));
|
||||
|
||||
var propertyTypeBuilder = new PropertyTypeBuilder();
|
||||
var additionalPropertyType = propertyTypeBuilder
|
||||
.WithPropertyEditorAlias("test")
|
||||
.WithValueStorageType(ValueStorageType.Nvarchar)
|
||||
.WithAlias("blah")
|
||||
.Build();
|
||||
|
||||
clone.AddPropertyType(additionalPropertyType);
|
||||
Assert.IsTrue(asDirty.IsPropertyDirty("PropertyTypes"));
|
||||
Assert.IsFalse(asDirty.IsPropertyDirty("PropertyGroups"));
|
||||
clone.AddPropertyGroup("hello");
|
||||
Assert.IsTrue(asDirty.IsPropertyDirty("PropertyGroups"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Serialize_Content_Type_Without_Error()
|
||||
{
|
||||
// Arrange
|
||||
var contentType = BuildContentType();
|
||||
|
||||
var json = JsonConvert.SerializeObject(contentType);
|
||||
Debug.Print(json);
|
||||
}
|
||||
|
||||
private static IContentType BuildContentType()
|
||||
{
|
||||
var builder = new ContentTypeBuilder();
|
||||
return builder
|
||||
.WithId(10)
|
||||
.WithAlias("textPage")
|
||||
.WithName("Text Page")
|
||||
.WithCreatorId(22)
|
||||
.WithDescription("test")
|
||||
.WithIsContainer(true)
|
||||
.WithIcon("icon")
|
||||
.WithThumbnail("thumb")
|
||||
.WithSortOrder(5)
|
||||
.WithLevel(3)
|
||||
.WithPath("-1,4,10")
|
||||
.WithPropertyTypeIdsIncrementingFrom(200)
|
||||
.AddPropertyGroup()
|
||||
.WithName("Content")
|
||||
.WithSortOrder(1)
|
||||
.AddPropertyType()
|
||||
.WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.TextBox)
|
||||
.WithValueStorageType(ValueStorageType.Nvarchar)
|
||||
.WithAlias("title")
|
||||
.WithName("Title")
|
||||
.WithSortOrder(1)
|
||||
.WithDataTypeId(-88)
|
||||
.Done()
|
||||
.AddPropertyType()
|
||||
.WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.TextBox)
|
||||
.WithValueStorageType(ValueStorageType.Ntext)
|
||||
.WithAlias("bodyText")
|
||||
.WithName("Body text")
|
||||
.WithSortOrder(2)
|
||||
.WithDataTypeId(-87)
|
||||
.Done()
|
||||
.Done()
|
||||
.AddPropertyGroup()
|
||||
.WithName("Meta")
|
||||
.WithSortOrder(2)
|
||||
.AddPropertyType()
|
||||
.WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.TextBox)
|
||||
.WithValueStorageType(ValueStorageType.Nvarchar)
|
||||
.WithAlias("keywords")
|
||||
.WithName("Keywords")
|
||||
.WithSortOrder(1)
|
||||
.WithDataTypeId(-88)
|
||||
.Done()
|
||||
.AddPropertyType()
|
||||
.WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.TextBox)
|
||||
.WithValueStorageType(ValueStorageType.Nvarchar)
|
||||
.WithAlias("description")
|
||||
.WithName("description")
|
||||
.WithSortOrder(1)
|
||||
.WithDataTypeId(-88)
|
||||
.Done()
|
||||
.Done()
|
||||
.AddAllowedTemplate()
|
||||
.WithId(200)
|
||||
.WithAlias("textPage")
|
||||
.WithName("Text Page")
|
||||
.Done()
|
||||
.AddAllowedTemplate()
|
||||
.WithId(201)
|
||||
.WithAlias("textPage2")
|
||||
.WithName("Text Page 2")
|
||||
.Done()
|
||||
.WithDefaultTemplateId(200)
|
||||
.AddAllowedContentType()
|
||||
.WithId(888)
|
||||
.WithAlias("sub")
|
||||
.WithSortOrder(8)
|
||||
.Done()
|
||||
.AddAllowedContentType()
|
||||
.WithId(889)
|
||||
.WithAlias("sub2")
|
||||
.WithSortOrder(9)
|
||||
.Done()
|
||||
.Build();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Deep_Clone_Media_Type()
|
||||
{
|
||||
// Arrange
|
||||
var contentType = BuildMediaType();
|
||||
|
||||
// Act
|
||||
var clone = (MediaType)contentType.DeepClone();
|
||||
|
||||
// Assert
|
||||
Assert.AreNotSame(clone, contentType);
|
||||
Assert.AreEqual(clone, contentType);
|
||||
Assert.AreEqual(clone.Id, contentType.Id);
|
||||
Assert.AreEqual(clone.PropertyGroups.Count, contentType.PropertyGroups.Count);
|
||||
for (var index = 0; index < contentType.PropertyGroups.Count; index++)
|
||||
{
|
||||
Assert.AreNotSame(clone.PropertyGroups[index], contentType.PropertyGroups[index]);
|
||||
Assert.AreEqual(clone.PropertyGroups[index], contentType.PropertyGroups[index]);
|
||||
}
|
||||
Assert.AreEqual(clone.PropertyTypes.Count(), contentType.PropertyTypes.Count());
|
||||
for (var index = 0; index < contentType.PropertyTypes.Count(); index++)
|
||||
{
|
||||
Assert.AreNotSame(clone.PropertyTypes.ElementAt(index), contentType.PropertyTypes.ElementAt(index));
|
||||
Assert.AreEqual(clone.PropertyTypes.ElementAt(index), contentType.PropertyTypes.ElementAt(index));
|
||||
}
|
||||
Assert.AreEqual(clone.CreateDate, contentType.CreateDate);
|
||||
Assert.AreEqual(clone.CreatorId, contentType.CreatorId);
|
||||
Assert.AreEqual(clone.Key, contentType.Key);
|
||||
Assert.AreEqual(clone.Level, contentType.Level);
|
||||
Assert.AreEqual(clone.Path, contentType.Path);
|
||||
Assert.AreEqual(clone.SortOrder, contentType.SortOrder);
|
||||
Assert.AreEqual(clone.Trashed, contentType.Trashed);
|
||||
Assert.AreEqual(clone.UpdateDate, contentType.UpdateDate);
|
||||
Assert.AreEqual(clone.Thumbnail, contentType.Thumbnail);
|
||||
Assert.AreEqual(clone.Icon, contentType.Icon);
|
||||
Assert.AreEqual(clone.IsContainer, contentType.IsContainer);
|
||||
|
||||
//This double verifies by reflection
|
||||
var allProps = clone.GetType().GetProperties();
|
||||
foreach (var propertyInfo in allProps)
|
||||
Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(contentType, null));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Serialize_Media_Type_Without_Error()
|
||||
{
|
||||
// Arrange
|
||||
var contentType = BuildMediaType();
|
||||
|
||||
var json = JsonConvert.SerializeObject(contentType);
|
||||
Debug.Print(json);
|
||||
}
|
||||
|
||||
private static IMediaType BuildMediaType()
|
||||
{
|
||||
var builder = new MediaTypeBuilder();
|
||||
return builder
|
||||
.WithId(10)
|
||||
.WithAlias(Constants.Conventions.MediaTypes.Image)
|
||||
.WithName("Image")
|
||||
.WithCreatorId(22)
|
||||
.WithDescription("test")
|
||||
.WithIcon("icon")
|
||||
.WithThumbnail("thumb")
|
||||
.WithSortOrder(5)
|
||||
.WithLevel(3)
|
||||
.WithPath("-1,4,10")
|
||||
.WithPropertyTypeIdsIncrementingFrom(200)
|
||||
.WithMediaPropertyGroup()
|
||||
.Build();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Deep_Clone_Member_Type()
|
||||
{
|
||||
// Arrange
|
||||
var contentType = BuildMemberType();
|
||||
|
||||
// Act
|
||||
var clone = (MemberType)contentType.DeepClone();
|
||||
|
||||
// Assert
|
||||
Assert.AreNotSame(clone, contentType);
|
||||
Assert.AreEqual(clone, contentType);
|
||||
Assert.AreEqual(clone.Id, contentType.Id);
|
||||
Assert.AreEqual(clone.PropertyGroups.Count, contentType.PropertyGroups.Count);
|
||||
for (var index = 0; index < contentType.PropertyGroups.Count; index++)
|
||||
{
|
||||
Assert.AreNotSame(clone.PropertyGroups[index], contentType.PropertyGroups[index]);
|
||||
Assert.AreEqual(clone.PropertyGroups[index], contentType.PropertyGroups[index]);
|
||||
}
|
||||
Assert.AreEqual(clone.PropertyTypes.Count(), contentType.PropertyTypes.Count());
|
||||
for (var index = 0; index < contentType.PropertyTypes.Count(); index++)
|
||||
{
|
||||
Assert.AreNotSame(clone.PropertyTypes.ElementAt(index), contentType.PropertyTypes.ElementAt(index));
|
||||
Assert.AreEqual(clone.PropertyTypes.ElementAt(index), contentType.PropertyTypes.ElementAt(index));
|
||||
}
|
||||
Assert.AreEqual(clone.CreateDate, contentType.CreateDate);
|
||||
Assert.AreEqual(clone.CreatorId, contentType.CreatorId);
|
||||
Assert.AreEqual(clone.Key, contentType.Key);
|
||||
Assert.AreEqual(clone.Level, contentType.Level);
|
||||
Assert.AreEqual(clone.Path, contentType.Path);
|
||||
Assert.AreEqual(clone.SortOrder, contentType.SortOrder);
|
||||
Assert.AreEqual(clone.Trashed, contentType.Trashed);
|
||||
Assert.AreEqual(clone.UpdateDate, contentType.UpdateDate);
|
||||
Assert.AreEqual(clone.Thumbnail, contentType.Thumbnail);
|
||||
Assert.AreEqual(clone.Icon, contentType.Icon);
|
||||
Assert.AreEqual(clone.IsContainer, contentType.IsContainer);
|
||||
Assert.AreEqual(clone.MemberTypePropertyTypes, ((MemberType)contentType).MemberTypePropertyTypes);
|
||||
|
||||
// This double verifies by reflection
|
||||
var allProps = clone.GetType().GetProperties();
|
||||
foreach (var propertyInfo in allProps)
|
||||
Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(contentType, null));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Serialize_Member_Type_Without_Error()
|
||||
{
|
||||
// Arrange
|
||||
var contentType = BuildMemberType();
|
||||
|
||||
var json = JsonConvert.SerializeObject(contentType);
|
||||
Debug.Print(json);
|
||||
}
|
||||
|
||||
private static IMemberType BuildMemberType()
|
||||
{
|
||||
var builder = new MemberTypeBuilder();
|
||||
return builder
|
||||
.WithId(10)
|
||||
.WithAlias("memberType")
|
||||
.WithName("Member type")
|
||||
.WithCreatorId(22)
|
||||
.WithDescription("test")
|
||||
.WithIcon("icon")
|
||||
.WithThumbnail("thumb")
|
||||
.WithSortOrder(5)
|
||||
.WithLevel(3)
|
||||
.WithPath("-1,4,10")
|
||||
.WithPropertyTypeIdsIncrementingFrom(200)
|
||||
.AddPropertyGroup()
|
||||
.WithName("Content")
|
||||
.AddPropertyType()
|
||||
.WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.TextBox)
|
||||
.WithValueStorageType(ValueStorageType.Nvarchar)
|
||||
.WithAlias("title")
|
||||
.WithName("Title")
|
||||
.WithSortOrder(1)
|
||||
.WithDataTypeId(-88)
|
||||
.Done()
|
||||
.AddPropertyType()
|
||||
.WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.TextBox)
|
||||
.WithValueStorageType(ValueStorageType.Ntext)
|
||||
.WithAlias("bodyText")
|
||||
.WithName("Body text")
|
||||
.WithSortOrder(2)
|
||||
.WithDataTypeId(-87)
|
||||
.Done()
|
||||
.Done()
|
||||
.WithMemberCanEditProperty("title", true)
|
||||
.WithMemberCanViewProperty("bodyText", true)
|
||||
.Build();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,7 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Infrastructure.Models
|
||||
Assert.AreEqual(clone.Id, template.Id);
|
||||
Assert.AreEqual(clone.Key, template.Key);
|
||||
Assert.AreEqual(clone.MasterTemplateAlias, template.MasterTemplateAlias);
|
||||
Assert.AreEqual(clone.MasterTemplateId.Value, template.MasterTemplateId.Value);
|
||||
Assert.AreEqual(clone.MasterTemplateId.Value, ((Template)template).MasterTemplateId.Value);
|
||||
Assert.AreEqual(clone.Name, template.Name);
|
||||
Assert.AreEqual(clone.UpdateDate, template.UpdateDate);
|
||||
|
||||
@@ -65,7 +65,7 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Infrastructure.Models
|
||||
Debug.Print(json);
|
||||
}
|
||||
|
||||
private Template BuildTemplate()
|
||||
private ITemplate BuildTemplate()
|
||||
{
|
||||
return _builder
|
||||
.WithId(3)
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace Umbraco.Tests.UnitTests.Umbraco.Tests.Common.Builders
|
||||
{
|
||||
public class AllowedContentTypeDetail
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Alias { get; set; }
|
||||
|
||||
public int SortOrder { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Tests.Common.Builders;
|
||||
using Umbraco.Tests.Common.Builders.Extensions;
|
||||
|
||||
namespace Umbraco.Tests.UnitTests.Umbraco.Tests.Common.Builders
|
||||
{
|
||||
[TestFixture]
|
||||
public class ContentTypeBuilderTests
|
||||
{
|
||||
[Test]
|
||||
public void Is_Built_Correctly()
|
||||
{
|
||||
// Arrange
|
||||
const int testId = 99;
|
||||
var testKey = Guid.NewGuid();
|
||||
const string testAlias = "mediaType";
|
||||
const string testName = "Content Type";
|
||||
const string testPropertyGroupName = "Content";
|
||||
const int testParentId = 98;
|
||||
const int testCreatorId = 22;
|
||||
var testCreateDate = DateTime.Now.AddHours(-1);
|
||||
var testUpdateDate = DateTime.Now;
|
||||
const int testLevel = 3;
|
||||
const string testPath = "-1, 4, 10";
|
||||
const int testSortOrder = 5;
|
||||
const string testDescription = "The description";
|
||||
const string testIcon = "icon";
|
||||
const string testThumbnail = "thumnail";
|
||||
const bool testTrashed = true;
|
||||
const int testPropertyTypeIdsIncrementingFrom = 200;
|
||||
var testPropertyType1 = new PropertyTypeDetail { Alias = "title", Name = "Title", SortOrder = 1, DataTypeId = -88 };
|
||||
var testPropertyType2 = new PropertyTypeDetail { Alias = "bodyText", Name = "Body Text", SortOrder = 2, DataTypeId = -87 };
|
||||
var testTemplate1 = new TemplateDetail { Id = 200, Alias = "template1", Name = "Template 1" };
|
||||
var testTemplate2 = new TemplateDetail { Id = 201, Alias = "template2", Name = "Template 2" };
|
||||
var testAllowedContentType1 = new AllowedContentTypeDetail { Id = 300, Alias = "subType1", SortOrder = 1 };
|
||||
var testAllowedContentType2 = new AllowedContentTypeDetail { Id = 301, Alias = "subType2", SortOrder = 2 };
|
||||
|
||||
var builder = new ContentTypeBuilder();
|
||||
|
||||
// Act
|
||||
var contentType = builder
|
||||
.WithId(testId)
|
||||
.WithKey(testKey)
|
||||
.WithAlias(testAlias)
|
||||
.WithName(testName)
|
||||
.WithCreatorId(testCreatorId)
|
||||
.WithCreateDate(testCreateDate)
|
||||
.WithUpdateDate(testUpdateDate)
|
||||
.WithParentId(testParentId)
|
||||
.WithLevel(testLevel)
|
||||
.WithPath(testPath)
|
||||
.WithSortOrder(testSortOrder)
|
||||
.WithDescription(testDescription)
|
||||
.WithIcon(testIcon)
|
||||
.WithThumbnail(testThumbnail)
|
||||
.WithTrashed(testTrashed)
|
||||
.WithPropertyTypeIdsIncrementingFrom(200)
|
||||
.AddPropertyGroup()
|
||||
.WithName(testPropertyGroupName)
|
||||
.WithSortOrder(1)
|
||||
.AddPropertyType()
|
||||
.WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.TextBox)
|
||||
.WithValueStorageType(ValueStorageType.Nvarchar)
|
||||
.WithAlias(testPropertyType1.Alias)
|
||||
.WithName(testPropertyType1.Name)
|
||||
.WithSortOrder(testPropertyType1.SortOrder)
|
||||
.WithDataTypeId(testPropertyType1.DataTypeId)
|
||||
.Done()
|
||||
.AddPropertyType()
|
||||
.WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.TextBox)
|
||||
.WithValueStorageType(ValueStorageType.Ntext)
|
||||
.WithAlias(testPropertyType2.Alias)
|
||||
.WithName(testPropertyType2.Name)
|
||||
.WithSortOrder(testPropertyType2.SortOrder)
|
||||
.WithDataTypeId(testPropertyType2.DataTypeId)
|
||||
.Done()
|
||||
.Done()
|
||||
.AddAllowedTemplate()
|
||||
.WithId(testTemplate1.Id)
|
||||
.WithAlias(testTemplate1.Alias)
|
||||
.WithName(testTemplate1.Name)
|
||||
.Done()
|
||||
.AddAllowedTemplate()
|
||||
.WithId(testTemplate2.Id)
|
||||
.WithAlias(testTemplate2.Alias)
|
||||
.WithName(testTemplate2.Name)
|
||||
.Done()
|
||||
.WithDefaultTemplateId(testTemplate1.Id)
|
||||
.AddAllowedContentType()
|
||||
.WithId(testAllowedContentType1.Id)
|
||||
.WithAlias(testAllowedContentType1.Alias)
|
||||
.WithSortOrder(testAllowedContentType1.SortOrder)
|
||||
.Done()
|
||||
.AddAllowedContentType()
|
||||
.WithId(testAllowedContentType2.Id)
|
||||
.WithAlias(testAllowedContentType2.Alias)
|
||||
.WithSortOrder(testAllowedContentType2.SortOrder)
|
||||
.Done()
|
||||
.Build();
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(testId, contentType.Id);
|
||||
Assert.AreEqual(testAlias, contentType.Alias);
|
||||
Assert.AreEqual(testName, contentType.Name);
|
||||
Assert.AreEqual(testKey, contentType.Key);
|
||||
Assert.AreEqual(testCreateDate, contentType.CreateDate);
|
||||
Assert.AreEqual(testUpdateDate, contentType.UpdateDate);
|
||||
Assert.AreEqual(testCreatorId, contentType.CreatorId);
|
||||
Assert.AreEqual(testParentId, contentType.ParentId);
|
||||
Assert.AreEqual(testLevel, contentType.Level);
|
||||
Assert.AreEqual(testPath, contentType.Path);
|
||||
Assert.AreEqual(testSortOrder, contentType.SortOrder);
|
||||
Assert.AreEqual(testDescription, contentType.Description);
|
||||
Assert.AreEqual(testIcon, contentType.Icon);
|
||||
Assert.AreEqual(testThumbnail, contentType.Thumbnail);
|
||||
Assert.AreEqual(testTrashed, contentType.Trashed);
|
||||
Assert.IsFalse(contentType.IsContainer);
|
||||
Assert.AreEqual(2, contentType.PropertyTypes.Count());
|
||||
|
||||
var propertyTypeIds = contentType.PropertyTypes.Select(x => x.Id).OrderBy(x => x);
|
||||
Assert.AreEqual(testPropertyTypeIdsIncrementingFrom + 1, propertyTypeIds.Min());
|
||||
Assert.AreEqual(testPropertyTypeIdsIncrementingFrom + 2, propertyTypeIds.Max());
|
||||
|
||||
var allowedTemplates = contentType.AllowedTemplates.ToList();
|
||||
Assert.AreEqual(2, allowedTemplates.Count);
|
||||
Assert.AreEqual(testTemplate1.Id, allowedTemplates[0].Id);
|
||||
Assert.AreEqual(testTemplate1.Alias, allowedTemplates[0].Alias);
|
||||
Assert.AreEqual(testTemplate1.Name, allowedTemplates[0].Name);
|
||||
Assert.AreEqual(testTemplate1.Id, contentType.DefaultTemplate.Id);
|
||||
|
||||
var allowedContentTypes = contentType.AllowedContentTypes.ToList();
|
||||
Assert.AreEqual(2, allowedContentTypes.Count);
|
||||
Assert.AreEqual(testAllowedContentType1.Id, allowedContentTypes[0].Id.Value);
|
||||
Assert.AreEqual(testAllowedContentType1.Alias, allowedContentTypes[0].Alias);
|
||||
Assert.AreEqual(testAllowedContentType1.SortOrder, allowedContentTypes[0].SortOrder);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Tests.Common.Builders;
|
||||
using Umbraco.Tests.Common.Builders.Extensions;
|
||||
|
||||
namespace Umbraco.Tests.UnitTests.Umbraco.Tests.Common.Builders
|
||||
{
|
||||
[TestFixture]
|
||||
public class MediaTypeBuilderTests
|
||||
{
|
||||
[Test]
|
||||
public void Is_Built_Correctly()
|
||||
{
|
||||
// Arrange
|
||||
const int testId = 99;
|
||||
var testKey = Guid.NewGuid();
|
||||
const string testAlias = "mediaType";
|
||||
const string testName = "Media Type";
|
||||
const string testPropertyGroupName = "Additional Content";
|
||||
const int testParentId = 98;
|
||||
const int testCreatorId = 22;
|
||||
var testCreateDate = DateTime.Now.AddHours(-1);
|
||||
var testUpdateDate = DateTime.Now;
|
||||
const int testLevel = 3;
|
||||
const string testPath = "-1, 4, 10";
|
||||
const int testSortOrder = 5;
|
||||
const string testDescription = "The description";
|
||||
const string testIcon = "icon";
|
||||
const string testThumbnail = "thumnail";
|
||||
const bool testTrashed = true;
|
||||
const int testPropertyTypeIdsIncrementingFrom = 200;
|
||||
var testPropertyType1 = new PropertyTypeDetail { Alias = "title", Name = "Title", SortOrder = 1, DataTypeId = -88 };
|
||||
var testPropertyType2 = new PropertyTypeDetail { Alias = "bodyText", Name = "Body Text", SortOrder = 2, DataTypeId = -87 };
|
||||
|
||||
var builder = new MediaTypeBuilder();
|
||||
|
||||
// Act
|
||||
var mediaType = builder
|
||||
.WithId(testId)
|
||||
.WithKey(testKey)
|
||||
.WithAlias(testAlias)
|
||||
.WithName(testName)
|
||||
.WithCreatorId(testCreatorId)
|
||||
.WithCreateDate(testCreateDate)
|
||||
.WithUpdateDate(testUpdateDate)
|
||||
.WithParentId(testParentId)
|
||||
.WithLevel(testLevel)
|
||||
.WithPath(testPath)
|
||||
.WithSortOrder(testSortOrder)
|
||||
.WithDescription(testDescription)
|
||||
.WithIcon(testIcon)
|
||||
.WithThumbnail(testThumbnail)
|
||||
.WithTrashed(testTrashed)
|
||||
.WithPropertyTypeIdsIncrementingFrom(200)
|
||||
.WithMediaPropertyGroup()
|
||||
.AddPropertyGroup()
|
||||
.WithId(1)
|
||||
.WithName(testPropertyGroupName)
|
||||
.WithSortOrder(1)
|
||||
.AddPropertyType()
|
||||
.WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.TextBox)
|
||||
.WithValueStorageType(ValueStorageType.Nvarchar)
|
||||
.WithAlias(testPropertyType1.Alias)
|
||||
.WithName(testPropertyType1.Name)
|
||||
.WithSortOrder(testPropertyType1.SortOrder)
|
||||
.WithDataTypeId(testPropertyType1.DataTypeId)
|
||||
.Done()
|
||||
.AddPropertyType()
|
||||
.WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.TextBox)
|
||||
.WithValueStorageType(ValueStorageType.Ntext)
|
||||
.WithAlias(testPropertyType2.Alias)
|
||||
.WithName(testPropertyType2.Name)
|
||||
.WithSortOrder(testPropertyType2.SortOrder)
|
||||
.WithDataTypeId(testPropertyType2.DataTypeId)
|
||||
.Done()
|
||||
.Done()
|
||||
.Build();
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(testId, mediaType.Id);
|
||||
Assert.AreEqual(testAlias, mediaType.Alias);
|
||||
Assert.AreEqual(testName, mediaType.Name);
|
||||
Assert.AreEqual(testKey, mediaType.Key);
|
||||
Assert.AreEqual(testCreateDate, mediaType.CreateDate);
|
||||
Assert.AreEqual(testUpdateDate, mediaType.UpdateDate);
|
||||
Assert.AreEqual(testCreatorId, mediaType.CreatorId);
|
||||
Assert.AreEqual(testParentId, mediaType.ParentId);
|
||||
Assert.AreEqual(testLevel, mediaType.Level);
|
||||
Assert.AreEqual(testPath, mediaType.Path);
|
||||
Assert.AreEqual(testSortOrder, mediaType.SortOrder);
|
||||
Assert.AreEqual(testDescription, mediaType.Description);
|
||||
Assert.AreEqual(testIcon, mediaType.Icon);
|
||||
Assert.AreEqual(testThumbnail, mediaType.Thumbnail);
|
||||
Assert.AreEqual(testTrashed, mediaType.Trashed);
|
||||
Assert.IsFalse(mediaType.IsContainer);
|
||||
Assert.AreEqual(7, mediaType.PropertyTypes.Count()); // 5 from media properties group, 2 custom
|
||||
|
||||
var propertyTypeIds = mediaType.PropertyTypes.Select(x => x.Id).OrderBy(x => x);
|
||||
Assert.AreEqual(testPropertyTypeIdsIncrementingFrom + 1, propertyTypeIds.Min());
|
||||
Assert.AreEqual(testPropertyTypeIdsIncrementingFrom + 7, propertyTypeIds.Max());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,19 +12,6 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Tests.Common.Builders
|
||||
[TestFixture]
|
||||
public class MemberBuilderTests
|
||||
{
|
||||
private class PropertyTypeDetail
|
||||
{
|
||||
public string Alias { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Description { get; set; } = string.Empty;
|
||||
|
||||
public int SortOrder { get; set; }
|
||||
|
||||
public int DataTypeId { get; set; }
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Is_Built_Correctly()
|
||||
{
|
||||
@@ -61,6 +48,7 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Tests.Common.Builders
|
||||
var testPropertyData3 = new KeyValuePair<string, object>("author", "John Doe");
|
||||
var testAdditionalData1 = new KeyValuePair<string, object>("test1", 123);
|
||||
var testAdditionalData2 = new KeyValuePair<string, object>("test2", "hello");
|
||||
const int testPropertyIdsIncrementingFrom = 200;
|
||||
|
||||
var builder = new MemberBuilder();
|
||||
|
||||
@@ -156,6 +144,11 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Tests.Common.Builders
|
||||
Assert.AreEqual(testPropertyData1.Value, member.GetValue<string>(testPropertyData1.Key));
|
||||
Assert.AreEqual(testPropertyData2.Value, member.GetValue<string>(testPropertyData2.Key));
|
||||
Assert.AreEqual(testPropertyData3.Value, member.GetValue<string>(testPropertyData3.Key));
|
||||
|
||||
var propertyIds = member.Properties.Select(x => x.Id).OrderBy(x => x);
|
||||
Assert.AreEqual(testPropertyIdsIncrementingFrom + 1, propertyIds.Min());
|
||||
Assert.AreEqual(testPropertyIdsIncrementingFrom + 10, propertyIds.Max());
|
||||
|
||||
Assert.AreEqual(2, member.AdditionalData.Count);
|
||||
Assert.AreEqual(testAdditionalData1.Value, member.AdditionalData[testAdditionalData1.Key]);
|
||||
Assert.AreEqual(testAdditionalData2.Value, member.AdditionalData[testAdditionalData2.Key]);
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Tests.Common.Builders;
|
||||
using Umbraco.Tests.Common.Builders.Extensions;
|
||||
|
||||
namespace Umbraco.Tests.UnitTests.Umbraco.Tests.Common.Builders
|
||||
{
|
||||
[TestFixture]
|
||||
public class MemberTypeBuilderTests
|
||||
{
|
||||
[Test]
|
||||
public void Is_Built_Correctly()
|
||||
{
|
||||
// Arrange
|
||||
const int testId = 99;
|
||||
var testKey = Guid.NewGuid();
|
||||
const string testAlias = "memberType";
|
||||
const string testName = "Member Type";
|
||||
const string testPropertyGroupName = "Content";
|
||||
const int testParentId = 98;
|
||||
const int testCreatorId = 22;
|
||||
var testCreateDate = DateTime.Now.AddHours(-1);
|
||||
var testUpdateDate = DateTime.Now;
|
||||
const int testLevel = 3;
|
||||
const string testPath = "-1, 4, 10";
|
||||
const int testSortOrder = 5;
|
||||
const string testDescription = "The description";
|
||||
const string testIcon = "icon";
|
||||
const string testThumbnail = "thumnail";
|
||||
const bool testTrashed = true;
|
||||
const int testPropertyTypeIdsIncrementingFrom = 200;
|
||||
var testPropertyType1 = new PropertyTypeDetail { Alias = "title", Name = "Title", SortOrder = 1, DataTypeId = -88 };
|
||||
var testPropertyType2 = new PropertyTypeDetail { Alias = "bodyText", Name = "Body Text", SortOrder = 2, DataTypeId = -87 };
|
||||
var testPropertyData1 = new KeyValuePair<string, object>("title", "Name member");
|
||||
|
||||
var builder = new MemberTypeBuilder();
|
||||
|
||||
// Act
|
||||
var memberType = builder
|
||||
.WithId(testId)
|
||||
.WithKey(testKey)
|
||||
.WithAlias(testAlias)
|
||||
.WithName(testName)
|
||||
.WithCreatorId(testCreatorId)
|
||||
.WithCreateDate(testCreateDate)
|
||||
.WithUpdateDate(testUpdateDate)
|
||||
.WithParentId(testParentId)
|
||||
.WithLevel(testLevel)
|
||||
.WithPath(testPath)
|
||||
.WithSortOrder(testSortOrder)
|
||||
.WithDescription(testDescription)
|
||||
.WithIcon(testIcon)
|
||||
.WithThumbnail(testThumbnail)
|
||||
.WithTrashed(testTrashed)
|
||||
.WithPropertyTypeIdsIncrementingFrom(200)
|
||||
.WithMembershipPropertyGroup()
|
||||
.AddPropertyGroup()
|
||||
.WithId(1)
|
||||
.WithName(testPropertyGroupName)
|
||||
.WithSortOrder(1)
|
||||
.AddPropertyType()
|
||||
.WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.TextBox)
|
||||
.WithValueStorageType(ValueStorageType.Nvarchar)
|
||||
.WithAlias(testPropertyType1.Alias)
|
||||
.WithName(testPropertyType1.Name)
|
||||
.WithSortOrder(testPropertyType1.SortOrder)
|
||||
.WithDataTypeId(testPropertyType1.DataTypeId)
|
||||
.Done()
|
||||
.AddPropertyType()
|
||||
.WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.TextBox)
|
||||
.WithValueStorageType(ValueStorageType.Ntext)
|
||||
.WithAlias(testPropertyType2.Alias)
|
||||
.WithName(testPropertyType2.Name)
|
||||
.WithSortOrder(testPropertyType2.SortOrder)
|
||||
.WithDataTypeId(testPropertyType2.DataTypeId)
|
||||
.Done()
|
||||
.Done()
|
||||
.WithMemberCanEditProperty(testPropertyType1.Alias, true)
|
||||
.WithMemberCanViewProperty(testPropertyType2.Alias, true)
|
||||
.Build();
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(testId, memberType.Id);
|
||||
Assert.AreEqual(testAlias, memberType.Alias);
|
||||
Assert.AreEqual(testName, memberType.Name);
|
||||
Assert.AreEqual(testKey, memberType.Key);
|
||||
Assert.AreEqual(testCreateDate, memberType.CreateDate);
|
||||
Assert.AreEqual(testUpdateDate, memberType.UpdateDate);
|
||||
Assert.AreEqual(testCreatorId, memberType.CreatorId);
|
||||
Assert.AreEqual(testParentId, memberType.ParentId);
|
||||
Assert.AreEqual(testLevel, memberType.Level);
|
||||
Assert.AreEqual(testPath, memberType.Path);
|
||||
Assert.AreEqual(testSortOrder, memberType.SortOrder);
|
||||
Assert.AreEqual(testDescription, memberType.Description);
|
||||
Assert.AreEqual(testIcon, memberType.Icon);
|
||||
Assert.AreEqual(testThumbnail, memberType.Thumbnail);
|
||||
Assert.AreEqual(testTrashed, memberType.Trashed);
|
||||
Assert.IsFalse(memberType.IsContainer);
|
||||
Assert.AreEqual(9, memberType.PropertyTypes.Count()); // 7 from membership properties group, 2 custom
|
||||
|
||||
var propertyTypeIds = memberType.PropertyTypes.Select(x => x.Id).OrderBy(x => x);
|
||||
Assert.AreEqual(testPropertyTypeIdsIncrementingFrom + 1, propertyTypeIds.Min());
|
||||
Assert.AreEqual(testPropertyTypeIdsIncrementingFrom + 9, propertyTypeIds.Max());
|
||||
|
||||
Assert.IsTrue(memberType.MemberCanEditProperty(testPropertyType1.Alias));
|
||||
Assert.IsFalse(memberType.MemberCanViewProperty(testPropertyType1.Alias));
|
||||
Assert.IsTrue(memberType.MemberCanViewProperty(testPropertyType2.Alias));
|
||||
Assert.IsFalse(memberType.MemberCanEditProperty(testPropertyType2.Alias));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
namespace Umbraco.Tests.UnitTests.Umbraco.Tests.Common.Builders
|
||||
{
|
||||
public class PropertyTypeDetail
|
||||
{
|
||||
public string Alias { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Description { get; set; } = string.Empty;
|
||||
|
||||
public int SortOrder { get; set; }
|
||||
|
||||
public int DataTypeId { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Tests.Common.Builders;
|
||||
using Umbraco.Tests.Common.Builders.Extensions;
|
||||
|
||||
@@ -49,7 +50,7 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Tests.Common.Builders
|
||||
Assert.AreEqual(content, template.Content);
|
||||
Assert.IsTrue(template.IsMasterTemplate);
|
||||
Assert.AreEqual(masterTemplateAlias, template.MasterTemplateAlias);
|
||||
Assert.AreEqual(masterTemplateId, template.MasterTemplateId.Value);
|
||||
Assert.AreEqual(masterTemplateId, ((Template)template).MasterTemplateId.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace Umbraco.Tests.UnitTests.Umbraco.Tests.Common.Builders
|
||||
{
|
||||
public class TemplateDetail
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Alias { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,520 +0,0 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Entities;
|
||||
using Umbraco.Core.Serialization;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Tests.TestHelpers.Entities;
|
||||
using Umbraco.Tests.TestHelpers.Stubs;
|
||||
using Umbraco.Tests.Testing;
|
||||
|
||||
namespace Umbraco.Tests.Models
|
||||
{
|
||||
[TestFixture]
|
||||
public class ContentTypeTests : UmbracoTestBase
|
||||
{
|
||||
[Test]
|
||||
[Ignore("Ignoring this test until we actually enforce this, see comments in ContentTypeBase.PropertyTypesChanged")]
|
||||
public void Cannot_Add_Duplicate_Property_Aliases()
|
||||
{
|
||||
var contentType = MockedContentTypes.CreateBasicContentType();
|
||||
|
||||
contentType.PropertyGroups.Add(new PropertyGroup(new PropertyTypeCollection(false, new[]
|
||||
{
|
||||
new PropertyType(TestHelper.ShortStringHelper, "testPropertyEditor", ValueStorageType.Nvarchar){ Alias = "myPropertyType" }
|
||||
})));
|
||||
|
||||
Assert.Throws<InvalidOperationException>(() =>
|
||||
contentType.PropertyTypeCollection.Add(
|
||||
new PropertyType(TestHelper.ShortStringHelper, "testPropertyEditor", ValueStorageType.Nvarchar) { Alias = "myPropertyType" }));
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Ignore("Ignoring this test until we actually enforce this, see comments in ContentTypeBase.PropertyTypesChanged")]
|
||||
public void Cannot_Update_Duplicate_Property_Aliases()
|
||||
{
|
||||
var contentType = MockedContentTypes.CreateBasicContentType();
|
||||
|
||||
contentType.PropertyGroups.Add(new PropertyGroup(new PropertyTypeCollection(false, new[]
|
||||
{
|
||||
new PropertyType(TestHelper.ShortStringHelper, "testPropertyEditor", ValueStorageType.Nvarchar){ Alias = "myPropertyType" }
|
||||
})));
|
||||
|
||||
contentType.PropertyTypeCollection.Add(new PropertyType(TestHelper.ShortStringHelper, "testPropertyEditor", ValueStorageType.Nvarchar) { Alias = "myPropertyType2" });
|
||||
|
||||
var toUpdate = contentType.PropertyTypeCollection["myPropertyType2"];
|
||||
|
||||
Assert.Throws<InvalidOperationException>(() => toUpdate.Alias = "myPropertyType");
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Deep_Clone_Content_Type_Sort()
|
||||
{
|
||||
var contentType = new ContentTypeSort(new Lazy<int>(() => 3), 4, "test");
|
||||
var clone = (ContentTypeSort)contentType.DeepClone();
|
||||
Assert.AreNotSame(clone, contentType);
|
||||
Assert.AreEqual(clone, contentType);
|
||||
Assert.AreEqual(clone.Id.Value, contentType.Id.Value);
|
||||
Assert.AreEqual(clone.SortOrder, contentType.SortOrder);
|
||||
Assert.AreEqual(clone.Alias, contentType.Alias);
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Deep_Clone_Content_Type_With_Reset_Identities()
|
||||
{
|
||||
var contentType = MockedContentTypes.CreateTextPageContentType();
|
||||
contentType.Id = 99;
|
||||
|
||||
var i = 200;
|
||||
foreach (var propertyType in contentType.PropertyTypes)
|
||||
{
|
||||
propertyType.Id = ++i;
|
||||
}
|
||||
foreach (var group in contentType.PropertyGroups)
|
||||
{
|
||||
group.Id = ++i;
|
||||
}
|
||||
//add a property type without a property group
|
||||
contentType.PropertyTypeCollection.Add(
|
||||
new PropertyType(TestHelper.ShortStringHelper, "test", ValueStorageType.Ntext, "title2") { Name = "Title2", Description = "", Mandatory = false, SortOrder = 1, DataTypeId = -88 });
|
||||
|
||||
contentType.AllowedTemplates = new[] { new Template(TestHelper.ShortStringHelper, "Name", "name") { Id = 200 }, new Template(TestHelper.ShortStringHelper, "Name2", "name2") { Id = 201 } };
|
||||
contentType.AllowedContentTypes = new[] { new ContentTypeSort(new Lazy<int>(() => 888), 8, "sub"), new ContentTypeSort(new Lazy<int>(() => 889), 9, "sub2") };
|
||||
contentType.Id = 10;
|
||||
contentType.CreateDate = DateTime.Now;
|
||||
contentType.CreatorId = 22;
|
||||
contentType.SetDefaultTemplate(new Template(TestHelper.ShortStringHelper, (string)"Test Template", (string)"testTemplate")
|
||||
{
|
||||
Id = 88
|
||||
});
|
||||
contentType.Description = "test";
|
||||
contentType.Icon = "icon";
|
||||
contentType.IsContainer = true;
|
||||
contentType.Thumbnail = "thumb";
|
||||
contentType.Key = Guid.NewGuid();
|
||||
contentType.Level = 3;
|
||||
contentType.Path = "-1,4,10";
|
||||
contentType.SortOrder = 5;
|
||||
contentType.Trashed = false;
|
||||
contentType.UpdateDate = DateTime.Now;
|
||||
|
||||
//ensure that nothing is marked as dirty
|
||||
contentType.ResetDirtyProperties(false);
|
||||
|
||||
var clone = (ContentType)contentType.DeepCloneWithResetIdentities("newAlias");
|
||||
|
||||
Assert.AreEqual("newAlias", clone.Alias);
|
||||
Assert.AreNotEqual("newAlias", contentType.Alias);
|
||||
Assert.IsFalse(clone.HasIdentity);
|
||||
|
||||
foreach (var propertyGroup in clone.PropertyGroups)
|
||||
{
|
||||
Assert.IsFalse(propertyGroup.HasIdentity);
|
||||
foreach (var propertyType in propertyGroup.PropertyTypes)
|
||||
{
|
||||
Assert.IsFalse(propertyType.HasIdentity);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var propertyType in clone.PropertyTypes.Where(x => x.HasIdentity))
|
||||
{
|
||||
Assert.IsFalse(propertyType.HasIdentity);
|
||||
}
|
||||
}
|
||||
|
||||
private static IProfilingLogger GetTestProfilingLogger()
|
||||
{
|
||||
var logger = new DebugDiagnosticsLogger(new MessageTemplates());
|
||||
var profiler = new TestProfiler();
|
||||
return new ProfilingLogger(logger, profiler);
|
||||
}
|
||||
|
||||
[Ignore("fixme - ignored test")]
|
||||
[Test]
|
||||
public void Can_Deep_Clone_Content_Type_Perf_Test()
|
||||
{
|
||||
// Arrange
|
||||
var contentType = MockedContentTypes.CreateTextPageContentType();
|
||||
contentType.Id = 99;
|
||||
|
||||
var i = 200;
|
||||
foreach (var propertyType in contentType.PropertyTypes)
|
||||
{
|
||||
propertyType.Id = ++i;
|
||||
}
|
||||
foreach (var group in contentType.PropertyGroups)
|
||||
{
|
||||
group.Id = ++i;
|
||||
}
|
||||
contentType.AllowedTemplates = new[] { new Template(TestHelper.ShortStringHelper, (string)"Name", (string)"name") { Id = 200 }, new Template(TestHelper.ShortStringHelper, (string)"Name2", (string)"name2") { Id = 201 } };
|
||||
contentType.AllowedContentTypes = new[] { new ContentTypeSort(new Lazy<int>(() => 888), 8, "sub"), new ContentTypeSort(new Lazy<int>(() => 889), 9, "sub2") };
|
||||
contentType.Id = 10;
|
||||
contentType.CreateDate = DateTime.Now;
|
||||
contentType.CreatorId = 22;
|
||||
contentType.SetDefaultTemplate(new Template(TestHelper.ShortStringHelper, (string)"Test Template", (string)"testTemplate")
|
||||
{
|
||||
Id = 88
|
||||
});
|
||||
contentType.Description = "test";
|
||||
contentType.Icon = "icon";
|
||||
contentType.IsContainer = true;
|
||||
contentType.Thumbnail = "thumb";
|
||||
contentType.Key = Guid.NewGuid();
|
||||
contentType.Level = 3;
|
||||
contentType.Path = "-1,4,10";
|
||||
contentType.SortOrder = 5;
|
||||
contentType.Trashed = false;
|
||||
contentType.UpdateDate = DateTime.Now;
|
||||
|
||||
var proflog = GetTestProfilingLogger();
|
||||
|
||||
using (proflog.DebugDuration<ContentTypeTests>("STARTING PERF TEST"))
|
||||
{
|
||||
for (var j = 0; j < 1000; j++)
|
||||
{
|
||||
using (proflog.DebugDuration<ContentTypeTests>("Cloning content type"))
|
||||
{
|
||||
var clone = (ContentType)contentType.DeepClone();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Deep_Clone_Content_Type()
|
||||
{
|
||||
// Arrange
|
||||
var contentType = MockedContentTypes.CreateTextPageContentType();
|
||||
contentType.Id = 99;
|
||||
|
||||
var i = 200;
|
||||
foreach (var propertyType in contentType.PropertyTypes)
|
||||
{
|
||||
propertyType.Id = ++i;
|
||||
}
|
||||
foreach (var group in contentType.PropertyGroups)
|
||||
{
|
||||
group.Id = ++i;
|
||||
}
|
||||
contentType.AllowedTemplates = new[] { new Template(TestHelper.ShortStringHelper, (string)"Name", (string)"name") { Id = 200 }, new Template(TestHelper.ShortStringHelper, (string)"Name2", (string)"name2") { Id = 201 } };
|
||||
contentType.AllowedContentTypes = new[] { new ContentTypeSort(new Lazy<int>(() => 888), 8, "sub"), new ContentTypeSort(new Lazy<int>(() => 889), 9, "sub2") };
|
||||
contentType.Id = 10;
|
||||
contentType.CreateDate = DateTime.Now;
|
||||
contentType.CreatorId = 22;
|
||||
contentType.SetDefaultTemplate(new Template(TestHelper.ShortStringHelper, (string)"Test Template", (string)"testTemplate")
|
||||
{
|
||||
Id = 88
|
||||
});
|
||||
contentType.Description = "test";
|
||||
contentType.Icon = "icon";
|
||||
contentType.IsContainer = true;
|
||||
contentType.Thumbnail = "thumb";
|
||||
contentType.Key = Guid.NewGuid();
|
||||
contentType.Level = 3;
|
||||
contentType.Path = "-1,4,10";
|
||||
contentType.SortOrder = 5;
|
||||
contentType.Trashed = false;
|
||||
contentType.UpdateDate = DateTime.Now;
|
||||
|
||||
// Act
|
||||
var clone = (ContentType)contentType.DeepClone();
|
||||
|
||||
// Assert
|
||||
Assert.AreNotSame(clone, contentType);
|
||||
Assert.AreEqual(clone, contentType);
|
||||
Assert.AreEqual(clone.Id, contentType.Id);
|
||||
Assert.AreEqual(clone.AllowedTemplates.Count(), contentType.AllowedTemplates.Count());
|
||||
for (var index = 0; index < contentType.AllowedTemplates.Count(); index++)
|
||||
{
|
||||
Assert.AreNotSame(clone.AllowedTemplates.ElementAt(index), contentType.AllowedTemplates.ElementAt(index));
|
||||
Assert.AreEqual(clone.AllowedTemplates.ElementAt(index), contentType.AllowedTemplates.ElementAt(index));
|
||||
}
|
||||
Assert.AreNotSame(clone.PropertyGroups, contentType.PropertyGroups);
|
||||
Assert.AreEqual(clone.PropertyGroups.Count, contentType.PropertyGroups.Count);
|
||||
for (var index = 0; index < contentType.PropertyGroups.Count; index++)
|
||||
{
|
||||
Assert.AreNotSame(clone.PropertyGroups[index], contentType.PropertyGroups[index]);
|
||||
Assert.AreEqual(clone.PropertyGroups[index], contentType.PropertyGroups[index]);
|
||||
}
|
||||
Assert.AreNotSame(clone.PropertyTypes, contentType.PropertyTypes);
|
||||
Assert.AreEqual(clone.PropertyTypes.Count(), contentType.PropertyTypes.Count());
|
||||
Assert.AreEqual(0, clone.NoGroupPropertyTypes.Count());
|
||||
for (var index = 0; index < contentType.PropertyTypes.Count(); index++)
|
||||
{
|
||||
Assert.AreNotSame(clone.PropertyTypes.ElementAt(index), contentType.PropertyTypes.ElementAt(index));
|
||||
Assert.AreEqual(clone.PropertyTypes.ElementAt(index), contentType.PropertyTypes.ElementAt(index));
|
||||
}
|
||||
|
||||
Assert.AreEqual(clone.CreateDate, contentType.CreateDate);
|
||||
Assert.AreEqual(clone.CreatorId, contentType.CreatorId);
|
||||
Assert.AreEqual(clone.Key, contentType.Key);
|
||||
Assert.AreEqual(clone.Level, contentType.Level);
|
||||
Assert.AreEqual(clone.Path, contentType.Path);
|
||||
Assert.AreEqual(clone.SortOrder, contentType.SortOrder);
|
||||
Assert.AreNotSame(clone.DefaultTemplate, contentType.DefaultTemplate);
|
||||
Assert.AreEqual(clone.DefaultTemplate, contentType.DefaultTemplate);
|
||||
Assert.AreEqual(clone.DefaultTemplateId, contentType.DefaultTemplateId);
|
||||
Assert.AreEqual(clone.Trashed, contentType.Trashed);
|
||||
Assert.AreEqual(clone.UpdateDate, contentType.UpdateDate);
|
||||
Assert.AreEqual(clone.Thumbnail, contentType.Thumbnail);
|
||||
Assert.AreEqual(clone.Icon, contentType.Icon);
|
||||
Assert.AreEqual(clone.IsContainer, contentType.IsContainer);
|
||||
|
||||
//This double verifies by reflection
|
||||
var allProps = clone.GetType().GetProperties();
|
||||
foreach (var propertyInfo in allProps)
|
||||
{
|
||||
Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(contentType, null));
|
||||
}
|
||||
|
||||
//need to ensure the event handlers are wired
|
||||
|
||||
var asDirty = (ICanBeDirty)clone;
|
||||
|
||||
Assert.IsFalse(asDirty.IsPropertyDirty("PropertyTypes"));
|
||||
clone.AddPropertyType(new PropertyType(TestHelper.ShortStringHelper, "test", ValueStorageType.Nvarchar, "blah"));
|
||||
Assert.IsTrue(asDirty.IsPropertyDirty("PropertyTypes"));
|
||||
Assert.IsFalse(asDirty.IsPropertyDirty("PropertyGroups"));
|
||||
clone.AddPropertyGroup("hello");
|
||||
Assert.IsTrue(asDirty.IsPropertyDirty("PropertyGroups"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Serialize_Content_Type_Without_Error()
|
||||
{
|
||||
// Arrange
|
||||
var contentType = MockedContentTypes.CreateTextPageContentType();
|
||||
contentType.Id = 99;
|
||||
|
||||
var i = 200;
|
||||
foreach (var propertyType in contentType.PropertyTypes)
|
||||
{
|
||||
propertyType.Id = ++i;
|
||||
}
|
||||
contentType.AllowedTemplates = new[] { new Template(TestHelper.ShortStringHelper, (string)"Name", (string)"name") { Id = 200 }, new Template(TestHelper.ShortStringHelper, (string)"Name2", (string)"name2") { Id = 201 } };
|
||||
contentType.AllowedContentTypes = new[] { new ContentTypeSort(new Lazy<int>(() => 888), 8, "sub"), new ContentTypeSort(new Lazy<int>(() => 889), 9, "sub2") };
|
||||
contentType.Id = 10;
|
||||
contentType.CreateDate = DateTime.Now;
|
||||
contentType.CreatorId = 22;
|
||||
contentType.SetDefaultTemplate(new Template(TestHelper.ShortStringHelper, (string)"Test Template", (string)"testTemplate")
|
||||
{
|
||||
Id = 88
|
||||
});
|
||||
contentType.Description = "test";
|
||||
contentType.Icon = "icon";
|
||||
contentType.IsContainer = true;
|
||||
contentType.Thumbnail = "thumb";
|
||||
contentType.Key = Guid.NewGuid();
|
||||
contentType.Level = 3;
|
||||
contentType.Path = "-1,4,10";
|
||||
contentType.SortOrder = 5;
|
||||
contentType.Trashed = false;
|
||||
contentType.UpdateDate = DateTime.Now;
|
||||
|
||||
var json = JsonConvert.SerializeObject(contentType);
|
||||
Debug.Print(json);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Deep_Clone_Media_Type()
|
||||
{
|
||||
// Arrange
|
||||
var contentType = MockedContentTypes.CreateImageMediaType();
|
||||
contentType.Id = 99;
|
||||
|
||||
var i = 200;
|
||||
foreach (var propertyType in contentType.PropertyTypes)
|
||||
{
|
||||
propertyType.Id = ++i;
|
||||
}
|
||||
contentType.Id = 10;
|
||||
contentType.CreateDate = DateTime.Now;
|
||||
contentType.CreatorId = 22;
|
||||
contentType.Description = "test";
|
||||
contentType.Icon = "icon";
|
||||
contentType.IsContainer = true;
|
||||
contentType.Thumbnail = "thumb";
|
||||
contentType.Key = Guid.NewGuid();
|
||||
contentType.Level = 3;
|
||||
contentType.Path = "-1,4,10";
|
||||
contentType.SortOrder = 5;
|
||||
contentType.Trashed = false;
|
||||
contentType.UpdateDate = DateTime.Now;
|
||||
|
||||
// Act
|
||||
var clone = (MediaType)contentType.DeepClone();
|
||||
|
||||
// Assert
|
||||
Assert.AreNotSame(clone, contentType);
|
||||
Assert.AreEqual(clone, contentType);
|
||||
Assert.AreEqual(clone.Id, contentType.Id);
|
||||
Assert.AreEqual(clone.PropertyGroups.Count, contentType.PropertyGroups.Count);
|
||||
for (var index = 0; index < contentType.PropertyGroups.Count; index++)
|
||||
{
|
||||
Assert.AreNotSame(clone.PropertyGroups[index], contentType.PropertyGroups[index]);
|
||||
Assert.AreEqual(clone.PropertyGroups[index], contentType.PropertyGroups[index]);
|
||||
}
|
||||
Assert.AreEqual(clone.PropertyTypes.Count(), contentType.PropertyTypes.Count());
|
||||
for (var index = 0; index < contentType.PropertyTypes.Count(); index++)
|
||||
{
|
||||
Assert.AreNotSame(clone.PropertyTypes.ElementAt(index), contentType.PropertyTypes.ElementAt(index));
|
||||
Assert.AreEqual(clone.PropertyTypes.ElementAt(index), contentType.PropertyTypes.ElementAt(index));
|
||||
}
|
||||
Assert.AreEqual(clone.CreateDate, contentType.CreateDate);
|
||||
Assert.AreEqual(clone.CreatorId, contentType.CreatorId);
|
||||
Assert.AreEqual(clone.Key, contentType.Key);
|
||||
Assert.AreEqual(clone.Level, contentType.Level);
|
||||
Assert.AreEqual(clone.Path, contentType.Path);
|
||||
Assert.AreEqual(clone.SortOrder, contentType.SortOrder);
|
||||
Assert.AreEqual(clone.Trashed, contentType.Trashed);
|
||||
Assert.AreEqual(clone.UpdateDate, contentType.UpdateDate);
|
||||
Assert.AreEqual(clone.Thumbnail, contentType.Thumbnail);
|
||||
Assert.AreEqual(clone.Icon, contentType.Icon);
|
||||
Assert.AreEqual(clone.IsContainer, contentType.IsContainer);
|
||||
|
||||
//This double verifies by reflection
|
||||
var allProps = clone.GetType().GetProperties();
|
||||
foreach (var propertyInfo in allProps)
|
||||
{
|
||||
Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(contentType, null));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Serialize_Media_Type_Without_Error()
|
||||
{
|
||||
// Arrange
|
||||
var contentType = MockedContentTypes.CreateImageMediaType();
|
||||
contentType.Id = 99;
|
||||
|
||||
var i = 200;
|
||||
foreach (var propertyType in contentType.PropertyTypes)
|
||||
{
|
||||
propertyType.Id = ++i;
|
||||
}
|
||||
contentType.Id = 10;
|
||||
contentType.CreateDate = DateTime.Now;
|
||||
contentType.CreatorId = 22;
|
||||
contentType.Description = "test";
|
||||
contentType.Icon = "icon";
|
||||
contentType.IsContainer = true;
|
||||
contentType.Thumbnail = "thumb";
|
||||
contentType.Key = Guid.NewGuid();
|
||||
contentType.Level = 3;
|
||||
contentType.Path = "-1,4,10";
|
||||
contentType.SortOrder = 5;
|
||||
contentType.Trashed = false;
|
||||
contentType.UpdateDate = DateTime.Now;
|
||||
|
||||
var json = JsonConvert.SerializeObject(contentType);
|
||||
Debug.Print(json);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Deep_Clone_Member_Type()
|
||||
{
|
||||
// Arrange
|
||||
var contentType = MockedContentTypes.CreateSimpleMemberType();
|
||||
contentType.Id = 99;
|
||||
|
||||
var i = 200;
|
||||
foreach (var propertyType in contentType.PropertyTypes)
|
||||
{
|
||||
propertyType.Id = ++i;
|
||||
}
|
||||
contentType.Id = 10;
|
||||
contentType.CreateDate = DateTime.Now;
|
||||
contentType.CreatorId = 22;
|
||||
contentType.Description = "test";
|
||||
contentType.Icon = "icon";
|
||||
contentType.IsContainer = true;
|
||||
contentType.Thumbnail = "thumb";
|
||||
contentType.Key = Guid.NewGuid();
|
||||
contentType.Level = 3;
|
||||
contentType.Path = "-1,4,10";
|
||||
contentType.SortOrder = 5;
|
||||
contentType.Trashed = false;
|
||||
contentType.UpdateDate = DateTime.Now;
|
||||
contentType.SetMemberCanEditProperty("title", true);
|
||||
contentType.SetMemberCanViewProperty("bodyText", true);
|
||||
|
||||
// Act
|
||||
var clone = (MemberType)contentType.DeepClone();
|
||||
|
||||
// Assert
|
||||
Assert.AreNotSame(clone, contentType);
|
||||
Assert.AreEqual(clone, contentType);
|
||||
Assert.AreEqual(clone.Id, contentType.Id);
|
||||
Assert.AreEqual(clone.PropertyGroups.Count, contentType.PropertyGroups.Count);
|
||||
for (var index = 0; index < contentType.PropertyGroups.Count; index++)
|
||||
{
|
||||
Assert.AreNotSame(clone.PropertyGroups[index], contentType.PropertyGroups[index]);
|
||||
Assert.AreEqual(clone.PropertyGroups[index], contentType.PropertyGroups[index]);
|
||||
}
|
||||
Assert.AreEqual(clone.PropertyTypes.Count(), contentType.PropertyTypes.Count());
|
||||
for (var index = 0; index < contentType.PropertyTypes.Count(); index++)
|
||||
{
|
||||
Assert.AreNotSame(clone.PropertyTypes.ElementAt(index), contentType.PropertyTypes.ElementAt(index));
|
||||
Assert.AreEqual(clone.PropertyTypes.ElementAt(index), contentType.PropertyTypes.ElementAt(index));
|
||||
}
|
||||
Assert.AreEqual(clone.CreateDate, contentType.CreateDate);
|
||||
Assert.AreEqual(clone.CreatorId, contentType.CreatorId);
|
||||
Assert.AreEqual(clone.Key, contentType.Key);
|
||||
Assert.AreEqual(clone.Level, contentType.Level);
|
||||
Assert.AreEqual(clone.Path, contentType.Path);
|
||||
Assert.AreEqual(clone.SortOrder, contentType.SortOrder);
|
||||
Assert.AreEqual(clone.Trashed, contentType.Trashed);
|
||||
Assert.AreEqual(clone.UpdateDate, contentType.UpdateDate);
|
||||
Assert.AreEqual(clone.Thumbnail, contentType.Thumbnail);
|
||||
Assert.AreEqual(clone.Icon, contentType.Icon);
|
||||
Assert.AreEqual(clone.IsContainer, contentType.IsContainer);
|
||||
Assert.AreEqual(clone.MemberTypePropertyTypes, contentType.MemberTypePropertyTypes);
|
||||
|
||||
//This double verifies by reflection
|
||||
var allProps = clone.GetType().GetProperties();
|
||||
foreach (var propertyInfo in allProps)
|
||||
{
|
||||
Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(contentType, null));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Serialize_Member_Type_Without_Error()
|
||||
{
|
||||
// Arrange
|
||||
var contentType = MockedContentTypes.CreateSimpleMemberType();
|
||||
contentType.Id = 99;
|
||||
|
||||
var i = 200;
|
||||
foreach (var propertyType in contentType.PropertyTypes)
|
||||
{
|
||||
propertyType.Id = ++i;
|
||||
}
|
||||
contentType.Id = 10;
|
||||
contentType.CreateDate = DateTime.Now;
|
||||
contentType.CreatorId = 22;
|
||||
contentType.Description = "test";
|
||||
contentType.Icon = "icon";
|
||||
contentType.IsContainer = true;
|
||||
contentType.Thumbnail = "thumb";
|
||||
contentType.Key = Guid.NewGuid();
|
||||
contentType.Level = 3;
|
||||
contentType.Path = "-1,4,10";
|
||||
contentType.SortOrder = 5;
|
||||
contentType.Trashed = false;
|
||||
contentType.UpdateDate = DateTime.Now;
|
||||
contentType.SetMemberCanEditProperty("title", true);
|
||||
contentType.SetMemberCanViewProperty("bodyText", true);
|
||||
|
||||
var json = JsonConvert.SerializeObject(contentType);
|
||||
Debug.Print(json);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -290,7 +290,6 @@
|
||||
<Compile Include="Models\Collections\Item.cs" />
|
||||
<Compile Include="Models\Collections\OrderItem.cs" />
|
||||
<Compile Include="Models\Collections\SimpleOrder.cs" />
|
||||
<Compile Include="Models\ContentTypeTests.cs" />
|
||||
<Compile Include="Models\DictionaryTranslationTests.cs" />
|
||||
<Compile Include="Web\Mvc\RenderModelBinderTests.cs" />
|
||||
<Compile Include="Web\Mvc\SurfaceControllerTests.cs" />
|
||||
|
||||
Reference in New Issue
Block a user