Merge pull request #7855 from AndyButland/netcore/unit-test-migration-member-models

Netcore: Migrated member unit tests into new project/builder pattern
This commit is contained in:
Bjarke Berg
2020-04-01 06:33:09 +02:00
committed by GitHub
30 changed files with 1387 additions and 205 deletions

View File

@@ -9,7 +9,6 @@ namespace Umbraco.Tests.Common.Builders
_parentBuilder = parentBuilder;
}
public TParent Done()
{
return _parentBuilder;

View File

@@ -21,7 +21,7 @@ namespace Umbraco.Tests.Common.Builders
public override IConfigurationEditor Build()
{
var defaultConfiguration = _defaultConfiguration ?? new Dictionary<string, object>();
var defaultConfiguration = _defaultConfiguration ?? new Dictionary<string, object>();
return new ConfigurationEditor()
{

View File

@@ -8,10 +8,16 @@ namespace Umbraco.Tests.Common.Builders
: BuilderBase<DataType>,
IWithIdBuilder,
IWithKeyBuilder,
IWithCreatorIdBuilder,
IWithCreateDateBuilder,
IWithUpdateDateBuilder,
IWithDeleteDateBuilder,
IWithNameBuilder
IWithNameBuilder,
IWithParentIdBuilder,
IWithTrashedBuilder,
IWithLevelBuilder,
IWithPathBuilder,
IWithSortOrderBuilder
{
private readonly DataEditorBuilder<DataTypeBuilder> _dataEditorBuilder;
private int? _id;
@@ -34,54 +40,18 @@ namespace Umbraco.Tests.Common.Builders
_dataEditorBuilder = new DataEditorBuilder<DataTypeBuilder>(this);
}
public DataTypeBuilder WithParentId(int parentId)
{
_parentId = parentId;
return this;
}
public DataTypeBuilder WithTrashed(bool trashed)
{
_trashed = trashed;
return this;
}
// public DataTypeBuilder WithConfiguration(object configuration)
// {
// _configuration = configuration;
// return this;
// }
public DataTypeBuilder WithLevel(int level)
{
_level = level;
return this;
}
public DataTypeBuilder WithPath(string path)
{
_path = path;
return this;
}
public DataTypeBuilder WithCreatorId(int creatorId)
{
_creatorId = creatorId;
return this;
}
public DataTypeBuilder WithDatabaseType(ValueStorageType databaseType)
{
_databaseType = databaseType;
return this;
}
public DataTypeBuilder WithSortOrder(int sortOrder)
{
_sortOrder = sortOrder;
return this;
}
public DataEditorBuilder<DataTypeBuilder> AddEditor()
{
return _dataEditorBuilder;
@@ -133,6 +103,12 @@ namespace Umbraco.Tests.Common.Builders
set => _key = value;
}
int? IWithCreatorIdBuilder.CreatorId
{
get => _creatorId;
set => _creatorId = value;
}
DateTime? IWithCreateDateBuilder.CreateDate
{
get => _createDate;
@@ -156,5 +132,35 @@ namespace Umbraco.Tests.Common.Builders
get => _name;
set => _name = value;
}
int? IWithParentIdBuilder.ParentId
{
get => _parentId;
set => _parentId = 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;
}
}
}

View File

@@ -21,7 +21,6 @@ namespace Umbraco.Tests.Common.Builders
private DateTime? _updateDate;
private string _value;
public DictionaryTranslationBuilder(DictionaryItemBuilder parentBuilder) : base(parentBuilder)
{
_languageBuilder = new LanguageBuilder<DictionaryTranslationBuilder>(this);

View File

@@ -12,6 +12,13 @@ namespace Umbraco.Tests.Common.Builders.Extensions
return builder;
}
public static T WithCreatorId<T>(this T builder, int creatorId)
where T : IWithCreatorIdBuilder
{
builder.CreatorId = creatorId;
return builder;
}
public static T WithCreateDate<T>(this T builder, DateTime createDate)
where T : IWithCreateDateBuilder
{
@@ -46,5 +53,61 @@ namespace Umbraco.Tests.Common.Builders.Extensions
builder.Key = key;
return builder;
}
public static T WithParentId<T>(this T builder, int parentId)
where T : IWithParentIdBuilder
{
builder.ParentId = parentId;
return builder;
}
public static T WithTrashed<T>(this T builder, bool trashed)
where T : IWithTrashedBuilder
{
builder.Trashed = trashed;
return builder;
}
public static T WithLevel<T>(this T builder, int level)
where T : IWithLevelBuilder
{
builder.Level = level;
return builder;
}
public static T WithPath<T>(this T builder, string path)
where T : IWithPathBuilder
{
builder.Path = path;
return builder;
}
public static T WithSortOrder<T>(this T builder, int sortOrder)
where T : IWithSortOrderBuilder
{
builder.SortOrder = sortOrder;
return builder;
}
public static T WithDescription<T>(this T builder, string description)
where T : IWithDescriptionBuilder
{
builder.Description = description;
return builder;
}
public static T WithIcon<T>(this T builder, string icon)
where T : IWithIconBuilder
{
builder.Icon = icon;
return builder;
}
public static T WithThumbnail<T>(this T builder, string thumbnail)
where T : IWithThumbnailBuilder
{
builder.Thumbnail = thumbnail;
return builder;
}
}
}

View File

@@ -0,0 +1,20 @@
namespace Umbraco.Tests.Common.Builders.Extensions
{
public static class StringExtensions
{
public static string ToCamelCase(this string s)
{
if (string.IsNullOrWhiteSpace(s))
{
return string.Empty;
}
if (s.Length == 1)
{
return s.ToLowerInvariant();
}
return char.ToLowerInvariant(s[0]) + s.Substring(1);
}
}
}

View File

@@ -0,0 +1,26 @@
using System.Collections.Generic;
namespace Umbraco.Tests.Common.Builders
{
public class GenericCollectionBuilder<TBuilder, T>
: ChildBuilderBase<TBuilder, IEnumerable<T>>
{
private readonly IList<T> _collection;
public GenericCollectionBuilder(TBuilder parentBuilder) : base(parentBuilder)
{
_collection = new List<T>();
}
public override IEnumerable<T> Build()
{
return _collection;
}
public GenericCollectionBuilder<TBuilder, T> WithValue(T value)
{
_collection.Add(value);
return this;
}
}
}

View File

@@ -0,0 +1,26 @@
using System.Collections.Generic;
namespace Umbraco.Tests.Common.Builders
{
public class GenericDictionaryBuilder<TBuilder, TKey, TValue>
: ChildBuilderBase<TBuilder, IDictionary<TKey, TValue>>
{
private readonly IDictionary<TKey, TValue> _dictionary;
public GenericDictionaryBuilder(TBuilder parentBuilder) : base(parentBuilder)
{
_dictionary = new Dictionary<TKey, TValue>();
}
public override IDictionary<TKey, TValue> Build()
{
return _dictionary;
}
public GenericDictionaryBuilder<TBuilder, TKey, TValue> WithKeyValue(TKey key, TValue value)
{
_dictionary.Add(key, value);
return this;
}
}
}

View File

@@ -0,0 +1,9 @@
using System;
namespace Umbraco.Tests.Common.Builders.Interfaces
{
public interface IWithCreatorIdBuilder
{
int? CreatorId { get; set; }
}
}

View File

@@ -0,0 +1,7 @@
namespace Umbraco.Tests.Common.Builders.Interfaces
{
public interface IWithDescriptionBuilder
{
string Description { get; set; }
}
}

View File

@@ -0,0 +1,7 @@
namespace Umbraco.Tests.Common.Builders.Interfaces
{
public interface IWithIconBuilder
{
string Icon { get; set; }
}
}

View File

@@ -0,0 +1,7 @@
namespace Umbraco.Tests.Common.Builders.Interfaces
{
public interface IWithLevelBuilder
{
int? Level { get; set; }
}
}

View File

@@ -0,0 +1,7 @@
namespace Umbraco.Tests.Common.Builders.Interfaces
{
public interface IWithParentIdBuilder
{
int? ParentId { get; set; }
}
}

View File

@@ -0,0 +1,7 @@
namespace Umbraco.Tests.Common.Builders.Interfaces
{
public interface IWithPathBuilder
{
string Path { get; set; }
}
}

View File

@@ -0,0 +1,7 @@
namespace Umbraco.Tests.Common.Builders.Interfaces
{
public interface IWithSortOrderBuilder
{
int? SortOrder { get; set; }
}
}

View File

@@ -0,0 +1,7 @@
namespace Umbraco.Tests.Common.Builders.Interfaces
{
public interface IWithThumbnailBuilder
{
string Thumbnail { get; set; }
}
}

View File

@@ -0,0 +1,7 @@
namespace Umbraco.Tests.Common.Builders.Interfaces
{
public interface IWithTrashedBuilder
{
bool? Trashed { get; set; }
}
}

View File

@@ -0,0 +1,280 @@
using System;
using Umbraco.Core.Models;
using Umbraco.Tests.Common.Builders.Interfaces;
namespace Umbraco.Tests.Common.Builders
{
public class MemberBuilder
: BuilderBase<Member>,
IWithIdBuilder,
IWithKeyBuilder,
IWithCreatorIdBuilder,
IWithCreateDateBuilder,
IWithUpdateDateBuilder,
IWithNameBuilder,
IWithTrashedBuilder,
IWithLevelBuilder,
IWithPathBuilder,
IWithSortOrderBuilder
{
private MemberTypeBuilder _memberTypeBuilder;
private GenericCollectionBuilder<MemberBuilder, string> _memberGroupsBuilder;
private GenericDictionaryBuilder<MemberBuilder, string, object> _additionalDataBuilder;
private GenericDictionaryBuilder<MemberBuilder, string, object> _propertyDataBuilder;
private int? _id;
private Guid? _key;
private DateTime? _createDate;
private DateTime? _updateDate;
private string _name;
private int? _creatorId;
private string _username;
private string _rawPasswordValue;
private string _email;
private int? _failedPasswordAttempts;
private int? _level;
private string _path;
private bool? _isApproved;
private bool? _isLockedOut;
private DateTime? _lastLockoutDate;
private DateTime? _lastLoginDate;
private DateTime? _lastPasswordChangeDate;
private int? _sortOrder;
private bool? _trashed;
private int? _propertyIdsIncrementingFrom;
public MemberBuilder WithUserName(string username)
{
_username = username;
return this;
}
public MemberBuilder WithEmail(string email)
{
_email = email;
return this;
}
public MemberBuilder WithRawPasswordValue(string rawPasswordValue)
{
_rawPasswordValue = rawPasswordValue;
return this;
}
public MemberBuilder WithFailedPasswordAttempts(int failedPasswordAttempts)
{
_failedPasswordAttempts = failedPasswordAttempts;
return this;
}
public MemberBuilder WithIsApproved(bool isApproved)
{
_isApproved = isApproved;
return this;
}
public MemberBuilder WithIsLockedOut(bool isLockedOut)
{
_isLockedOut = isLockedOut;
return this;
}
public MemberBuilder WithLastLockoutDate(DateTime lastLockoutDate)
{
_lastLockoutDate = lastLockoutDate;
return this;
}
public MemberBuilder WithLastLoginDate(DateTime lastLoginDate)
{
_lastLoginDate = lastLoginDate;
return this;
}
public MemberBuilder WithLastPasswordChangeDate(DateTime lastPasswordChangeDate)
{
_lastPasswordChangeDate = lastPasswordChangeDate;
return this;
}
public MemberBuilder WithPropertyIdsIncrementingFrom(int propertyIdsIncrementingFrom)
{
_propertyIdsIncrementingFrom = propertyIdsIncrementingFrom;
return this;
}
public MemberTypeBuilder AddMemberType()
{
var builder = new MemberTypeBuilder(this);
_memberTypeBuilder = builder;
return builder;
}
public GenericCollectionBuilder<MemberBuilder, string> AddMemberGroups()
{
var builder = new GenericCollectionBuilder<MemberBuilder, string>(this);
_memberGroupsBuilder = builder;
return builder;
}
public GenericDictionaryBuilder<MemberBuilder, string, object> AddAdditionalData()
{
var builder = new GenericDictionaryBuilder<MemberBuilder, string, object>(this);
_additionalDataBuilder = builder;
return builder;
}
public GenericDictionaryBuilder<MemberBuilder, string, object> AddPropertyData()
{
var builder = new GenericDictionaryBuilder<MemberBuilder, string, object>(this);
_propertyDataBuilder = builder;
return builder;
}
public override Member 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 creatorId = _creatorId ?? 1;
var username = _username ?? string.Empty;
var email = _email ?? string.Empty;
var rawPasswordValue = _rawPasswordValue ?? string.Empty;
var failedPasswordAttempts = _failedPasswordAttempts ?? 0;
var level = _level ?? 1;
var path = _path ?? "-1";
var isApproved = _isApproved ?? false;
var isLockedOut = _isLockedOut ?? false;
var lastLockoutDate = _lastLockoutDate ?? DateTime.Now;
var lastLoginDate = _lastLoginDate ?? DateTime.Now;
var lastPasswordChangeDate = _lastPasswordChangeDate ?? DateTime.Now;
var sortOrder = _sortOrder ?? 0;
var trashed = _trashed ?? false;
if (_memberTypeBuilder == null)
{
throw new InvalidOperationException("A member cannot be constructed without providing a member type (use AddMemberType).");
}
var memberType = _memberTypeBuilder.Build();
var member = new Member(name, email, username, rawPasswordValue, memberType)
{
Id = id,
Key = key,
CreateDate = createDate,
UpdateDate = updateDate,
CreatorId = creatorId,
Level = level,
Path = path,
SortOrder = sortOrder,
Trashed = trashed,
};
if (_propertyIdsIncrementingFrom.HasValue)
{
var i = _propertyIdsIncrementingFrom.Value;
foreach (var property in member.Properties)
{
property.Id = ++i;
}
}
member.FailedPasswordAttempts = failedPasswordAttempts;
member.IsApproved = isApproved;
member.IsLockedOut = isLockedOut;
member.LastLockoutDate = lastLockoutDate;
member.LastLoginDate = lastLoginDate;
member.LastPasswordChangeDate = lastPasswordChangeDate;
if (_memberGroupsBuilder != null)
{
member.Groups = _memberGroupsBuilder.Build();
}
if (_additionalDataBuilder != null)
{
var additionalData = _additionalDataBuilder.Build();
foreach (var kvp in additionalData)
{
member.AdditionalData.Add(kvp.Key, kvp.Value);
}
}
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;
}
}
}

View File

@@ -0,0 +1,99 @@
using System;
using Umbraco.Core.Models;
using Umbraco.Tests.Common.Builders.Interfaces;
namespace Umbraco.Tests.Common.Builders
{
public class MemberGroupBuilder
: BuilderBase<MemberGroup>,
IWithIdBuilder,
IWithKeyBuilder,
IWithCreatorIdBuilder,
IWithCreateDateBuilder,
IWithUpdateDateBuilder,
IWithNameBuilder
{
private GenericDictionaryBuilder<MemberGroupBuilder, string, object> _additionalDataBuilder;
private int? _id;
private Guid? _key;
private DateTime? _createDate;
private DateTime? _updateDate;
private string _name;
private int? _creatorId;
public GenericDictionaryBuilder<MemberGroupBuilder, string, object> AddAdditionalData()
{
var builder = new GenericDictionaryBuilder<MemberGroupBuilder, string, object>(this);
_additionalDataBuilder = builder;
return builder;
}
public override MemberGroup 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 creatorId = _creatorId ?? 1;
var memberGroup = new MemberGroup
{
Id = id,
Key = key,
CreateDate = createDate,
UpdateDate = updateDate,
Name = name,
CreatorId = creatorId,
};
if (_additionalDataBuilder != null)
{
var additionalData = _additionalDataBuilder.Build();
foreach (var kvp in additionalData)
{
memberGroup.AdditionalData.Add(kvp.Key, kvp.Value);
}
}
return memberGroup;
}
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;
}
}
}

View File

@@ -0,0 +1,198 @@
using System;
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, MemberType>,
IWithIdBuilder,
IWithAliasBuilder,
IWithNameBuilder,
IWithParentIdBuilder,
IWithSortOrderBuilder,
IWithCreatorIdBuilder,
IWithDescriptionBuilder,
IWithIconBuilder,
IWithThumbnailBuilder,
IWithTrashedBuilder
{
private readonly List<PropertyGroupBuilder> _propertyGroupBuilders = new List<PropertyGroupBuilder>();
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(MemberBuilder parentBuilder) : base(parentBuilder)
{
}
public MemberTypeBuilder WithMembershipPropertyGroup()
{
var builder = new PropertyGroupBuilder(this)
.WithName(Constants.Conventions.Member.StandardPropertiesGroupName)
.WithSortOrder(1)
.AddPropertyType()
.WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.TextArea)
.WithValueStorageType(ValueStorageType.Ntext)
.WithAlias(Constants.Conventions.Member.Comments)
.WithName(Constants.Conventions.Member.CommentsLabel)
.Done()
.AddPropertyType()
.WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.Boolean)
.WithValueStorageType(ValueStorageType.Integer)
.WithAlias(Constants.Conventions.Member.IsApproved)
.WithName(Constants.Conventions.Member.IsApprovedLabel)
.Done()
.AddPropertyType()
.WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.Boolean)
.WithValueStorageType(ValueStorageType.Integer)
.WithAlias(Constants.Conventions.Member.IsLockedOut)
.WithName(Constants.Conventions.Member.IsLockedOutLabel)
.Done()
.AddPropertyType()
.WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.Label)
.WithValueStorageType(ValueStorageType.Date)
.WithAlias(Constants.Conventions.Member.LastLoginDate)
.WithName(Constants.Conventions.Member.LastLoginDateLabel)
.Done()
.AddPropertyType()
.WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.Label)
.WithValueStorageType(ValueStorageType.Date)
.WithAlias(Constants.Conventions.Member.LastPasswordChangeDate)
.WithName(Constants.Conventions.Member.LastPasswordChangeDateLabel)
.Done()
.AddPropertyType()
.WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.Label)
.WithValueStorageType(ValueStorageType.Date)
.WithAlias(Constants.Conventions.Member.LastLockoutDate)
.WithName(Constants.Conventions.Member.LastLockoutDateLabel)
.Done()
.AddPropertyType()
.WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.Label)
.WithValueStorageType(ValueStorageType.Integer)
.WithAlias(Constants.Conventions.Member.FailedPasswordAttempts)
.WithName(Constants.Conventions.Member.FailedPasswordAttemptsLabel)
.Done();
_propertyGroupBuilders.Add(builder);
return this;
}
public PropertyGroupBuilder AddPropertyGroup()
{
var builder = new PropertyGroupBuilder(this);
_propertyGroupBuilders.Add(builder);
return builder;
}
public override MemberType 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)
{
Id = id,
Alias = alias,
Name = name,
SortOrder = sortOrder,
Description = description,
Icon = icon,
Thumbnail = thumbnail,
CreatorId = creatorId,
Trashed = trashed,
};
foreach (var propertyGroup in _propertyGroupBuilders.Select(x => x.Build()))
{
memberType.PropertyGroups.Add(propertyGroup);
}
memberType.ResetDirtyProperties(false);
return memberType;
}
int? IWithIdBuilder.Id
{
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;
}
}
}

View File

@@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core.Models;
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
{
private readonly List<PropertyTypeBuilder> _propertyTypeBuilders = new List<PropertyTypeBuilder>();
private string _name;
private int? _sortOrder;
public PropertyGroupBuilder(MemberTypeBuilder parentBuilder) : base(parentBuilder)
{
}
public PropertyTypeBuilder AddPropertyType()
{
var builder = new PropertyTypeBuilder(this);
_propertyTypeBuilders.Add(builder);
return builder;
}
public override PropertyGroup Build()
{
var name = _name ?? Guid.NewGuid().ToString();
var sortOrder = _sortOrder ?? 0;
var properties = new PropertyTypeCollection(false);
foreach (var propertyType in _propertyTypeBuilders.Select(x => x.Build()))
{
properties.Add(propertyType);
}
return new PropertyGroup(properties)
{
Name = name,
SortOrder = sortOrder,
};
}
string IWithNameBuilder.Name
{
get => _name;
set => _name = value;
}
int? IWithSortOrderBuilder.SortOrder
{
get => _sortOrder;
set => _sortOrder = value;
}
}
}

View File

@@ -0,0 +1,93 @@
using System;
using Moq;
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 PropertyTypeBuilder
: ChildBuilderBase<PropertyGroupBuilder, PropertyType>,
IWithAliasBuilder,
IWithNameBuilder,
IWithSortOrderBuilder,
IWithDescriptionBuilder
{
private string _propertyEditorAlias;
private ValueStorageType? _valueStorageType;
private string _alias;
private string _name;
private int? _sortOrder;
private string _description;
private int? _dataTypeId;
public PropertyTypeBuilder(PropertyGroupBuilder parentBuilder) : base(parentBuilder)
{
}
public PropertyTypeBuilder WithPropertyEditorAlias(string propertyEditorAlias)
{
_propertyEditorAlias = propertyEditorAlias;
return this;
}
public PropertyTypeBuilder WithValueStorageType(ValueStorageType valueStorageType)
{
_valueStorageType = valueStorageType;
return this;
}
public PropertyTypeBuilder WithDataTypeId(int dataTypeId)
{
_dataTypeId = dataTypeId;
return this;
}
public override PropertyType Build()
{
var propertyEditorAlias = _propertyEditorAlias ?? Guid.NewGuid().ToString().ToCamelCase();
var valueStorageType = _valueStorageType ?? ValueStorageType.Ntext;
var name = _name ?? Guid.NewGuid().ToString();
var alias = _alias ?? name.ToCamelCase();
var sortOrder = _sortOrder ?? 0;
var dataTypeId = _dataTypeId ?? 0;
var description = _description ?? string.Empty;
var shortStringHelper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig());
return new PropertyType(shortStringHelper, propertyEditorAlias, valueStorageType)
{
Alias = alias,
Name = name,
SortOrder = sortOrder,
DataTypeId = dataTypeId,
Description = description,
};
}
string IWithAliasBuilder.Alias
{
get => _alias;
set => _alias = value;
}
string IWithNameBuilder.Name
{
get => _name;
set => _name = value;
}
int? IWithSortOrderBuilder.SortOrder
{
get => _sortOrder;
set => _sortOrder = value;
}
string IWithDescriptionBuilder.Description
{
get => _description;
set => _description = value;
}
}
}

View File

@@ -4,18 +4,17 @@ 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 DataTypeTests
{
private readonly DataTypeBuilder _builder = new DataTypeBuilder();
[Test]
public void Can_Deep_Clone()
{
var dtd = _builder
var dtd = _builder
.WithId(3123)
.Build();

View File

@@ -3,28 +3,21 @@ using System.Diagnostics;
using Newtonsoft.Json;
using NUnit.Framework;
using Umbraco.Core.Models;
using Umbraco.Core.Serialization;
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 MemberGroupTests
{
private readonly MemberGroupBuilder _builder = new MemberGroupBuilder();
[Test]
public void Can_Deep_Clone()
{
// Arrange
var group = new MemberGroup()
{
CreateDate = DateTime.Now,
CreatorId = 4,
Id = 6,
Key = Guid.NewGuid(),
UpdateDate = DateTime.Now,
Name = "asdf"
};
group.AdditionalData.Add("test1", 123);
group.AdditionalData.Add("test2", "hello");
var group = BuildMemberGroup();
// Act
var clone = (MemberGroup)group.DeepClone();
@@ -44,29 +37,32 @@ namespace Umbraco.Tests.Models
//This double verifies by reflection
var allProps = clone.GetType().GetProperties();
foreach (var propertyInfo in allProps)
{
Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(group, null));
}
}
[Test]
public void Can_Serialize_Without_Error()
{
var group = new MemberGroup()
{
CreateDate = DateTime.Now,
CreatorId = 4,
Id = 6,
Key = Guid.NewGuid(),
UpdateDate = DateTime.Now,
Name = "asdf"
};
group.AdditionalData.Add("test1", 123);
group.AdditionalData.Add("test2", "hello");
var group = BuildMemberGroup();
var json = JsonConvert.SerializeObject(group);
Debug.Print(json);
}
private MemberGroup BuildMemberGroup()
{
return _builder
.WithId(6)
.WithKey(Guid.NewGuid())
.WithName("Test Group")
.WithCreatorId(4)
.WithCreateDate(DateTime.Now)
.WithUpdateDate(DateTime.Now)
.AddAdditionalData()
.WithKeyValue("test1", 123)
.WithKeyValue("test2", "hello")
.Done()
.Build();
}
}
}

View File

@@ -0,0 +1,151 @@
using System;
using System.Diagnostics;
using System.Linq;
using Newtonsoft.Json;
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.Infrastructure.Models
{
[TestFixture]
public class MemberTests
{
private readonly MemberBuilder _builder = new MemberBuilder();
[Test]
public void Can_Deep_Clone()
{
// Arrange
var member = BuildMember();
// Act
var clone = (Member)member.DeepClone();
// Assert
Assert.AreNotSame(clone, member);
Assert.AreEqual(clone, member);
Assert.AreEqual(clone.Id, member.Id);
Assert.AreEqual(clone.VersionId, member.VersionId);
Assert.AreEqual(clone.AdditionalData, member.AdditionalData);
Assert.AreEqual(clone.ContentType, member.ContentType);
Assert.AreEqual(clone.ContentTypeId, member.ContentTypeId);
Assert.AreEqual(clone.CreateDate, member.CreateDate);
Assert.AreEqual(clone.CreatorId, member.CreatorId);
Assert.AreEqual(clone.Comments, member.Comments);
Assert.AreEqual(clone.Key, member.Key);
Assert.AreEqual(clone.FailedPasswordAttempts, member.FailedPasswordAttempts);
Assert.AreEqual(clone.Level, member.Level);
Assert.AreEqual(clone.Path, member.Path);
Assert.AreEqual(clone.Groups, member.Groups);
Assert.AreEqual(clone.Groups.Count(), member.Groups.Count());
Assert.AreEqual(clone.IsApproved, member.IsApproved);
Assert.AreEqual(clone.IsLockedOut, member.IsLockedOut);
Assert.AreEqual(clone.SortOrder, member.SortOrder);
Assert.AreEqual(clone.LastLockoutDate, member.LastLockoutDate);
Assert.AreNotSame(clone.LastLoginDate, member.LastLoginDate);
Assert.AreEqual(clone.LastPasswordChangeDate, member.LastPasswordChangeDate);
Assert.AreEqual(clone.Trashed, member.Trashed);
Assert.AreEqual(clone.UpdateDate, member.UpdateDate);
Assert.AreEqual(clone.VersionId, member.VersionId);
Assert.AreEqual(clone.RawPasswordValue, member.RawPasswordValue);
Assert.AreNotSame(clone.Properties, member.Properties);
Assert.AreEqual(clone.Properties.Count(), member.Properties.Count());
for (var index = 0; index < member.Properties.Count; index++)
{
Assert.AreNotSame(clone.Properties[index], member.Properties[index]);
Assert.AreEqual(clone.Properties[index], member.Properties[index]);
}
// this can be the same, it is immutable
Assert.AreSame(clone.ContentType, member.ContentType);
//This double verifies by reflection
var allProps = clone.GetType().GetProperties();
foreach (var propertyInfo in allProps)
Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(member, null));
}
[Test]
public void Can_Serialize_Without_Error()
{
var member = BuildMember();
var json = JsonConvert.SerializeObject(member);
Debug.Print(json);
}
private Member BuildMember()
{
return _builder
.AddMemberType()
.WithId(99)
.WithAlias("memberType")
.WithName("Member Type")
.WithMembershipPropertyGroup()
.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()
.AddPropertyType()
.WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.TextBox)
.WithValueStorageType(ValueStorageType.Nvarchar)
.WithAlias("author")
.WithName("Author")
.WithDescription("Name of the author")
.WithSortOrder(3)
.WithDataTypeId(-88)
.Done()
.Done()
.Done()
.WithId(10)
.WithKey(Guid.NewGuid())
.WithName("Fred")
.WithUserName("fred")
.WithRawPasswordValue("raw pass")
.WithEmail("email@email.com")
.WithCreatorId(22)
.WithCreateDate(DateTime.Now)
.WithUpdateDate(DateTime.Now)
.WithFailedPasswordAttempts(22)
.WithLevel(3)
.WithPath("-1, 4, 10")
.WithIsApproved(true)
.WithIsLockedOut(true)
.WithSortOrder(5)
.WithTrashed(false)
.AddMemberGroups()
.WithValue("Group 1")
.WithValue("Group 2")
.Done()
.AddAdditionalData()
.WithKeyValue("test1", 123)
.WithKeyValue("test2", "hello")
.Done()
.WithPropertyIdsIncrementingFrom(200)
.AddPropertyData()
.WithKeyValue("title", "Name member")
.WithKeyValue("bodyText", "This is a subpage")
.WithKeyValue("author", "John Doe")
.Done()
.Build();
}
}
}

View File

@@ -0,0 +1,27 @@
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 DataTypeBuilderTests
{
[Test]
public void Is_Built_Correctly()
{
// Arrange
const int testId = 3123;
var builder = new DataTypeBuilder();
// Act
var dtd = builder
.WithId(testId)
.Build();
// Assert
Assert.AreEqual(testId, dtd.Id);
}
}
}

View File

@@ -0,0 +1,158 @@
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 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()
{
// Arrange
const int testMemberTypeId = 99;
const string testMemberTypeAlias = "memberType";
const string testMemberTypeName = "Member Type";
const string testMemberTypePropertyGroupName = "Content";
const int testId = 10;
const string testName = "Fred";
const string testUsername = "fred";
const string testRawPasswordValue = "raw pass";
const string testEmail = "email@email.com";
const int testCreatorId = 22;
const int testLevel = 3;
const string testPath = "-1, 4, 10";
const bool testIsApproved = true;
const bool testIsLockedOut = true;
const int testSortOrder = 5;
const bool testTrashed = false;
var testKey = Guid.NewGuid();
var testCreateDate = DateTime.Now.AddHours(-1);
var testUpdateDate = DateTime.Now;
var testLastLockoutDate = DateTime.Now.AddHours(-2);
var testLastLoginDate = DateTime.Now.AddHours(-3);
var testLastPasswordChangeDate = DateTime.Now.AddHours(-4);
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 testPropertyType3 = new PropertyTypeDetail { Alias = "author", Name = "Author", Description = "Writer of the article", SortOrder = 1, DataTypeId = -88 };
var testGroups = new string[] { "group1", "group2" };
var testPropertyData1 = new KeyValuePair<string, object>("title", "Name member");
var testPropertyData2 = new KeyValuePair<string, object>("bodyText", "This is a subpage");
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");
var builder = new MemberBuilder();
// Act
var member = builder
.AddMemberType()
.WithId(testMemberTypeId)
.WithAlias(testMemberTypeAlias)
.WithName(testMemberTypeName)
.WithMembershipPropertyGroup()
.AddPropertyGroup()
.WithName(testMemberTypePropertyGroupName)
.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()
.AddPropertyType()
.WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.TextBox)
.WithValueStorageType(ValueStorageType.Nvarchar)
.WithAlias(testPropertyType3.Alias)
.WithName(testPropertyType3.Name)
.WithDescription(testPropertyType3.Description)
.WithSortOrder(testPropertyType3.SortOrder)
.WithDataTypeId(testPropertyType3.DataTypeId)
.Done()
.Done()
.Done()
.WithId(testId)
.WithKey(testKey)
.WithName(testName)
.WithUserName(testUsername)
.WithRawPasswordValue(testRawPasswordValue)
.WithEmail(testEmail)
.WithCreatorId(testCreatorId)
.WithCreateDate(testCreateDate)
.WithUpdateDate(testUpdateDate)
.WithFailedPasswordAttempts(22)
.WithLevel(testLevel)
.WithPath(testPath)
.WithIsApproved(testIsApproved)
.WithIsLockedOut(testIsLockedOut)
.WithLastLockoutDate(testLastLockoutDate)
.WithLastLoginDate(testLastLoginDate)
.WithLastPasswordChangeDate(testLastPasswordChangeDate)
.WithSortOrder(testSortOrder)
.WithTrashed(testTrashed)
.AddMemberGroups()
.WithValue(testGroups[0])
.WithValue(testGroups[1])
.Done()
.AddAdditionalData()
.WithKeyValue(testAdditionalData1.Key, testAdditionalData1.Value)
.WithKeyValue(testAdditionalData2.Key, testAdditionalData2.Value)
.Done()
.WithPropertyIdsIncrementingFrom(200)
.AddPropertyData()
.WithKeyValue(testPropertyData1.Key, testPropertyData1.Value)
.WithKeyValue(testPropertyData2.Key, testPropertyData2.Value)
.WithKeyValue(testPropertyData3.Key, testPropertyData3.Value)
.Done()
.Build();
// Assert
Assert.AreEqual(testMemberTypeId, member.ContentTypeId);
Assert.AreEqual(testMemberTypeAlias, member.ContentType.Alias);
Assert.AreEqual(testMemberTypeName, member.ContentType.Name);
Assert.AreEqual(testId, member.Id);
Assert.AreEqual(testKey, member.Key);
Assert.AreEqual(testName, member.Name);
Assert.AreEqual(testCreateDate, member.CreateDate);
Assert.AreEqual(testUpdateDate, member.UpdateDate);
Assert.AreEqual(testCreatorId, member.CreatorId);
Assert.AreEqual(testGroups, member.Groups.ToArray());
Assert.AreEqual(10, member.Properties.Count); // 7 from membership properties group, 3 custom
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));
Assert.AreEqual(2, member.AdditionalData.Count);
Assert.AreEqual(testAdditionalData1.Value, member.AdditionalData[testAdditionalData1.Key]);
Assert.AreEqual(testAdditionalData2.Value, member.AdditionalData[testAdditionalData2.Key]);
}
}
}

View File

@@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
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 MemberGroupBuilderTests
{
[Test]
public void Is_Built_Correctly()
{
// Arrange
const int testId = 6;
const string testName = "Test Group";
const int testCreatorId = 4;
var testKey = Guid.NewGuid();
var testCreateDate = DateTime.Now.AddHours(-1);
var testUpdateDate = DateTime.Now;
var testAdditionalData1 = new KeyValuePair<string, object>("test1", 123);
var testAdditionalData2 = new KeyValuePair<string, object>("test2", "hello");
var builder = new MemberGroupBuilder();
// Act
var group = builder
.WithId(testId)
.WithKey(testKey)
.WithName(testName)
.WithCreatorId(testCreatorId)
.WithCreateDate(testCreateDate)
.WithUpdateDate(testUpdateDate)
.AddAdditionalData()
.WithKeyValue(testAdditionalData1.Key, testAdditionalData1.Value)
.WithKeyValue(testAdditionalData2.Key, testAdditionalData2.Value)
.Done()
.Build();
// Assert
Assert.AreEqual(testId, group.Id);
Assert.AreEqual(testKey, group.Key);
Assert.AreEqual(testName, group.Name);
Assert.AreEqual(testCreateDate, group.CreateDate);
Assert.AreEqual(testUpdateDate, group.UpdateDate);
Assert.AreEqual(testCreatorId, group.CreatorId);
Assert.AreEqual(3, group.AdditionalData.Count); // previousName is added as part of the MemberGroup construction, plus the 2 we've added.
Assert.AreEqual(testAdditionalData1.Value, group.AdditionalData[testAdditionalData1.Key]);
Assert.AreEqual(testAdditionalData2.Value, group.AdditionalData[testAdditionalData2.Key]);
}
}
}

View File

@@ -1,134 +0,0 @@
using System;
using System.Diagnostics;
using System.Linq;
using Newtonsoft.Json;
using NUnit.Framework;
using Umbraco.Core.Composing;
using Umbraco.Core.Models;
using Umbraco.Tests.TestHelpers;
using Umbraco.Tests.TestHelpers.Entities;
namespace Umbraco.Tests.Models
{
[TestFixture]
public class MemberTests
{
[Test]
public void Can_Deep_Clone()
{
// Arrange
var memberType = MockedContentTypes.CreateSimpleMemberType("memberType", "Member Type");
memberType.Id = 99;
var member = MockedMember.CreateSimpleMember(memberType, "Name", "email@email.com", "pass", "user", Guid.NewGuid());
var i = 200;
foreach (var property in member.Properties)
{
property.Id = ++i;
}
member.Id = 10;
member.CreateDate = DateTime.Now;
member.CreatorId = 22;
member.Comments = "comments";
member.Key = Guid.NewGuid();
member.FailedPasswordAttempts = 22;
member.Level = 3;
member.Path = "-1,4,10";
member.Groups = new[] {"group1", "group2"};
member.IsApproved = true;
member.IsLockedOut = true;
member.LastLockoutDate = DateTime.Now;
member.LastLoginDate = DateTime.Now;
member.LastPasswordChangeDate = DateTime.Now;
member.RawPasswordValue = "raw pass";
member.SortOrder = 5;
member.Trashed = false;
member.UpdateDate = DateTime.Now;
member.AdditionalData.Add("test1", 123);
member.AdditionalData.Add("test2", "hello");
// Act
var clone = (Member)member.DeepClone();
// Assert
Assert.AreNotSame(clone, member);
Assert.AreEqual(clone, member);
Assert.AreEqual(clone.Id, member.Id);
Assert.AreEqual(clone.VersionId, member.VersionId);
Assert.AreEqual(clone.AdditionalData, member.AdditionalData);
Assert.AreEqual(clone.ContentType, member.ContentType);
Assert.AreEqual(clone.ContentTypeId, member.ContentTypeId);
Assert.AreEqual(clone.CreateDate, member.CreateDate);
Assert.AreEqual(clone.CreatorId, member.CreatorId);
Assert.AreEqual(clone.Comments, member.Comments);
Assert.AreEqual(clone.Key, member.Key);
Assert.AreEqual(clone.FailedPasswordAttempts, member.FailedPasswordAttempts);
Assert.AreEqual(clone.Level, member.Level);
Assert.AreEqual(clone.Path, member.Path);
Assert.AreEqual(clone.Groups, member.Groups);
Assert.AreEqual(clone.Groups.Count(), member.Groups.Count());
Assert.AreEqual(clone.IsApproved, member.IsApproved);
Assert.AreEqual(clone.IsLockedOut, member.IsLockedOut);
Assert.AreEqual(clone.SortOrder, member.SortOrder);
Assert.AreEqual(clone.LastLockoutDate, member.LastLockoutDate);
Assert.AreNotSame(clone.LastLoginDate, member.LastLoginDate);
Assert.AreEqual(clone.LastPasswordChangeDate, member.LastPasswordChangeDate);
Assert.AreEqual(clone.Trashed, member.Trashed);
Assert.AreEqual(clone.UpdateDate, member.UpdateDate);
Assert.AreEqual(clone.VersionId, member.VersionId);
Assert.AreEqual(clone.RawPasswordValue, member.RawPasswordValue);
Assert.AreNotSame(clone.Properties, member.Properties);
Assert.AreEqual(clone.Properties.Count(), member.Properties.Count());
for (var index = 0; index < member.Properties.Count; index++)
{
Assert.AreNotSame(clone.Properties[index], member.Properties[index]);
Assert.AreEqual(clone.Properties[index], member.Properties[index]);
}
// this can be the same, it is immutable
Assert.AreSame(clone.ContentType, member.ContentType);
//This double verifies by reflection
var allProps = clone.GetType().GetProperties();
foreach (var propertyInfo in allProps)
{
Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(member, null));
}
}
[Test]
public void Can_Serialize_Without_Error()
{
var memberType = MockedContentTypes.CreateSimpleMemberType("memberType", "Member Type");
memberType.Id = 99;
var member = MockedMember.CreateSimpleMember(memberType, "Name", "email@email.com", "pass", "user", Guid.NewGuid());
var i = 200;
foreach (var property in member.Properties)
{
property.Id = ++i;
}
member.Id = 10;
member.CreateDate = DateTime.Now;
member.CreatorId = 22;
member.Comments = "comments";
member.Key = Guid.NewGuid();
member.FailedPasswordAttempts = 22;
member.Level = 3;
member.Path = "-1,4,10";
member.Groups = new[] { "group1", "group2" };
member.IsApproved = true;
member.IsLockedOut = true;
member.LastLockoutDate = DateTime.Now;
member.LastLoginDate = DateTime.Now;
member.LastPasswordChangeDate = DateTime.Now;
member.RawPasswordValue = "raw pass";
member.SortOrder = 5;
member.Trashed = false;
member.UpdateDate = DateTime.Now;
member.AdditionalData.Add("test1", 123);
member.AdditionalData.Add("test2", "hello");
var json = JsonConvert.SerializeObject(member);
Debug.Print(json);
}
}
}

View File

@@ -297,8 +297,6 @@
<Compile Include="Models\ContentTypeTests.cs" />
<Compile Include="Models\DeepCloneHelperTests.cs" />
<Compile Include="Models\DictionaryTranslationTests.cs" />
<Compile Include="Models\MemberGroupTests.cs" />
<Compile Include="Models\MemberTests.cs" />
<Compile Include="Models\PropertyGroupTests.cs" />
<Compile Include="Models\PropertyTypeTests.cs" />
<Compile Include="Models\RelationTests.cs" />