Migrated property, property type and property group tests into new project and builder pattern.
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace Umbraco.Tests.Common.Builders
|
||||
{
|
||||
public class MemberTypeBuilder
|
||||
: ChildBuilderBase<MemberBuilder, MemberType>,
|
||||
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,9 +92,9 @@ 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;
|
||||
}
|
||||
|
||||
@@ -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<Property>,
|
||||
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 Property 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,101 @@
|
||||
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)
|
||||
.WithCreateDate(DateTime.Now)
|
||||
.WithName("Group1")
|
||||
.WithSortOrder(555)
|
||||
.WithKey(Guid.NewGuid())
|
||||
.WithUpdateDate(DateTime.Now)
|
||||
.AddPropertyType()
|
||||
.WithId(3)
|
||||
.WithPropertyEditorAlias("TestPropertyEditor")
|
||||
.WithValueStorageType(ValueStorageType.Nvarchar)
|
||||
.WithAlias("test")
|
||||
.WithName("Test")
|
||||
.WithSortOrder(9)
|
||||
.WithDataTypeId(5)
|
||||
.WithCreateDate(DateTime.Now)
|
||||
.WithUpdateDate(DateTime.Now)
|
||||
.WithDescription("testing")
|
||||
.WithKey(Guid.NewGuid())
|
||||
.WithPropertyGroupId(11)
|
||||
.WithMandatory(true)
|
||||
.WithValidationRegExp("xxxx")
|
||||
.Done()
|
||||
.AddPropertyType()
|
||||
.WithId(4)
|
||||
.WithPropertyEditorAlias("TestPropertyEditor2")
|
||||
.WithValueStorageType(ValueStorageType.Nvarchar)
|
||||
.WithAlias("test2")
|
||||
.WithName("Test2")
|
||||
.WithSortOrder(10)
|
||||
.WithDataTypeId(6)
|
||||
.WithCreateDate(DateTime.Now)
|
||||
.WithUpdateDate(DateTime.Now)
|
||||
.WithDescription("testing2")
|
||||
.WithKey(Guid.NewGuid())
|
||||
.WithPropertyGroupId(12)
|
||||
.WithMandatory(true)
|
||||
.WithValidationRegExp("yyyy")
|
||||
.Done()
|
||||
.Build();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
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 Property BuildProperty()
|
||||
{
|
||||
return _builder
|
||||
.WithId(4)
|
||||
.WithKey(Guid.NewGuid())
|
||||
.WithCreateDate(DateTime.Now)
|
||||
.WithUpdateDate(DateTime.Now)
|
||||
.AddPropertyType()
|
||||
.WithId(3)
|
||||
.WithPropertyEditorAlias("TestPropertyEditor")
|
||||
.WithValueStorageType(ValueStorageType.Nvarchar)
|
||||
.WithAlias("test")
|
||||
.WithName("Test")
|
||||
.WithSortOrder(9)
|
||||
.WithDataTypeId(5)
|
||||
.WithCreateDate(DateTime.Now)
|
||||
.WithUpdateDate(DateTime.Now)
|
||||
.WithDescription("testing")
|
||||
.WithKey(Guid.NewGuid())
|
||||
.WithPropertyGroupId(11)
|
||||
.WithMandatory(true)
|
||||
.WithValidationRegExp("xxxx")
|
||||
.Done()
|
||||
.Build();
|
||||
}
|
||||
}
|
||||
}
|
||||
+29
-37
@@ -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,30 @@ 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)
|
||||
.WithCreateDate(DateTime.Now)
|
||||
.WithUpdateDate(DateTime.Now)
|
||||
.WithDescription("testing")
|
||||
.WithKey(Guid.NewGuid())
|
||||
.WithPropertyGroupId(11)
|
||||
.WithMandatory(true)
|
||||
.WithValidationRegExp("xxxx")
|
||||
.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
+49
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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,8 +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" />
|
||||
|
||||
Reference in New Issue
Block a user