Merge remote-tracking branch 'origin/netcore/dev' into netcore/feature/ab5819-initialize-composers

This commit is contained in:
Bjarke Berg
2020-04-14 07:29:59 +02:00
34 changed files with 1252 additions and 468 deletions
-2
View File
@@ -31,8 +31,6 @@ namespace Umbraco.Core.Models
_childObjectType = childObjectType;
}
/// <summary>
/// Gets or sets the Name of the RelationType
/// </summary>
@@ -76,6 +76,9 @@
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>Umbraco.Tests.Integration</_Parameter1>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>Umbraco.Tests.Common</_Parameter1>
</AssemblyAttribute>
</ItemGroup>
<ItemGroup>
@@ -33,6 +33,13 @@ namespace Umbraco.Tests.Common.Builders.Extensions
return builder;
}
public static T WithDeleteDate<T>(this T builder, DateTime deleteDate)
where T : IWithDeleteDateBuilder
{
builder.DeleteDate = deleteDate;
return builder;
}
public static T WithAlias<T>(this T builder, string alias)
where T : IWithAliasBuilder
{
@@ -0,0 +1,6 @@
namespace Umbraco.Tests.Common.Builders.Interfaces
{
public interface IBuildPropertyGroups
{
}
}
@@ -0,0 +1,6 @@
namespace Umbraco.Tests.Common.Builders.Interfaces
{
public interface IBuildPropertyTypes
{
}
}
@@ -155,7 +155,7 @@ namespace Umbraco.Tests.Common.Builders
if (_memberTypeBuilder == null)
{
throw new InvalidOperationException("A member cannot be constructed without providing a member type (use AddMemberType).");
throw new InvalidOperationException("A member cannot be constructed without providing a member type. Use AddMemberType().");
}
var memberType = _memberTypeBuilder.Build();
@@ -10,7 +10,8 @@ using Umbraco.Tests.Common.Builders.Interfaces;
namespace Umbraco.Tests.Common.Builders
{
public class MemberTypeBuilder
: ChildBuilderBase<MemberBuilder, MemberType>,
: ChildBuilderBase<MemberBuilder, IMemberType>,
IBuildPropertyGroups,
IWithIdBuilder,
IWithAliasBuilder,
IWithNameBuilder,
@@ -22,7 +23,7 @@ namespace Umbraco.Tests.Common.Builders
IWithThumbnailBuilder,
IWithTrashedBuilder
{
private readonly List<PropertyGroupBuilder> _propertyGroupBuilders = new List<PropertyGroupBuilder>();
private readonly List<PropertyGroupBuilder<MemberTypeBuilder>> _propertyGroupBuilders = new List<PropertyGroupBuilder<MemberTypeBuilder>>();
private int? _id;
private string _alias;
@@ -41,7 +42,8 @@ namespace Umbraco.Tests.Common.Builders
public MemberTypeBuilder WithMembershipPropertyGroup()
{
var builder = new PropertyGroupBuilder(this)
var builder = new PropertyGroupBuilder<MemberTypeBuilder>(this)
.WithId(99)
.WithName(Constants.Conventions.Member.StandardPropertiesGroupName)
.WithSortOrder(1)
.AddPropertyType()
@@ -90,14 +92,14 @@ namespace Umbraco.Tests.Common.Builders
return this;
}
public PropertyGroupBuilder AddPropertyGroup()
public PropertyGroupBuilder<MemberTypeBuilder> AddPropertyGroup()
{
var builder = new PropertyGroupBuilder(this);
var builder = new PropertyGroupBuilder<MemberTypeBuilder>(this);
_propertyGroupBuilders.Add(builder);
return builder;
}
public override MemberType Build()
public override IMemberType Build()
{
var id = _id ?? 1;
var name = _name ?? Guid.NewGuid().ToString();
@@ -0,0 +1,71 @@
using System;
using Umbraco.Core.Models;
using Umbraco.Tests.Common.Builders.Interfaces;
namespace Umbraco.Tests.Common.Builders
{
public class PropertyBuilder
: BuilderBase<IProperty>,
IBuildPropertyTypes,
IWithIdBuilder,
IWithKeyBuilder,
IWithCreateDateBuilder,
IWithUpdateDateBuilder
{
private PropertyTypeBuilder<PropertyBuilder> _propertyTypeBuilder;
private int? _id;
private Guid? _key;
private DateTime? _createDate;
private DateTime? _updateDate;
public PropertyTypeBuilder<PropertyBuilder> AddPropertyType()
{
var builder = new PropertyTypeBuilder<PropertyBuilder>(this);
_propertyTypeBuilder = builder;
return builder;
}
public override IProperty Build()
{
var id = _id ?? 1;
var key = _key ?? Guid.NewGuid();
var createDate = _createDate ?? DateTime.Now;
var updateDate = _updateDate ?? DateTime.Now;
// Needs to be within collection to support publishing.
var propertyTypeCollection = new PropertyTypeCollection(true, new[] { _propertyTypeBuilder.Build() });
return new Property(id, propertyTypeCollection[0])
{
Key = key,
CreateDate = createDate,
UpdateDate = updateDate,
};
}
int? IWithIdBuilder.Id
{
get => _id;
set => _id = value;
}
Guid? IWithKeyBuilder.Key
{
get => _key;
set => _key = value;
}
DateTime? IWithCreateDateBuilder.CreateDate
{
get => _createDate;
set => _createDate = value;
}
DateTime? IWithUpdateDateBuilder.UpdateDate
{
get => _updateDate;
set => _updateDate = value;
}
}
}
@@ -6,29 +6,53 @@ using Umbraco.Tests.Common.Builders.Interfaces;
namespace Umbraco.Tests.Common.Builders
{
public class PropertyGroupBuilder
: ChildBuilderBase<MemberTypeBuilder, PropertyGroup>, // TODO: likely want to generalise this, so can use for document and media types too.
IWithNameBuilder,
IWithSortOrderBuilder
public class PropertyGroupBuilder : PropertyGroupBuilder<NullPropertyGroupBuilderParent>
{
private readonly List<PropertyTypeBuilder> _propertyTypeBuilders = new List<PropertyTypeBuilder>();
public PropertyGroupBuilder() : base(null)
{
}
}
public class NullPropertyGroupBuilderParent : IBuildPropertyGroups
{
}
public class PropertyGroupBuilder<TParent>
: ChildBuilderBase<TParent, PropertyGroup>,
IBuildPropertyTypes,
IWithIdBuilder,
IWithKeyBuilder,
IWithCreateDateBuilder,
IWithUpdateDateBuilder,
IWithNameBuilder,
IWithSortOrderBuilder where TParent: IBuildPropertyGroups
{
private readonly List<PropertyTypeBuilder<PropertyGroupBuilder<TParent>>> _propertyTypeBuilders = new List<PropertyTypeBuilder<PropertyGroupBuilder<TParent>>>();
private int? _id;
private Guid? _key;
private DateTime? _createDate;
private DateTime? _updateDate;
private string _name;
private int? _sortOrder;
public PropertyGroupBuilder(MemberTypeBuilder parentBuilder) : base(parentBuilder)
public PropertyGroupBuilder(TParent parentBuilder) : base(parentBuilder)
{
}
public PropertyTypeBuilder AddPropertyType()
public PropertyTypeBuilder<PropertyGroupBuilder<TParent>> AddPropertyType()
{
var builder = new PropertyTypeBuilder(this);
var builder = new PropertyTypeBuilder<PropertyGroupBuilder<TParent>>(this);
_propertyTypeBuilders.Add(builder);
return builder;
}
public override PropertyGroup Build()
{
var id = _id ?? 1;
var key = _key ?? Guid.NewGuid();
var createDate = _createDate ?? DateTime.Now;
var updateDate = _updateDate ?? DateTime.Now;
var name = _name ?? Guid.NewGuid().ToString();
var sortOrder = _sortOrder ?? 0;
@@ -40,17 +64,45 @@ namespace Umbraco.Tests.Common.Builders
return new PropertyGroup(properties)
{
Id = id,
Key = key,
Name = name,
SortOrder = sortOrder,
CreateDate = createDate,
UpdateDate = updateDate,
};
}
int? IWithIdBuilder.Id
{
get => _id;
set => _id = value;
}
Guid? IWithKeyBuilder.Key
{
get => _key;
set => _key = value;
}
string IWithNameBuilder.Name
{
get => _name;
set => _name = value;
}
DateTime? IWithCreateDateBuilder.CreateDate
{
get => _createDate;
set => _createDate = value;
}
DateTime? IWithUpdateDateBuilder.UpdateDate
{
get => _updateDate;
set => _updateDate = value;
}
int? IWithSortOrderBuilder.SortOrder
{
get => _sortOrder;
@@ -1,5 +1,4 @@
using System;
using Moq;
using Umbraco.Core.Models;
using Umbraco.Core.Strings;
using Umbraco.Tests.Common.Builders.Extensions;
@@ -7,65 +6,139 @@ using Umbraco.Tests.Common.Builders.Interfaces;
namespace Umbraco.Tests.Common.Builders
{
public class PropertyTypeBuilder
: ChildBuilderBase<PropertyGroupBuilder, PropertyType>,
public class PropertyTypeBuilder : PropertyTypeBuilder<NullPropertyTypeBuilderParent>
{
public PropertyTypeBuilder() : base(null)
{
}
}
public class NullPropertyTypeBuilderParent : IBuildPropertyTypes
{
}
public class PropertyTypeBuilder<TParent>
: ChildBuilderBase<TParent, PropertyType>,
IWithIdBuilder,
IWithKeyBuilder,
IWithAliasBuilder,
IWithNameBuilder,
IWithCreateDateBuilder,
IWithUpdateDateBuilder,
IWithSortOrderBuilder,
IWithDescriptionBuilder
IWithDescriptionBuilder where TParent : IBuildPropertyTypes
{
private int? _id;
private Guid? _key;
private string _propertyEditorAlias;
private ValueStorageType? _valueStorageType;
private string _alias;
private string _name;
private DateTime? _createDate;
private DateTime? _updateDate;
private int? _sortOrder;
private string _description;
private int? _dataTypeId;
private Lazy<int> _propertyGroupId;
private bool? _mandatory;
private string _mandatoryMessage;
private string _validationRegExp;
private string _validationRegExpMessage;
public PropertyTypeBuilder(PropertyGroupBuilder parentBuilder) : base(parentBuilder)
public PropertyTypeBuilder(TParent parentBuilder) : base(parentBuilder)
{
}
public PropertyTypeBuilder WithPropertyEditorAlias(string propertyEditorAlias)
public PropertyTypeBuilder<TParent> WithPropertyEditorAlias(string propertyEditorAlias)
{
_propertyEditorAlias = propertyEditorAlias;
return this;
}
public PropertyTypeBuilder WithValueStorageType(ValueStorageType valueStorageType)
public PropertyTypeBuilder<TParent> WithValueStorageType(ValueStorageType valueStorageType)
{
_valueStorageType = valueStorageType;
return this;
}
public PropertyTypeBuilder WithDataTypeId(int dataTypeId)
public PropertyTypeBuilder<TParent> WithDataTypeId(int dataTypeId)
{
_dataTypeId = dataTypeId;
return this;
}
public PropertyTypeBuilder<TParent> WithPropertyGroupId(int propertyGroupId)
{
_propertyGroupId = new Lazy<int>(() => propertyGroupId);
return this;
}
public PropertyTypeBuilder<TParent> WithMandatory(bool mandatory, string mandatoryMessage = "")
{
_mandatory = mandatory;
_mandatoryMessage = mandatoryMessage;
return this;
}
public PropertyTypeBuilder<TParent> WithValidationRegExp(string validationRegExp, string validationRegExpMessage = "")
{
_validationRegExp = validationRegExp;
_validationRegExpMessage = validationRegExpMessage;
return this;
}
public override PropertyType Build()
{
var id = _id ?? 0;
var key = _key ?? Guid.NewGuid();
var propertyEditorAlias = _propertyEditorAlias ?? Guid.NewGuid().ToString().ToCamelCase();
var valueStorageType = _valueStorageType ?? ValueStorageType.Ntext;
var name = _name ?? Guid.NewGuid().ToString();
var alias = _alias ?? name.ToCamelCase();
var createDate = _createDate ?? DateTime.Now;
var updateDate = _updateDate ?? DateTime.Now;
var sortOrder = _sortOrder ?? 0;
var dataTypeId = _dataTypeId ?? 0;
var description = _description ?? string.Empty;
var propertyGroupId = _propertyGroupId ?? null;
var mandatory = _mandatory ?? false;
var mandatoryMessage = _mandatoryMessage ?? string.Empty;
var validationRegExp = _validationRegExp ?? string.Empty;
var validationRegExpMessage = _validationRegExpMessage ?? string.Empty;
var shortStringHelper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig());
return new PropertyType(shortStringHelper, propertyEditorAlias, valueStorageType)
{
Id = id,
Key = key,
Alias = alias,
Name = name,
SortOrder = sortOrder,
DataTypeId = dataTypeId,
Description = description,
CreateDate = createDate,
UpdateDate = updateDate,
PropertyGroupId = propertyGroupId,
Mandatory = mandatory,
MandatoryMessage = mandatoryMessage,
ValidationRegExp = validationRegExp,
ValidationRegExpMessage = validationRegExpMessage,
};
}
int? IWithIdBuilder.Id
{
get => _id;
set => _id = value;
}
Guid? IWithKeyBuilder.Key
{
get => _key;
set => _key = value;
}
string IWithAliasBuilder.Alias
{
get => _alias;
@@ -78,6 +151,18 @@ namespace Umbraco.Tests.Common.Builders
set => _name = value;
}
DateTime? IWithCreateDateBuilder.CreateDate
{
get => _createDate;
set => _createDate = value;
}
DateTime? IWithUpdateDateBuilder.UpdateDate
{
get => _updateDate;
set => _updateDate = value;
}
int? IWithSortOrderBuilder.SortOrder
{
get => _sortOrder;
@@ -0,0 +1,95 @@
using System;
using Umbraco.Core.Models;
using Umbraco.Tests.Common.Builders.Interfaces;
namespace Umbraco.Tests.Common.Builders
{
public class RelationBuilder
: BuilderBase<Relation>,
IWithIdBuilder,
IWithKeyBuilder,
IWithCreateDateBuilder,
IWithUpdateDateBuilder
{
private RelationTypeBuilder _relationTypeBuilder;
private int? _id;
private int? _parentId;
private int? _childId;
private Guid? _key;
private DateTime? _createDate;
private DateTime? _updateDate;
private string _comment;
public RelationBuilder WithComment(string comment)
{
_comment = comment;
return this;
}
public RelationBuilder BetweenIds(int parentId, int childId)
{
_parentId = parentId;
_childId = childId;
return this;
}
public RelationTypeBuilder AddRelationType()
{
var builder = new RelationTypeBuilder(this);
_relationTypeBuilder = builder;
return builder;
}
public override Relation Build()
{
var id = _id ?? 0;
var parentId = _parentId ?? 0;
var childId = _childId ?? 0;
var key = _key ?? Guid.NewGuid();
var createDate = _createDate ?? DateTime.Now;
var updateDate = _updateDate ?? DateTime.Now;
var comment = _comment ?? string.Empty;
if (_relationTypeBuilder == null)
{
throw new InvalidOperationException("Cannot construct a Relation without a RelationType. Use AddRelationType().");
}
var relationType = _relationTypeBuilder.Build();
return new Relation(parentId, childId, relationType)
{
Comment = comment,
CreateDate = createDate,
Id = id,
Key = key,
UpdateDate = updateDate
};
}
int? IWithIdBuilder.Id
{
get => _id;
set => _id = value;
}
Guid? IWithKeyBuilder.Key
{
get => _key;
set => _key = value;
}
DateTime? IWithCreateDateBuilder.CreateDate
{
get => _createDate;
set => _createDate = value;
}
DateTime? IWithUpdateDateBuilder.UpdateDate
{
get => _updateDate;
set => _updateDate = value;
}
}
}
@@ -4,15 +4,8 @@ using Umbraco.Tests.Common.Builders.Interfaces;
namespace Umbraco.Tests.Common.Builders
{
public class RelationTypeBuilder : RelationTypeBuilder<object>
{
public RelationTypeBuilder() : base(null)
{
}
}
public class RelationTypeBuilder<TParent>
: ChildBuilderBase<TParent, IRelationType>,
public class RelationTypeBuilder
: ChildBuilderBase<RelationBuilder, IRelationType>,
IWithIdBuilder,
IWithAliasBuilder,
IWithNameBuilder,
@@ -32,7 +25,11 @@ namespace Umbraco.Tests.Common.Builders
private Guid? _parentObjectType;
private DateTime? _updateDate;
public RelationTypeBuilder(TParent parentBuilder) : base(parentBuilder)
public RelationTypeBuilder() : base(null)
{
}
public RelationTypeBuilder(RelationBuilder parentBuilder) : base(parentBuilder)
{
}
@@ -91,8 +88,7 @@ namespace Umbraco.Tests.Common.Builders
var updateDate = _updateDate ?? DateTime.Now;
var deleteDate = _deleteDate ?? null;
return new RelationType(name, alias, isBidirectional, parentObjectType,
childObjectType)
return new RelationType(name, alias, isBidirectional, parentObjectType, childObjectType)
{
Id = id,
Key = key,
@@ -102,19 +98,19 @@ namespace Umbraco.Tests.Common.Builders
};
}
public RelationTypeBuilder<TParent> WithIsBidirectional(bool isBidirectional)
public RelationTypeBuilder WithIsBidirectional(bool isBidirectional)
{
_isBidirectional = isBidirectional;
return this;
}
public RelationTypeBuilder<TParent> WithChildObjectType(Guid childObjectType)
public RelationTypeBuilder WithChildObjectType(Guid childObjectType)
{
_childObjectType = childObjectType;
return this;
}
public RelationTypeBuilder<TParent> WithParentObjectType(Guid parentObjectType)
public RelationTypeBuilder WithParentObjectType(Guid parentObjectType)
{
_parentObjectType = parentObjectType;
return this;
@@ -0,0 +1,34 @@
using Umbraco.Core.Models;
namespace Umbraco.Tests.Common.Builders
{
public class StylesheetBuilder
: BuilderBase<Stylesheet>
{
private string _path;
private string _content;
public StylesheetBuilder WithPath(string path)
{
_path = path;
return this;
}
public StylesheetBuilder WithContent(string content)
{
_content = content;
return this;
}
public override Stylesheet Build()
{
var path = _path ?? string.Empty;
var content = _content ?? string.Empty;
return new Stylesheet(path)
{
Content = content,
};
}
}
}
@@ -0,0 +1,116 @@
using System;
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 TemplateBuilder
: BuilderBase<Template>,
IWithIdBuilder,
IWithKeyBuilder,
IWithAliasBuilder,
IWithNameBuilder,
IWithCreateDateBuilder,
IWithUpdateDateBuilder,
IWithPathBuilder
{
private int? _id;
private Guid? _key;
private string _alias;
private string _name;
private DateTime? _createDate;
private DateTime? _updateDate;
private string _path;
private string _content;
private bool? _isMasterTemplate;
private string _masterTemplateAlias;
private Lazy<int> _masterTemplateId;
public TemplateBuilder WithContent(string content)
{
_content = content;
return this;
}
public TemplateBuilder AsMasterTemplate(string masterTemplateAlias, int masterTemplateId)
{
_isMasterTemplate = true;
_masterTemplateAlias = masterTemplateAlias;
_masterTemplateId = new Lazy<int>(() => masterTemplateId);
return this;
}
public override Template Build()
{
var id = _id ?? 0;
var key = _key ?? Guid.NewGuid();
var name = _name ?? Guid.NewGuid().ToString();
var alias = _alias ?? name.ToCamelCase();
var createDate = _createDate ?? DateTime.Now;
var updateDate = _updateDate ?? DateTime.Now;
var path = _path ?? string.Empty;
var content = _content;
var isMasterTemplate = _isMasterTemplate ?? false;
var masterTemplateAlias = _masterTemplateAlias ?? string.Empty;
var masterTemplateId = _masterTemplateId ?? null;
var shortStringHelper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig());
return new Template(shortStringHelper, name, alias)
{
Id = id,
Key = key,
CreateDate = createDate,
UpdateDate = updateDate,
Path = path,
Content = content,
IsMasterTemplate = isMasterTemplate,
MasterTemplateAlias = masterTemplateAlias,
MasterTemplateId = masterTemplateId,
};
}
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;
}
DateTime? IWithCreateDateBuilder.CreateDate
{
get => _createDate;
set => _createDate = value;
}
DateTime? IWithUpdateDateBuilder.UpdateDate
{
get => _updateDate;
set => _updateDate = value;
}
string IWithPathBuilder.Path
{
get => _path;
set => _path = value;
}
}
}
@@ -0,0 +1,92 @@
using System;
using System.Diagnostics;
using Newtonsoft.Json;
using NUnit.Framework;
using Umbraco.Core.Models;
using Umbraco.Tests.Common.Builders;
using Umbraco.Tests.Common.Builders.Extensions;
namespace Umbraco.Tests.UnitTests.Umbraco.Infrastructure.Models
{
[TestFixture]
public class PropertyGroupTests
{
private readonly PropertyGroupBuilder _builder = new PropertyGroupBuilder();
[Test]
public void Can_Deep_Clone()
{
var pg = BuildPropertyGroup();
var clone = (PropertyGroup)pg.DeepClone();
Assert.AreNotSame(clone, pg);
Assert.AreEqual(clone, pg);
Assert.AreEqual(clone.Id, pg.Id);
Assert.AreEqual(clone.CreateDate, pg.CreateDate);
Assert.AreEqual(clone.Key, pg.Key);
Assert.AreEqual(clone.Name, pg.Name);
Assert.AreEqual(clone.SortOrder, pg.SortOrder);
Assert.AreEqual(clone.UpdateDate, pg.UpdateDate);
Assert.AreNotSame(clone.PropertyTypes, pg.PropertyTypes);
Assert.AreEqual(clone.PropertyTypes, pg.PropertyTypes);
Assert.AreEqual(clone.PropertyTypes.Count, pg.PropertyTypes.Count);
for (var i = 0; i < pg.PropertyTypes.Count; i++)
{
Assert.AreNotSame(clone.PropertyTypes[i], pg.PropertyTypes[i]);
Assert.AreEqual(clone.PropertyTypes[i], pg.PropertyTypes[i]);
}
//This double verifies by reflection
var allProps = clone.GetType().GetProperties();
foreach (var propertyInfo in allProps)
{
Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(pg, null));
}
}
[Test]
public void Can_Serialize_Without_Error()
{
var pg = BuildPropertyGroup();
var json = JsonConvert.SerializeObject(pg);
Debug.Print(json);
}
private PropertyGroup BuildPropertyGroup()
{
return _builder
.WithId(77)
.WithName("Group1")
.WithSortOrder(555)
.AddPropertyType()
.WithId(3)
.WithPropertyEditorAlias("TestPropertyEditor")
.WithValueStorageType(ValueStorageType.Nvarchar)
.WithAlias("test")
.WithName("Test")
.WithSortOrder(9)
.WithDataTypeId(5)
.WithDescription("testing")
.WithPropertyGroupId(11)
.WithMandatory(true)
.WithValidationRegExp("xxxx")
.Done()
.AddPropertyType()
.WithId(4)
.WithPropertyEditorAlias("TestPropertyEditor2")
.WithValueStorageType(ValueStorageType.Nvarchar)
.WithAlias("test2")
.WithName("Test2")
.WithSortOrder(10)
.WithDataTypeId(6)
.WithDescription("testing2")
.WithPropertyGroupId(12)
.WithMandatory(true)
.WithValidationRegExp("yyyy")
.Done()
.Build();
}
}
}
@@ -0,0 +1,61 @@
using System;
using System.Linq;
using NUnit.Framework;
using Umbraco.Core.Models;
using Umbraco.Tests.Common.Builders;
using Umbraco.Tests.Common.Builders.Extensions;
namespace Umbraco.Tests.UnitTests.Umbraco.Infrastructure.Models
{
[TestFixture]
public class PropertyTests
{
private readonly PropertyBuilder _builder = new PropertyBuilder();
[Test]
public void Can_Deep_Clone()
{
var property = BuildProperty();
property.SetValue("hello");
property.PublishValues();
var clone = (Property)property.DeepClone();
Assert.AreNotSame(clone, property);
Assert.AreNotSame(clone.Values, property.Values);
Assert.AreNotSame(property.PropertyType, clone.PropertyType);
for (var i = 0; i < property.Values.Count; i++)
{
Assert.AreNotSame(property.Values.ElementAt(i), clone.Values.ElementAt(i));
}
// This double verifies by reflection
var allProps = clone.GetType().GetProperties();
foreach (var propertyInfo in allProps)
{
Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(property, null));
}
}
private IProperty BuildProperty()
{
return _builder
.WithId(4)
.AddPropertyType()
.WithId(3)
.WithPropertyEditorAlias("TestPropertyEditor")
.WithValueStorageType(ValueStorageType.Nvarchar)
.WithAlias("test")
.WithName("Test")
.WithSortOrder(9)
.WithDataTypeId(5)
.WithDescription("testing")
.WithPropertyGroupId(11)
.WithMandatory(true)
.WithValidationRegExp("xxxx")
.Done()
.Build();
}
}
}
@@ -5,32 +5,20 @@ using System.Linq;
using System.Reflection;
using NUnit.Framework;
using Umbraco.Core.Models;
using Umbraco.Tests.Testing;
using Umbraco.Tests.Common.Builders;
using Umbraco.Tests.Common.Builders.Extensions;
namespace Umbraco.Tests.Models
namespace Umbraco.Tests.UnitTests.Umbraco.Infrastructure.Models
{
[TestFixture]
public class PropertyTypeTests : UmbracoTestBase
public class PropertyTypeTests
{
private readonly PropertyTypeBuilder _builder = new PropertyTypeBuilder();
[Test]
public void Can_Deep_Clone()
{
var pt = new PropertyType(ShortStringHelper, "TestPropertyEditor", ValueStorageType.Nvarchar, "test")
{
Id = 3,
CreateDate = DateTime.Now,
DataTypeId = 5,
PropertyEditorAlias = "propTest",
Description = "testing",
Key = Guid.NewGuid(),
Mandatory = true,
Name = "Test",
PropertyGroupId = new Lazy<int>(() => 11),
SortOrder = 9,
UpdateDate = DateTime.Now,
ValidationRegExp = "xxxx",
ValueStorageType = ValueStorageType.Nvarchar
};
var pt = BuildPropertyType();
var clone = (PropertyType)pt.DeepClone();
@@ -59,8 +47,8 @@ namespace Umbraco.Tests.Models
var actual = propertyInfo.GetValue(clone, null);
if (propertyInfo.PropertyType == typeof(Lazy<int>))
{
expected = ((Lazy<int>) expected).Value;
actual = ((Lazy<int>) actual).Value;
expected = ((Lazy<int>)expected).Value;
actual = ((Lazy<int>)actual).Value;
}
Assert.AreEqual(expected, actual, $"Value of propery: '{propertyInfo.Name}': {expected} != {actual}");
@@ -70,26 +58,27 @@ namespace Umbraco.Tests.Models
[Test]
public void Can_Serialize_Without_Error()
{
var pt = new PropertyType(ShortStringHelper, "TestPropertyEditor", ValueStorageType.Nvarchar, "test")
{
Id = 3,
CreateDate = DateTime.Now,
DataTypeId = 5,
PropertyEditorAlias = "propTest",
Description = "testing",
Key = Guid.NewGuid(),
Mandatory = true,
Name = "Test",
PropertyGroupId = new Lazy<int>(() => 11),
SortOrder = 9,
UpdateDate = DateTime.Now,
ValidationRegExp = "xxxx",
ValueStorageType = ValueStorageType.Nvarchar
};
var pt = BuildPropertyType();
var json = JsonConvert.SerializeObject(pt);
Debug.Print(json);
}
private PropertyType BuildPropertyType()
{
return _builder
.WithId(3)
.WithPropertyEditorAlias("TestPropertyEditor")
.WithValueStorageType(ValueStorageType.Nvarchar)
.WithAlias("test")
.WithName("Test")
.WithSortOrder(9)
.WithDataTypeId(5)
.WithDescription("testing")
.WithPropertyGroupId(11)
.WithMandatory(true)
.WithValidationRegExp("xxxx")
.Build();
}
}
}
@@ -0,0 +1,73 @@
using System;
using System.Diagnostics;
using Newtonsoft.Json;
using NUnit.Framework;
using Umbraco.Core.Models;
using Umbraco.Tests.Common.Builders;
using Umbraco.Tests.Common.Builders.Extensions;
namespace Umbraco.Tests.UnitTests.Umbraco.Infrastructure.Models
{
[TestFixture]
public class RelationTests
{
private readonly RelationBuilder _builder = new RelationBuilder();
[Test]
public void Can_Deep_Clone()
{
var relation = BuildRelation();
var clone = (Relation) relation.DeepClone();
Assert.AreNotSame(clone, relation);
Assert.AreEqual(clone, relation);
Assert.AreEqual(clone.ChildId, relation.ChildId);
Assert.AreEqual(clone.Comment, relation.Comment);
Assert.AreEqual(clone.CreateDate, relation.CreateDate);
Assert.AreEqual(clone.Id, relation.Id);
Assert.AreEqual(clone.Key, relation.Key);
Assert.AreEqual(clone.ParentId, relation.ParentId);
Assert.AreNotSame(clone.RelationType, relation.RelationType);
Assert.AreEqual(clone.RelationType, relation.RelationType);
Assert.AreEqual(clone.RelationTypeId, relation.RelationTypeId);
Assert.AreEqual(clone.UpdateDate, relation.UpdateDate);
//This double verifies by reflection
var allProps = clone.GetType().GetProperties();
foreach (var propertyInfo in allProps)
{
Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(relation, null));
}
}
[Test]
public void Can_Serialize_Without_Error()
{
var relation = BuildRelation();
var json = JsonConvert.SerializeObject(relation);
Debug.Print(json);
}
private Relation BuildRelation()
{
return _builder
.BetweenIds(9, 8)
.WithId(4)
.WithComment("test comment")
.WithCreateDate(DateTime.Now)
.WithUpdateDate(DateTime.Now)
.WithKey(Guid.NewGuid())
.AddRelationType()
.WithId(66)
.WithAlias("test")
.WithName("Test")
.WithIsBidirectional(false)
.WithParentObjectType(Guid.NewGuid())
.WithChildObjectType(Guid.NewGuid())
.Done()
.Build();
}
}
}
@@ -30,8 +30,7 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Infrastructure.Models
Assert.AreEqual(clone.Id, item.Id);
Assert.AreEqual(clone.Key, item.Key);
Assert.AreEqual(clone.Name, item.Name);
Assert.AreNotSame(clone.ParentObjectType, item.ParentObjectType);
Assert.AreNotSame(clone.ChildObjectType, item.ChildObjectType);
Assert.AreEqual(clone.CreateDate, item.CreateDate);
Assert.AreEqual(clone.UpdateDate, item.UpdateDate);
//This double verifies by reflection
@@ -3,26 +3,24 @@ using System.Linq;
using Newtonsoft.Json;
using NUnit.Framework;
using Umbraco.Core.Models;
using Umbraco.Core.Serialization;
using Umbraco.Tests.TestHelpers;
using Umbraco.Tests.Common.Builders;
namespace Umbraco.Tests.Models
namespace Umbraco.Tests.UnitTests.Umbraco.Infrastructure.Models
{
[TestFixture]
public class StylesheetTests
{
[SetUp]
public virtual void Initialize()
{
SettingsForTests.Reset();
}
private readonly StylesheetBuilder _builder = new StylesheetBuilder();
[Test]
public void Can_Create_Stylesheet()
{
// Arrange
var stylesheet = new Stylesheet("/css/styles.css");
stylesheet.Content = @"body { color:#000; } .bold {font-weight:bold;}";
// Act
var stylesheet = _builder
.WithPath("/css/styles.css")
.WithContent(@"body { color:#000; } .bold {font-weight:bold;}")
.Build();
// Assert
Assert.That(stylesheet.Name, Is.EqualTo("styles.css"));
@@ -33,8 +31,12 @@ namespace Umbraco.Tests.Models
public void Can_Add_Property()
{
// Arrange
var stylesheet = new Stylesheet("/css/styles.css") {Content = @"body { color:#000; } .bold {font-weight:bold;}"};
var stylesheet = _builder
.WithPath("/css/styles.css")
.WithContent(@"body { color:#000; } .bold {font-weight:bold;}")
.Build();
// Act
stylesheet.AddProperty(new StylesheetProperty("Test", "p", "font-weight:bold; font-family:Arial;"));
// Assert
@@ -48,13 +50,16 @@ namespace Umbraco.Tests.Models
public void Can_Remove_Property()
{
// Arrange
var stylesheet = new Stylesheet("/css/styles.css") { Content = @"body { color:#000; } /**umb_name:Hello*/p{font-size:2em;} .bold {font-weight:bold;}" };
var stylesheet = _builder
.WithPath("/css/styles.css")
.WithContent(@"body { color:#000; } /**umb_name:Hello*/p{font-size:2em;} .bold {font-weight:bold;}")
.Build();
Assert.AreEqual(1, stylesheet.Properties.Count());
// Act
stylesheet.RemoveProperty("Hello");
// Assert
Assert.AreEqual(0, stylesheet.Properties.Count());
Assert.AreEqual(@"body { color:#000; } .bold {font-weight:bold;}", stylesheet.Content);
}
@@ -63,17 +68,20 @@ namespace Umbraco.Tests.Models
public void Can_Update_Property()
{
// Arrange
var stylesheet = new Stylesheet("/css/styles.css")
{
Content = @"body { color:#000; } /**umb_name:Hello*/p{font-size:2em;} .bold {font-weight:bold;}"
};
var stylesheet = _builder
.WithPath("/css/styles.css")
.WithContent(@"body { color:#000; } /**umb_name:Hello*/p{font-size:2em;} .bold {font-weight:bold;}")
.Build();
// Act
var prop = stylesheet.Properties.Single();
prop.Alias = "li";
prop.Value = "font-size:5em;";
//re-get
// - re-get
prop = stylesheet.Properties.Single();
// Assert
Assert.AreEqual("li", prop.Alias);
Assert.AreEqual("font-size:5em;", prop.Value);
Assert.AreEqual("body { color:#000; } /**umb_name:Hello*/\r\nli {\r\n\tfont-size:5em;\r\n} .bold {font-weight:bold;}", stylesheet.Content);
@@ -83,12 +91,15 @@ namespace Umbraco.Tests.Models
public void Can_Get_Properties_From_Css()
{
// Arrange
var stylesheet = new Stylesheet("/css/styles.css");
stylesheet.Content = @"body { color:#000; } .bold {font-weight:bold;} /**umb_name:Hello */ p { font-size: 1em; } /**umb_name:testing123*/ li:first-child {padding:0px;}";
var stylesheet = _builder
.WithPath("/css/styles.css")
.WithContent(@"body { color:#000; } .bold {font-weight:bold;} /**umb_name:Hello */ p { font-size: 1em; } /**umb_name:testing123*/ li:first-child {padding:0px;}")
.Build();
// Act
var properties = stylesheet.Properties;
// Assert
Assert.AreEqual(2, properties.Count());
Assert.AreEqual("Hello", properties.First().Name);
Assert.AreEqual("font-size: 1em;", properties.First().Value);
@@ -102,13 +113,17 @@ namespace Umbraco.Tests.Models
[Test]
public void Can_Serialize_Without_Error()
{
var stylesheet = new Stylesheet("/css/styles.css");
stylesheet.Content = @"@media screen and (min-width: 600px) and (min-width: 900px) {
.class {
background: #666;
}
}";
// Arrange
var stylesheet = _builder
.WithPath("/css/styles.css")
.WithContent(@"@media screen and (min-width: 600px) and (min-width: 900px) {
.class {
background: #666;
}
}")
.Build();
// Act
var json = JsonConvert.SerializeObject(stylesheet);
Debug.Print(json);
}
@@ -0,0 +1,78 @@
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using Newtonsoft.Json;
using NUnit.Framework;
using Umbraco.Core.Models;
using Umbraco.Tests.Common.Builders;
using Umbraco.Tests.Common.Builders.Extensions;
namespace Umbraco.Tests.UnitTests.Umbraco.Infrastructure.Models
{
[TestFixture]
public class TemplateTests
{
private readonly TemplateBuilder _builder = new TemplateBuilder();
[Test]
public void Can_Deep_Clone()
{
var template = BuildTemplate();
var clone = (Template)template.DeepClone();
Assert.AreNotSame(clone, template);
Assert.AreEqual(clone, template);
Assert.AreEqual(clone.Path, template.Path);
Assert.AreEqual(clone.IsMasterTemplate, template.IsMasterTemplate);
Assert.AreEqual(clone.CreateDate, template.CreateDate);
Assert.AreEqual(clone.Alias, template.Alias);
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.Name, template.Name);
Assert.AreEqual(clone.UpdateDate, template.UpdateDate);
// clone.Content should be null but getting it would lazy-load
var type = clone.GetType();
var contentField = type.BaseType.GetField("_content", BindingFlags.Instance | BindingFlags.NonPublic);
var value = contentField.GetValue(clone);
Assert.IsNull(value);
// this double verifies by reflection
// need to exclude content else it would lazy-load
var allProps = clone.GetType().GetProperties();
foreach (var propertyInfo in allProps.Where(x => x.Name != "Content"))
{
Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(template, null));
}
}
[Test]
public void Can_Serialize_Without_Error()
{
var template = BuildTemplate();
var json = JsonConvert.SerializeObject(template);
Debug.Print(json);
}
private Template BuildTemplate()
{
return _builder
.WithId(3)
.WithAlias("test")
.WithName("Test")
.WithCreateDate(DateTime.Now)
.WithUpdateDate(DateTime.Now)
.WithKey(Guid.NewGuid())
.WithPath("-1,3")
.WithContent("blah")
.AsMasterTemplate("master", 88)
.Build();
}
}
}
@@ -71,6 +71,7 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Tests.Common.Builders
.WithName(testMemberTypeName)
.WithMembershipPropertyGroup()
.AddPropertyGroup()
.WithId(1)
.WithName(testMemberTypePropertyGroupName)
.WithSortOrder(1)
.AddPropertyType()
@@ -0,0 +1,42 @@
using System;
using NUnit.Framework;
using Umbraco.Tests.Common.Builders;
using Umbraco.Tests.Common.Builders.Extensions;
namespace Umbraco.Tests.UnitTests.Umbraco.Tests.Common.Builders
{
[TestFixture]
public class PropertyBuilderTests
{
[Test]
public void Is_Built_Correctly()
{
// Arrange
const int testId = 4;
var testKey = Guid.NewGuid();
var testCreateDate = DateTime.Now.AddHours(-1);
var testUpdateDate = DateTime.Now;
var testPropertyTypeId = 3;
var builder = new PropertyBuilder();
// Act
var property = builder
.WithId(testId)
.WithKey(testKey)
.WithCreateDate(testCreateDate)
.WithUpdateDate(testUpdateDate)
.AddPropertyType()
.WithId(testPropertyTypeId)
.Done()
.Build();
// Assert
Assert.AreEqual(testId, property.Id);
Assert.AreEqual(testCreateDate, property.CreateDate);
Assert.AreEqual(testUpdateDate, property.UpdateDate);
Assert.AreEqual(testKey, property.Key);
Assert.AreEqual(testPropertyTypeId, property.PropertyType.Id);
}
}
}
@@ -0,0 +1,49 @@
using System;
using NUnit.Framework;
using Umbraco.Tests.Common.Builders;
using Umbraco.Tests.Common.Builders.Extensions;
namespace Umbraco.Tests.UnitTests.Umbraco.Tests.Common.Builders
{
[TestFixture]
public class PropertyGroupBuilderTests
{
[Test]
public void Is_Built_Correctly()
{
// Arrange
const int testId = 77;
var testKey = Guid.NewGuid();
const string testName = "Group1";
const int testSortOrder = 555;
var testCreateDate = DateTime.Now.AddHours(-1);
var testUpdateDate = DateTime.Now;
const int testPropertyTypeId = 3;
var builder = new PropertyGroupBuilder();
// Act
var propertyGroup = builder
.WithId(testId)
.WithCreateDate(testCreateDate)
.WithName(testName)
.WithSortOrder(testSortOrder)
.WithKey(testKey)
.WithUpdateDate(testUpdateDate)
.AddPropertyType()
.WithId(3)
.Done()
.Build();
// Assert
Assert.AreEqual(testId, propertyGroup.Id);
Assert.AreEqual(testName, propertyGroup.Name);
Assert.AreEqual(testSortOrder, propertyGroup.SortOrder);
Assert.AreEqual(testCreateDate, propertyGroup.CreateDate);
Assert.AreEqual(testUpdateDate, propertyGroup.UpdateDate);
Assert.AreEqual(testKey, propertyGroup.Key);
Assert.AreEqual(1, propertyGroup.PropertyTypes.Count);
Assert.AreEqual(testPropertyTypeId, propertyGroup.PropertyTypes[0].Id);
}
}
}
@@ -0,0 +1,72 @@
using System;
using NUnit.Framework;
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 PropertyTypeBuilderTests
{
[Test]
public void Is_Built_Correctly()
{
// Arrange
const int testId = 3;
var testKey = Guid.NewGuid();
const string testPropertyEditorAlias = "TestPropertyEditor";
const ValueStorageType testValueStorageType = ValueStorageType.Nvarchar;
const string testAlias = "test";
const string testName = "Test";
const int testSortOrder = 9;
const int testDataTypeId = 5;
var testCreateDate = DateTime.Now.AddHours(-1);
var testUpdateDate = DateTime.Now;
const string testDescription = "testing";
const int testPropertyGroupId = 11;
const bool testMandatory = true;
const string testMandatoryMessage = "Field is required";
const string testValidationRegExp = "xxxx";
const string testValidationRegExpMessage = "Field must match pattern";
var builder = new PropertyTypeBuilder();
// Act
var propertyType = builder
.WithId(testId)
.WithPropertyEditorAlias(testPropertyEditorAlias)
.WithValueStorageType(testValueStorageType)
.WithAlias(testAlias)
.WithName(testName)
.WithSortOrder(testSortOrder)
.WithDataTypeId(testDataTypeId)
.WithCreateDate(testCreateDate)
.WithUpdateDate(testUpdateDate)
.WithDescription(testDescription)
.WithKey(testKey)
.WithPropertyGroupId(testPropertyGroupId)
.WithMandatory(testMandatory, testMandatoryMessage)
.WithValidationRegExp(testValidationRegExp, testValidationRegExpMessage)
.Build();
// Assert
Assert.AreEqual(testId, propertyType.Id);
Assert.AreEqual(testPropertyEditorAlias, propertyType.PropertyEditorAlias);
Assert.AreEqual(testValueStorageType, propertyType.ValueStorageType);
Assert.AreEqual(testAlias, propertyType.Alias);
Assert.AreEqual(testName, propertyType.Name);
Assert.AreEqual(testSortOrder, propertyType.SortOrder);
Assert.AreEqual(testDataTypeId, propertyType.DataTypeId);
Assert.AreEqual(testCreateDate, propertyType.CreateDate);
Assert.AreEqual(testUpdateDate, propertyType.UpdateDate);
Assert.AreEqual(testDescription, propertyType.Description);
Assert.AreEqual(testKey, propertyType.Key);
Assert.AreEqual(testPropertyGroupId, propertyType.PropertyGroupId.Value);
Assert.AreEqual(testMandatory, propertyType.Mandatory);
Assert.AreEqual(testMandatoryMessage, propertyType.MandatoryMessage);
Assert.AreEqual(testValidationRegExp, propertyType.ValidationRegExp);
Assert.AreEqual(testValidationRegExpMessage, propertyType.ValidationRegExpMessage);
}
}
}
@@ -0,0 +1,64 @@
using System;
using NUnit.Framework;
using Umbraco.Tests.Common.Builders;
using Umbraco.Tests.Common.Builders.Extensions;
namespace Umbraco.Tests.UnitTests.Umbraco.Tests.Common.Builders
{
[TestFixture]
public class RelationBuilderTests
{
[Test]
public void Is_Built_Correctly()
{
// Arrange
const int parentId = 9;
const int childId = 8;
const int id = 4;
var key = Guid.NewGuid();
var createDate = DateTime.Now.AddHours(-1);
var updateDate = DateTime.Now;
const string comment = "test comment";
const int relationTypeId = 66;
const string relationTypeAlias = "test";
const string relationTypeName = "name";
var parentObjectType = Guid.NewGuid();
var childObjectType = Guid.NewGuid();
var builder = new RelationBuilder();
// Act
var relation = builder
.BetweenIds(parentId, childId)
.WithId(id)
.WithComment(comment)
.WithCreateDate(createDate)
.WithUpdateDate(updateDate)
.WithKey(key)
.AddRelationType()
.WithId(relationTypeId)
.WithAlias(relationTypeAlias)
.WithName(relationTypeName)
.WithIsBidirectional(false)
.WithParentObjectType(parentObjectType)
.WithChildObjectType(childObjectType)
.Done()
.Build();
// Assert
Assert.AreEqual(parentId, relation.ParentId);
Assert.AreEqual(childId, relation.ChildId);
Assert.AreEqual(id, relation.Id);
Assert.AreEqual(createDate, relation.CreateDate);
Assert.AreEqual(updateDate, relation.UpdateDate);
Assert.AreEqual(key, relation.Key);
Assert.AreEqual(comment, relation.Comment);
Assert.AreEqual(relationTypeId, relation.RelationType.Id);
Assert.AreEqual(relationTypeAlias, relation.RelationType.Alias);
Assert.AreEqual(relationTypeName, relation.RelationType.Name);
Assert.IsFalse(relation.RelationType.IsBidirectional);
Assert.AreEqual(parentObjectType, relation.RelationType.ParentObjectType);
Assert.AreEqual(childObjectType, relation.RelationType.ChildObjectType);
}
}
}
@@ -0,0 +1,55 @@
using System;
using NUnit.Framework;
using Umbraco.Tests.Common.Builders;
using Umbraco.Tests.Common.Builders.Extensions;
namespace Umbraco.Tests.UnitTests.Umbraco.Tests.Common.Builders
{
[TestFixture]
public class RelationTypeBuilderTests
{
[Test]
public void Is_Built_Correctly()
{
// Arrange
const int id = 3;
const string alias = "test";
const string name = "Test";
var key = Guid.NewGuid();
var createDate = DateTime.Now.AddHours(-2);
var updateDate = DateTime.Now.AddHours(-1);
var deleteDate = DateTime.Now;
var parentObjectType = Guid.NewGuid();
var childObjectType = Guid.NewGuid();
const bool isBidirectional = true;
var builder = new RelationTypeBuilder();
// Act
var relationType = builder
.WithId(id)
.WithAlias(alias)
.WithName(name)
.WithKey(key)
.WithCreateDate(createDate)
.WithUpdateDate(updateDate)
.WithDeleteDate(deleteDate)
.WithParentObjectType(parentObjectType)
.WithChildObjectType(childObjectType)
.WithIsBidirectional(isBidirectional)
.Build();
// Assert
Assert.AreEqual(id, relationType.Id);
Assert.AreEqual(alias, relationType.Alias);
Assert.AreEqual(name, relationType.Name);
Assert.AreEqual(key, relationType.Key);
Assert.AreEqual(createDate, relationType.CreateDate);
Assert.AreEqual(updateDate, relationType.UpdateDate);
Assert.AreEqual(deleteDate, relationType.DeleteDate);
Assert.AreEqual(parentObjectType, relationType.ParentObjectType);
Assert.AreEqual(childObjectType, relationType.ChildObjectType);
Assert.AreEqual(isBidirectional, relationType.IsBidirectional);
}
}
}
@@ -0,0 +1,29 @@
using NUnit.Framework;
using Umbraco.Tests.Common.Builders;
namespace Umbraco.Tests.UnitTests.Umbraco.Tests.Common.Builders
{
[TestFixture]
public class StylesheetBuilderTests
{
[Test]
public void Is_Built_Correctly()
{
// Arrange
const string path = "/css/styles.css";
const string content = @"body { color:#000; } .bold {font-weight:bold;}";
var builder = new StylesheetBuilder();
// Act
var stylesheet = builder
.WithPath(path)
.WithContent(content)
.Build();
// Assert
Assert.AreEqual("\\css\\styles.css", stylesheet.Path);
Assert.AreEqual(content, stylesheet.Content);
}
}
}
@@ -0,0 +1,55 @@
using System;
using NUnit.Framework;
using Umbraco.Tests.Common.Builders;
using Umbraco.Tests.Common.Builders.Extensions;
namespace Umbraco.Tests.UnitTests.Umbraco.Tests.Common.Builders
{
[TestFixture]
public class TemplateBuilderTests
{
[Test]
public void Is_Built_Correctly()
{
// Arrange
const int id = 3;
const string alias = "test";
const string name = "Test";
var key = Guid.NewGuid();
var createDate = DateTime.Now.AddHours(-1);
var updateDate = DateTime.Now;
const string path = "-1,3";
const string content = "blah";
const string masterTemplateAlias = "master";
const int masterTemplateId = 88;
var builder = new TemplateBuilder();
// Act
var template = builder
.WithId(3)
.WithAlias(alias)
.WithName(name)
.WithCreateDate(createDate)
.WithUpdateDate(updateDate)
.WithKey(key)
.WithPath(path)
.WithContent(content)
.AsMasterTemplate(masterTemplateAlias, masterTemplateId)
.Build();
// Assert
Assert.AreEqual(id, template.Id);
Assert.AreEqual(alias, template.Alias);
Assert.AreEqual(name, template.Name);
Assert.AreEqual(createDate, template.CreateDate);
Assert.AreEqual(updateDate, template.UpdateDate);
Assert.AreEqual(key, template.Key);
Assert.AreEqual(path, template.Path);
Assert.AreEqual(content, template.Content);
Assert.IsTrue(template.IsMasterTemplate);
Assert.AreEqual(masterTemplateAlias, template.MasterTemplateAlias);
Assert.AreEqual(masterTemplateId, template.MasterTemplateId.Value);
}
}
}
@@ -1,141 +0,0 @@
using System;
using System.Diagnostics;
using Newtonsoft.Json;
using NUnit.Framework;
using Umbraco.Core.Models;
using Umbraco.Core.Serialization;
using Umbraco.Tests.Testing;
namespace Umbraco.Tests.Models
{
[TestFixture]
public class PropertyGroupTests : UmbracoTestBase
{
[Test]
public void Can_Deep_Clone()
{
var pg = new PropertyGroup(
new PropertyTypeCollection(false, new[]
{
new PropertyType(ShortStringHelper, "TestPropertyEditor", ValueStorageType.Nvarchar, "test")
{
Id = 3,
CreateDate = DateTime.Now,
DataTypeId = 5,
PropertyEditorAlias = "propTest",
Description = "testing",
Key = Guid.NewGuid(),
Mandatory = true,
Name = "Test",
PropertyGroupId = new Lazy<int>(() => 11),
SortOrder = 9,
UpdateDate = DateTime.Now,
ValidationRegExp = "xxxx",
ValueStorageType = ValueStorageType.Nvarchar
},
new PropertyType(ShortStringHelper, "TestPropertyEditor", ValueStorageType.Nvarchar, "test2")
{
Id = 4,
CreateDate = DateTime.Now,
DataTypeId = 6,
PropertyEditorAlias = "propTest",
Description = "testing2",
Key = Guid.NewGuid(),
Mandatory = true,
Name = "Test2",
PropertyGroupId = new Lazy<int>(() => 12),
SortOrder = 10,
UpdateDate = DateTime.Now,
ValidationRegExp = "yyyy",
ValueStorageType = ValueStorageType.Nvarchar
}
}))
{
Id = 77,
CreateDate = DateTime.Now,
Key = Guid.NewGuid(),
Name = "Group1",
SortOrder = 555,
UpdateDate = DateTime.Now
};
var clone = (PropertyGroup)pg.DeepClone();
Assert.AreNotSame(clone, pg);
Assert.AreEqual(clone, pg);
Assert.AreEqual(clone.Id, pg.Id);
Assert.AreEqual(clone.CreateDate, pg.CreateDate);
Assert.AreEqual(clone.Key, pg.Key);
Assert.AreEqual(clone.Name, pg.Name);
Assert.AreEqual(clone.SortOrder, pg.SortOrder);
Assert.AreEqual(clone.UpdateDate, pg.UpdateDate);
Assert.AreNotSame(clone.PropertyTypes, pg.PropertyTypes);
Assert.AreEqual(clone.PropertyTypes, pg.PropertyTypes);
Assert.AreEqual(clone.PropertyTypes.Count, pg.PropertyTypes.Count);
for (var i = 0; i < pg.PropertyTypes.Count; i++)
{
Assert.AreNotSame(clone.PropertyTypes[i], pg.PropertyTypes[i]);
Assert.AreEqual(clone.PropertyTypes[i], pg.PropertyTypes[i]);
}
//This double verifies by reflection
var allProps = clone.GetType().GetProperties();
foreach (var propertyInfo in allProps)
{
Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(pg, null));
}
}
[Test]
public void Can_Serialize_Without_Error()
{
var pg = new PropertyGroup(
new PropertyTypeCollection(false, new[]
{
new PropertyType(ShortStringHelper, "TestPropertyEditor", ValueStorageType.Nvarchar, "test")
{
Id = 3,
CreateDate = DateTime.Now,
DataTypeId = 5,
PropertyEditorAlias = "propTest",
Description = "testing",
Key = Guid.NewGuid(),
Mandatory = true,
Name = "Test",
PropertyGroupId = new Lazy<int>(() => 11),
SortOrder = 9,
UpdateDate = DateTime.Now,
ValidationRegExp = "xxxx",
ValueStorageType = ValueStorageType.Nvarchar
},
new PropertyType(ShortStringHelper, "TestPropertyEditor2", ValueStorageType.Nvarchar, "test2")
{
Id = 4,
CreateDate = DateTime.Now,
DataTypeId = 6,
PropertyEditorAlias = "propTest",
Description = "testing2",
Key = Guid.NewGuid(),
Mandatory = true,
Name = "Test2",
PropertyGroupId = new Lazy<int>(() => 12),
SortOrder = 10,
UpdateDate = DateTime.Now,
ValidationRegExp = "yyyy",
ValueStorageType = ValueStorageType.Nvarchar
}
}))
{
Id = 77,
CreateDate = DateTime.Now,
Key = Guid.NewGuid(),
Name = "Group1",
SortOrder = 555,
UpdateDate = DateTime.Now
};
var json = JsonConvert.SerializeObject(pg);
Debug.Print(json);
}
}
}
-63
View File
@@ -1,63 +0,0 @@
using System;
using System.Linq;
using NUnit.Framework;
using Umbraco.Core.Models;
using Umbraco.Tests.Testing;
namespace Umbraco.Tests.Models
{
[TestFixture]
public class PropertyTests : UmbracoTestBase
{
[Test]
public void Can_Deep_Clone()
{
// needs to be within collection to support publishing
var ptCollection = new PropertyTypeCollection(true, new[] {new PropertyType(ShortStringHelper,"TestPropertyEditor", ValueStorageType.Nvarchar, "test")
{
Id = 3,
CreateDate = DateTime.Now,
DataTypeId = 5,
PropertyEditorAlias = "propTest",
Description = "testing",
Key = Guid.NewGuid(),
Mandatory = true,
Name = "Test",
PropertyGroupId = new Lazy<int>(() => 11),
SortOrder = 9,
UpdateDate = DateTime.Now,
ValidationRegExp = "xxxx",
ValueStorageType = ValueStorageType.Nvarchar
}});
var property = new Property(123, ptCollection[0])
{
CreateDate = DateTime.Now,
Id = 4,
Key = Guid.NewGuid(),
UpdateDate = DateTime.Now
};
property.SetValue("hello");
property.PublishValues();
var clone = (Property)property.DeepClone();
Assert.AreNotSame(clone, property);
Assert.AreNotSame(clone.Values, property.Values);
Assert.AreNotSame(property.PropertyType, clone.PropertyType);
for (int i = 0; i < property.Values.Count; i++)
{
Assert.AreNotSame(property.Values.ElementAt(i), clone.Values.ElementAt(i));
}
//This double verifies by reflection
var allProps = clone.GetType().GetProperties();
foreach (var propertyInfo in allProps)
{
Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(property, null));
}
}
}
}
-70
View File
@@ -1,70 +0,0 @@
using System;
using System.Diagnostics;
using Newtonsoft.Json;
using NUnit.Framework;
using Umbraco.Core.Models;
using Umbraco.Core.Serialization;
namespace Umbraco.Tests.Models
{
[TestFixture]
public class RelationTests
{
[Test]
public void Can_Deep_Clone()
{
var item = new Relation(9, 8, new RelationType("test", "test", false, Guid.NewGuid(), Guid.NewGuid())
{
Id = 66
})
{
Comment = "test comment",
CreateDate = DateTime.Now,
Id = 4,
Key = Guid.NewGuid(),
UpdateDate = DateTime.Now
};
var clone = (Relation) item.DeepClone();
Assert.AreNotSame(clone, item);
Assert.AreEqual(clone, item);
Assert.AreEqual(clone.ChildId, item.ChildId);
Assert.AreEqual(clone.Comment, item.Comment);
Assert.AreEqual(clone.CreateDate, item.CreateDate);
Assert.AreEqual(clone.Id, item.Id);
Assert.AreEqual(clone.Key, item.Key);
Assert.AreEqual(clone.ParentId, item.ParentId);
Assert.AreNotSame(clone.RelationType, item.RelationType);
Assert.AreEqual(clone.RelationType, item.RelationType);
Assert.AreEqual(clone.RelationTypeId, item.RelationTypeId);
Assert.AreEqual(clone.UpdateDate, item.UpdateDate);
//This double verifies by reflection
var allProps = clone.GetType().GetProperties();
foreach (var propertyInfo in allProps)
{
Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(item, null));
}
}
[Test]
public void Can_Serialize_Without_Error()
{
var item = new Relation(9, 8, new RelationType("test", "test", false, Guid.NewGuid(), Guid.NewGuid())
{
Id = 66
})
{
Comment = "test comment",
CreateDate = DateTime.Now,
Id = 4,
Key = Guid.NewGuid(),
UpdateDate = DateTime.Now
};
var json = JsonConvert.SerializeObject(item);
Debug.Print(json);
}
}
}
-81
View File
@@ -1,81 +0,0 @@
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using Newtonsoft.Json;
using NUnit.Framework;
using Umbraco.Core.Models;
using Umbraco.Core.Serialization;
using Umbraco.Tests.Testing;
namespace Umbraco.Tests.Models
{
[TestFixture]
public class TemplateTests : UmbracoTestBase
{
[Test]
public void Can_Deep_Clone()
{
var item = new Template(ShortStringHelper, "Test", "test")
{
Id = 3,
CreateDate = DateTime.Now,
Key = Guid.NewGuid(),
UpdateDate = DateTime.Now,
Content = "blah",
Path = "-1,3",
IsMasterTemplate = true,
MasterTemplateAlias = "master",
MasterTemplateId = new Lazy<int>(() => 88)
};
var clone = (Template)item.DeepClone();
Assert.AreNotSame(clone, item);
Assert.AreEqual(clone, item);
Assert.AreEqual(clone.Path, item.Path);
Assert.AreEqual(clone.IsMasterTemplate, item.IsMasterTemplate);
Assert.AreEqual(clone.CreateDate, item.CreateDate);
Assert.AreEqual(clone.Alias, item.Alias);
Assert.AreEqual(clone.Id, item.Id);
Assert.AreEqual(clone.Key, item.Key);
Assert.AreEqual(clone.MasterTemplateAlias, item.MasterTemplateAlias);
Assert.AreEqual(clone.MasterTemplateId.Value, item.MasterTemplateId.Value);
Assert.AreEqual(clone.Name, item.Name);
Assert.AreEqual(clone.UpdateDate, item.UpdateDate);
// clone.Content should be null but getting it would lazy-load
var type = clone.GetType();
var contentField = type.BaseType.GetField("_content", BindingFlags.Instance | BindingFlags.NonPublic);
var value = contentField.GetValue(clone);
Assert.IsNull(value);
// this double verifies by reflection
// need to exclude content else it would lazy-load
var allProps = clone.GetType().GetProperties();
foreach (var propertyInfo in allProps.Where(x => x.Name != "Content"))
{
Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(item, null));
}
}
[Test]
public void Can_Serialize_Without_Error()
{
var item = new Template(ShortStringHelper, "Test", "test")
{
Id = 3,
CreateDate = DateTime.Now,
Key = Guid.NewGuid(),
UpdateDate = DateTime.Now,
Content = "blah",
MasterTemplateAlias = "master",
MasterTemplateId = new Lazy<int>(() => 88)
};
var json = JsonConvert.SerializeObject(item);
Debug.Print(json);
}
}
}
-6
View File
@@ -143,7 +143,6 @@
<Compile Include="Models\CultureImpactTests.cs" />
<Compile Include="Models\ImageProcessorImageUrlGeneratorTest.cs" />
<Compile Include="Models\PathValidationTests.cs" />
<Compile Include="Models\PropertyTests.cs" />
<Compile Include="Models\VariationTests.cs" />
<Compile Include="Persistence\Mappers\MapperTestBase.cs" />
<Compile Include="Persistence\Repositories\DocumentRepositoryTest.cs" />
@@ -297,10 +296,6 @@
<Compile Include="Models\ContentTypeTests.cs" />
<Compile Include="Models\DeepCloneHelperTests.cs" />
<Compile Include="Models\DictionaryTranslationTests.cs" />
<Compile Include="Models\PropertyGroupTests.cs" />
<Compile Include="Models\PropertyTypeTests.cs" />
<Compile Include="Models\RelationTests.cs" />
<Compile Include="Models\TemplateTests.cs" />
<Compile Include="Models\LightEntityTest.cs" />
<Compile Include="Models\UserTests.cs" />
<Compile Include="Web\Mvc\RenderModelBinderTests.cs" />
@@ -402,7 +397,6 @@
<Compile Include="PropertyEditors\PropertyEditorValueConverterTests.cs" />
<Compile Include="Models\ContentTests.cs" />
<Compile Include="Models\ContentXmlTest.cs" />
<Compile Include="Models\StylesheetTests.cs" />
<Compile Include="Persistence\SqlCeTableByTableTest.cs" />
<Compile Include="Persistence\DatabaseContextTests.cs" />
<Compile Include="Persistence\Mappers\ContentMapperTest.cs" />