Merge remote-tracking branch 'Umbraco/netcore/dev' into netcore/feature/users

This commit is contained in:
Scott Brady
2020-04-17 10:37:13 +01:00
63 changed files with 1279 additions and 518 deletions

View File

@@ -1,5 +1,6 @@
using System;
using System.Runtime.Serialization;
using Umbraco.Core.Exceptions;
using Umbraco.Core.Models.Entities;
namespace Umbraco.Core.Models
@@ -13,20 +14,25 @@ namespace Umbraco.Core.Models
{
private string _name;
private string _alias;
private bool _isBidrectional;
private bool _isBidirectional;
private Guid? _parentObjectType;
private Guid? _childObjectType;
public RelationType(string alias, string name)
: this(name, alias, false, null, null)
: this(name: name, alias: alias, false, null, null)
{
}
public RelationType(string name, string alias, bool isBidrectional, Guid? parentObjectType, Guid? childObjectType)
{
if (name == null) throw new ArgumentNullException(nameof(name));
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(name));
if (alias == null) throw new ArgumentNullException(nameof(alias));
if (string.IsNullOrWhiteSpace(alias)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(alias));
_name = name;
_alias = alias;
_isBidrectional = isBidrectional;
_isBidirectional = isBidrectional;
_parentObjectType = parentObjectType;
_childObjectType = childObjectType;
}
@@ -57,8 +63,8 @@ namespace Umbraco.Core.Models
[DataMember]
public bool IsBidirectional
{
get => _isBidrectional;
set => SetPropertyValueAndDetectChanges(value, ref _isBidrectional, nameof(IsBidirectional));
get => _isBidirectional;
set => SetPropertyValueAndDetectChanges(value, ref _isBidirectional, nameof(IsBidirectional));
}
/// <summary>

View File

@@ -9,7 +9,7 @@ namespace Umbraco.Core.Persistence.Factories
public static IRelationType BuildEntity(RelationTypeDto dto)
{
var entity = new RelationType(dto.Name, dto.Alias, dto.Dual, dto.ChildObjectType, dto.ParentObjectType);
var entity = new RelationType(dto.Name, dto.Alias, dto.Dual, dto.ParentObjectType, dto.ChildObjectType);
try
{

View File

@@ -23,7 +23,6 @@ namespace Umbraco.Core.PropertyEditors
public class DataEditor : IDataEditor
{
private IDictionary<string, object> _defaultConfiguration;
private IDataValueEditor _dataValueEditor;
/// <summary>
/// Initializes a new instance of the <see cref="DataEditor"/> class.
@@ -105,7 +104,7 @@ namespace Umbraco.Core.PropertyEditors
/// simple enough for now.</para>
/// </remarks>
// TODO: point of that one? shouldn't we always configure?
public IDataValueEditor GetValueEditor() => ExplicitValueEditor ?? (_dataValueEditor ?? (_dataValueEditor = CreateValueEditor()));
public IDataValueEditor GetValueEditor() => ExplicitValueEditor ?? CreateValueEditor();
/// <inheritdoc />
/// <remarks>

View File

@@ -186,6 +186,10 @@ namespace Umbraco.Web.PropertyEditors
public IEnumerable<UmbracoEntityReference> GetReferences(object value)
{
var rawJson = value == null ? string.Empty : value is string str ? str : value.ToString();
if (rawJson.IsNullOrWhiteSpace())
yield break;
DeserializeGridValue(rawJson, out var richTextEditorValues, out var mediaValues);
foreach (var umbracoEntityReference in richTextEditorValues.SelectMany(x =>

View File

@@ -57,9 +57,11 @@ namespace Umbraco.Web.PropertyEditors
if (string.IsNullOrEmpty(asString)) yield break;
if (UdiParser.TryParse(asString, out var udi))
yield return new UmbracoEntityReference(udi);
foreach (var udiStr in asString.Split(','))
{
if (UdiParser.TryParse(udiStr, out var udi))
yield return new UmbracoEntityReference(udi);
}
}
}
}

View File

@@ -78,7 +78,10 @@
</AssemblyAttribute>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>Umbraco.Tests.Common</_Parameter1>
</AssemblyAttribute>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>Umbraco.Tests.UnitTests</_Parameter1>
</AssemblyAttribute>
</ItemGroup>
<ItemGroup>

View File

@@ -876,9 +876,11 @@ namespace Umbraco.Web.PublishedCache.NuCache
var id = content.FirstChildContentId;
while (id > 0)
{
// get the required link node, this ensures that both `link` and `link.Value` are not null
var link = GetRequiredLinkedNode(id, "child", null);
ClearBranchLocked(link.Value);
id = link.Value.NextSiblingContentId;
var linkValue = link.Value; // capture local since clearing in recurse can clear it
ClearBranchLocked(linkValue); // recurse
id = linkValue.NextSiblingContentId;
}
}

View File

@@ -7,12 +7,10 @@ namespace Umbraco.Tests.Common.Builders
{
private IDictionary<string, object> _defaultConfiguration;
public ConfigurationEditorBuilder(TParent parentBuilder) : base(parentBuilder)
{
}
public ConfigurationEditorBuilder<TParent> WithDefaultConfiguration(IDictionary<string, object> defaultConfiguration)
{
_defaultConfiguration = defaultConfiguration;
@@ -28,6 +26,5 @@ namespace Umbraco.Tests.Common.Builders
DefaultConfiguration = defaultConfiguration,
};
}
}
}

View File

@@ -9,8 +9,8 @@ namespace Umbraco.Tests.Common.Builders
{
public class DataEditorBuilder<TParent> : ChildBuilderBase<TParent, IDataEditor>
{
private readonly ConfigurationEditorBuilder<DataEditorBuilder<TParent>> _explicitConfigurationEditorBuilder;
private readonly DataValueEditorBuilder<DataEditorBuilder<TParent>> _explicitValueEditorBuilder;
private ConfigurationEditorBuilder<DataEditorBuilder<TParent>> _explicitConfigurationEditorBuilder;
private DataValueEditorBuilder<DataEditorBuilder<TParent>> _explicitValueEditorBuilder;
private IDictionary<string, object> _defaultConfiguration;
public DataEditorBuilder(TParent parentBuilder) : base(parentBuilder)

View File

@@ -19,7 +19,7 @@ namespace Umbraco.Tests.Common.Builders
IWithPathBuilder,
IWithSortOrderBuilder
{
private readonly DataEditorBuilder<DataTypeBuilder> _dataEditorBuilder;
private DataEditorBuilder<DataTypeBuilder> _dataEditorBuilder;
private int? _id;
private int? _parentId;
private Guid? _key;
@@ -28,7 +28,6 @@ namespace Umbraco.Tests.Common.Builders
private DateTime? _deleteDate;
private string _name;
private bool? _trashed;
// private object _configuration;
private int? _level;
private string _path;
private int? _creatorId;
@@ -40,12 +39,6 @@ namespace Umbraco.Tests.Common.Builders
_dataEditorBuilder = new DataEditorBuilder<DataTypeBuilder>(this);
}
// public DataTypeBuilder WithConfiguration(object configuration)
// {
// _configuration = configuration;
// return this;
// }
public DataTypeBuilder WithDatabaseType(ValueStorageType databaseType)
{
_databaseType = databaseType;
@@ -67,7 +60,6 @@ namespace Umbraco.Tests.Common.Builders
var updateDate = _updateDate ?? DateTime.Now;
var deleteDate = _deleteDate ?? null;
var name = _name ?? Guid.NewGuid().ToString();
// var configuration = _configuration ?? editor.GetConfigurationEditor().DefaultConfigurationObject;
var level = _level ?? 0;
var path = _path ?? string.Empty;
var creatorId = _creatorId ?? 1;

View File

@@ -13,7 +13,6 @@ namespace Umbraco.Tests.Common.Builders
private bool? _hideLabel;
private string _valueType;
public DataValueEditorBuilder(TParent parentBuilder) : base(parentBuilder)
{
}

View File

@@ -12,8 +12,7 @@ namespace Umbraco.Tests.Common.Builders
IWithDeleteDateBuilder,
IWithKeyBuilder
{
private readonly LanguageBuilder<DictionaryTranslationBuilder> _languageBuilder;
private readonly Guid? _uniqueId = null;
private LanguageBuilder<DictionaryTranslationBuilder> _languageBuilder;
private DateTime? _createDate;
private DateTime? _deleteDate;
private int? _id;
@@ -26,6 +25,36 @@ namespace Umbraco.Tests.Common.Builders
_languageBuilder = new LanguageBuilder<DictionaryTranslationBuilder>(this);
}
public LanguageBuilder<DictionaryTranslationBuilder> AddLanguage() => _languageBuilder;
public DictionaryTranslationBuilder WithValue(string value)
{
_value = value;
return this;
}
public override IDictionaryTranslation Build()
{
var createDate = _createDate ?? DateTime.Now;
var updateDate = _updateDate ?? DateTime.Now;
var deleteDate = _deleteDate ?? null;
var id = _id ?? 1;
var key = _key ?? Guid.NewGuid();
var result = new DictionaryTranslation(
_languageBuilder.Build(),
_value ?? Guid.NewGuid().ToString(),
key)
{
CreateDate = createDate,
UpdateDate = updateDate,
DeleteDate = deleteDate,
Id = id
};
return result;
}
DateTime? IWithCreateDateBuilder.CreateDate
{
get => _createDate;
@@ -55,35 +84,5 @@ namespace Umbraco.Tests.Common.Builders
get => _updateDate;
set => _updateDate = value;
}
public override IDictionaryTranslation Build()
{
var createDate = _createDate ?? DateTime.Now;
var updateDate = _updateDate ?? DateTime.Now;
var deleteDate = _deleteDate ?? null;
var id = _id ?? 1;
var key = _key ?? Guid.NewGuid();
var result = new DictionaryTranslation(
_languageBuilder.Build(),
_value ?? Guid.NewGuid().ToString(),
_uniqueId ?? key)
{
CreateDate = createDate,
UpdateDate = updateDate,
DeleteDate = deleteDate,
Id = id
};
return result;
}
public LanguageBuilder<DictionaryTranslationBuilder> AddLanguage() => _languageBuilder;
public DictionaryTranslationBuilder WithValue(string value)
{
_value = value;
return this;
}
}
}

View File

@@ -0,0 +1,44 @@
using Umbraco.Core.Models.Entities;
using Umbraco.Tests.Common.Builders.Interfaces;
namespace Umbraco.Tests.Common.Builders
{
public class EntitySlimBuilder
: BuilderBase<EntitySlim>,
IWithIdBuilder,
IWithParentIdBuilder
{
private int? _id;
private int? _parentId;
public override EntitySlim Build()
{
var id = _id ?? 1;
var parentId = _parentId ?? -1;
return new EntitySlim
{
Id = id,
ParentId = parentId,
};
}
public EntitySlimBuilder WithNoParentId()
{
_parentId = 0;
return this;
}
int? IWithIdBuilder.Id
{
get => _id;
set => _id = value;
}
int? IWithParentIdBuilder.ParentId
{
get => _parentId;
set => _parentId = value;
}
}
}

View File

@@ -12,6 +12,13 @@ namespace Umbraco.Tests.Common.Builders.Extensions
return builder;
}
public static T WithoutIdentity<T>(this T builder)
where T : IWithIdBuilder
{
builder.Id = 0;
return builder;
}
public static T WithCreatorId<T>(this T builder, int creatorId)
where T : IWithCreatorIdBuilder
{
@@ -116,5 +123,60 @@ namespace Umbraco.Tests.Common.Builders.Extensions
builder.Thumbnail = thumbnail;
return builder;
}
public static T WithLogin<T>(this T builder, string username, string rawPasswordValue)
where T : IWithLoginBuilder
{
builder.Username = username;
builder.RawPasswordValue = rawPasswordValue;
return builder;
}
public static T WithEmail<T>(this T builder, string email)
where T : IWithEmailBuilder
{
builder.Email = email;
return builder;
}
public static T WithFailedPasswordAttempts<T>(this T builder, int failedPasswordAttempts)
where T : IWithFailedPasswordAttemptsBuilder
{
builder.FailedPasswordAttempts = failedPasswordAttempts;
return builder;
}
public static T WithIsApproved<T>(this T builder, bool isApproved)
where T : IWithIsApprovedBuilder
{
builder.IsApproved = isApproved;
return builder;
}
public static T WithIsLockedOut<T>(this T builder, bool isLockedOut, DateTime? lastLockoutDate = null)
where T : IWithIsLockedOutBuilder
{
builder.IsLockedOut = isLockedOut;
if (lastLockoutDate.HasValue)
{
builder.LastLockoutDate = lastLockoutDate.Value;
}
return builder;
}
public static T WithLastLoginDate<T>(this T builder, DateTime lastLoginDate)
where T : IWithLastLoginDateBuilder
{
builder.LastLoginDate = lastLoginDate;
return builder;
}
public static T WithLastPasswordChangeDate<T>(this T builder, DateTime lastPasswordChangeDate)
where T : IWithLastPasswordChangeDateBuilder
{
builder.LastPasswordChangeDate = lastPasswordChangeDate;
return builder;
}
}
}

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
namespace Umbraco.Tests.Common.Builders
{
@@ -14,7 +15,8 @@ namespace Umbraco.Tests.Common.Builders
public override IEnumerable<T> Build()
{
return _collection;
var collection = _collection?.ToList() ?? Enumerable.Empty<T>();
return collection;
}
public GenericCollectionBuilder<TBuilder, T> WithValue(T value)

View File

@@ -14,7 +14,9 @@ namespace Umbraco.Tests.Common.Builders
public override IDictionary<TKey, TValue> Build()
{
return _dictionary;
return _dictionary == null
? new Dictionary<TKey, TValue>()
: new Dictionary<TKey, TValue>(_dictionary);
}
public GenericDictionaryBuilder<TBuilder, TKey, TValue> WithKeyValue(TKey key, TValue value)

View File

@@ -34,7 +34,6 @@ namespace Umbraco.Tests.Common.Builders
private int? _versionCheckPeriod;
private readonly SmtpSettingsBuilder<GlobalSettingsBuilder<TParent>> _smtpSettingsBuilder;
public GlobalSettingsBuilder(TParent parentBuilder) : base(parentBuilder)
{
_smtpSettingsBuilder = new SmtpSettingsBuilder<GlobalSettingsBuilder<TParent>>(this);
@@ -192,7 +191,6 @@ namespace Umbraco.Tests.Common.Builders
var mainDomLock = _mainDomLock ?? string.Empty;
var noNodesViewPath = _noNodesViewPath ?? "~/config/splashes/NoNodes.cshtml";
return new TestGlobalSettings
{
ConfigurationStatus = configurationStatus,

View File

@@ -0,0 +1,12 @@
namespace Umbraco.Tests.Common.Builders.Interfaces
{
public interface IAccountBuilder : IWithLoginBuilder,
IWithEmailBuilder,
IWithFailedPasswordAttemptsBuilder,
IWithIsApprovedBuilder,
IWithIsLockedOutBuilder,
IWithLastLoginDateBuilder,
IWithLastPasswordChangeDateBuilder
{
}
}

View File

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

View File

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

View File

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

View File

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

View File

@@ -0,0 +1,11 @@
using System;
namespace Umbraco.Tests.Common.Builders.Interfaces
{
public interface IWithIsLockedOutBuilder
{
bool? IsLockedOut { get; set; }
DateTime? LastLockoutDate { get; set; }
}
}

View File

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

View File

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

View File

@@ -0,0 +1,9 @@
namespace Umbraco.Tests.Common.Builders.Interfaces
{
public interface IWithLoginBuilder
{
string Username { get; set; }
string RawPasswordValue { get; set; }
}
}

View File

@@ -37,6 +37,50 @@ namespace Umbraco.Tests.Common.Builders
{
}
public LanguageBuilder<TParent> WithIsDefault(bool isDefault)
{
_isDefault = isDefault;
return this;
}
public LanguageBuilder<TParent> WithIsMandatory(bool isMandatory)
{
_isMandatory = isMandatory;
return this;
}
public LanguageBuilder<TParent> WithFallbackLanguageId(int fallbackLanguageId)
{
_fallbackLanguageId = fallbackLanguageId;
return this;
}
public override ILanguage Build()
{
var cultureInfo = _cultureInfo ?? CultureInfo.GetCultureInfo("en-US");
var key = _key ?? Guid.NewGuid();
var createDate = _createDate ?? DateTime.Now;
var updateDate = _updateDate ?? DateTime.Now;
var deleteDate = _deleteDate ?? null;
var fallbackLanguageId = _fallbackLanguageId ?? null;
var isDefault = _isDefault ?? false;
var isMandatory = _isMandatory ?? false;
return new Language(Mock.Of<IGlobalSettings>(), cultureInfo.Name)
{
Id = _id ?? 1,
CultureName = cultureInfo.TwoLetterISOLanguageName,
IsoCode = new RegionInfo(cultureInfo.LCID).Name,
Key = key,
CreateDate = createDate,
UpdateDate = updateDate,
DeleteDate = deleteDate,
IsDefault = isDefault,
IsMandatory = isMandatory,
FallbackLanguageId = fallbackLanguageId
};
}
DateTime? IWithCreateDateBuilder.CreateDate
{
get => _createDate;
@@ -72,49 +116,5 @@ namespace Umbraco.Tests.Common.Builders
get => _updateDate;
set => _updateDate = value;
}
public override ILanguage Build()
{
var cultureInfo = _cultureInfo ?? CultureInfo.GetCultureInfo("en-US");
var key = _key ?? Guid.NewGuid();
var createDate = _createDate ?? DateTime.Now;
var updateDate = _updateDate ?? DateTime.Now;
var deleteDate = _deleteDate ?? null;
var fallbackLanguageId = _fallbackLanguageId ?? null;
var isDefault = _isDefault ?? false;
var isMandatory = _isMandatory ?? false;
return new Language(Mock.Of<IGlobalSettings>(), cultureInfo.Name)
{
Id = _id ?? 1,
CultureName = cultureInfo.TwoLetterISOLanguageName,
IsoCode = new RegionInfo(cultureInfo.LCID).Name,
Key = key,
CreateDate = createDate,
UpdateDate = updateDate,
DeleteDate = deleteDate,
IsDefault = isDefault,
IsMandatory = isMandatory,
FallbackLanguageId = fallbackLanguageId
};
}
public LanguageBuilder<TParent> WithIsDefault(bool isDefault)
{
_isDefault = isDefault;
return this;
}
public LanguageBuilder<TParent> WithIsMandatory(bool isMandatory)
{
_isMandatory = isMandatory;
return this;
}
public LanguageBuilder<TParent> WithFallbackLanguageId(int fallbackLanguageId)
{
_fallbackLanguageId = fallbackLanguageId;
return this;
}
}
}

View File

@@ -0,0 +1,125 @@
using System;
using System.Collections.Generic;
using System.Linq;
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 MacroBuilder
: BuilderBase<Macro>,
IWithIdBuilder,
IWithKeyBuilder,
IWithAliasBuilder,
IWithNameBuilder
{
private List<MacroPropertyBuilder> _propertyBuilders = new List<MacroPropertyBuilder>();
private int? _id;
private Guid? _key;
private string _alias;
private string _name;
private bool? _useInEditor;
private int? _cacheDuration;
private bool? _cacheByPage;
private bool? _cacheByMember;
private bool? _dontRender;
private string _macroSource;
public MacroBuilder WithUseInEditor(bool useInEditor)
{
_useInEditor = useInEditor;
return this;
}
public MacroBuilder WithCacheDuration(int cacheDuration)
{
_cacheDuration = cacheDuration;
return this;
}
public MacroBuilder WithCacheByPage(bool cacheByPage)
{
_cacheByPage = cacheByPage;
return this;
}
public MacroBuilder WithCacheByMember(bool cacheByMember)
{
_cacheByMember = cacheByMember;
return this;
}
public MacroBuilder WithDontRender(bool dontRender)
{
_dontRender = dontRender;
return this;
}
public MacroBuilder WithSource(string macroSource)
{
_macroSource = macroSource;
return this;
}
public MacroPropertyBuilder AddProperty()
{
var builder = new MacroPropertyBuilder(this);
_propertyBuilders.Add(builder);
return builder;
}
public override Macro Build()
{
var id = _id ?? 1;
var name = _name ?? Guid.NewGuid().ToString();
var alias = _alias ?? name.ToCamelCase();
var key = _key ?? Guid.NewGuid();
var useInEditor = _useInEditor ?? false;
var cacheDuration = _cacheDuration ?? 0;
var cacheByPage = _cacheByPage ?? false;
var cacheByMember = _cacheByMember ?? false;
var dontRender = _dontRender ?? false;
var macroSource = _macroSource ?? string.Empty;
var shortStringHelper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig());
var macro = new Macro(shortStringHelper, id, key, useInEditor, cacheDuration, alias, name, cacheByPage, cacheByMember, dontRender, macroSource);
foreach (var property in _propertyBuilders.Select(x => x.Build()))
{
macro.Properties.Add(property);
}
return macro;
}
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;
}
}
}

View File

@@ -0,0 +1,75 @@
using System;
using Umbraco.Core.Models;
using Umbraco.Tests.Common.Builders.Extensions;
using Umbraco.Tests.Common.Builders.Interfaces;
namespace Umbraco.Tests.Common.Builders
{
public class MacroPropertyBuilder
: ChildBuilderBase<MacroBuilder, IMacroProperty>,
IWithIdBuilder,
IWithKeyBuilder,
IWithAliasBuilder,
IWithNameBuilder,
IWithSortOrderBuilder
{
private int? _id;
private Guid? _key;
private string _alias;
private string _name;
private int? _sortOrder;
private string _editorAlias;
public MacroPropertyBuilder(MacroBuilder parentBuilder) : base(parentBuilder)
{
}
public MacroPropertyBuilder WithEditorAlias(string editorAlias)
{
_editorAlias = editorAlias;
return this;
}
public override IMacroProperty Build()
{
var id = _id ?? 1;
var name = _name ?? Guid.NewGuid().ToString();
var alias = _alias ?? name.ToCamelCase();
var key = _key ?? Guid.NewGuid();
var sortOrder = _sortOrder ?? 0;
var editorAlias = _editorAlias ?? string.Empty;
return new MacroProperty(id, key, alias, name, sortOrder, editorAlias);
}
int? IWithIdBuilder.Id
{
get => _id;
set => _id = value;
}
Guid? IWithKeyBuilder.Key
{
get => _key;
set => _key = value;
}
string IWithAliasBuilder.Alias
{
get => _alias;
set => _alias = value;
}
string IWithNameBuilder.Name
{
get => _name;
set => _name = value;
}
int? IWithSortOrderBuilder.SortOrder
{
get => _sortOrder;
set => _sortOrder = value;
}
}
}

View File

@@ -15,7 +15,8 @@ namespace Umbraco.Tests.Common.Builders
IWithTrashedBuilder,
IWithLevelBuilder,
IWithPathBuilder,
IWithSortOrderBuilder
IWithSortOrderBuilder,
IAccountBuilder
{
private MemberTypeBuilder _memberTypeBuilder;
private GenericCollectionBuilder<MemberBuilder, string> _memberGroupsBuilder;
@@ -28,12 +29,12 @@ namespace Umbraco.Tests.Common.Builders
private DateTime? _updateDate;
private string _name;
private int? _creatorId;
private int? _level;
private string _path;
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;
@@ -43,60 +44,6 @@ namespace Umbraco.Tests.Common.Builders
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;
@@ -139,19 +86,19 @@ namespace Umbraco.Tests.Common.Builders
var updateDate = _updateDate ?? DateTime.Now;
var name = _name ?? Guid.NewGuid().ToString();
var creatorId = _creatorId ?? 1;
var level = _level ?? 1;
var path = _path ?? "-1";
var sortOrder = _sortOrder ?? 0;
var trashed = _trashed ?? false;
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)
{
@@ -276,5 +223,59 @@ namespace Umbraco.Tests.Common.Builders
get => _sortOrder;
set => _sortOrder = value;
}
string IWithLoginBuilder.Username
{
get => _username;
set => _username = value;
}
string IWithLoginBuilder.RawPasswordValue
{
get => _rawPasswordValue;
set => _rawPasswordValue = value;
}
string IWithEmailBuilder.Email
{
get => _email;
set => _email = value;
}
int? IWithFailedPasswordAttemptsBuilder.FailedPasswordAttempts
{
get => _failedPasswordAttempts;
set => _failedPasswordAttempts = value;
}
bool? IWithIsApprovedBuilder.IsApproved
{
get => _isApproved;
set => _isApproved = value;
}
bool? IWithIsLockedOutBuilder.IsLockedOut
{
get => _isLockedOut;
set => _isLockedOut = value;
}
DateTime? IWithIsLockedOutBuilder.LastLockoutDate
{
get => _lastLockoutDate;
set => _lastLockoutDate = value;
}
DateTime? IWithLastLoginDateBuilder.LastLoginDate
{
get => _lastLoginDate;
set => _lastLoginDate = value;
}
DateTime? IWithLastPasswordChangeDateBuilder.LastPasswordChangeDate
{
get => _lastPasswordChangeDate;
set => _lastPasswordChangeDate = value;
}
}
}

View File

@@ -126,7 +126,7 @@ namespace Umbraco.Tests.Common.Builders
ValidationRegExpMessage = validationRegExpMessage,
};
}
int? IWithIdBuilder.Id
{
get => _id;

View File

@@ -33,6 +33,47 @@ namespace Umbraco.Tests.Common.Builders
{
}
public RelationTypeBuilder WithIsBidirectional(bool isBidirectional)
{
_isBidirectional = isBidirectional;
return this;
}
public RelationTypeBuilder WithChildObjectType(Guid childObjectType)
{
_childObjectType = childObjectType;
return this;
}
public RelationTypeBuilder WithParentObjectType(Guid parentObjectType)
{
_parentObjectType = parentObjectType;
return this;
}
public override IRelationType Build()
{
var alias = _alias ?? Guid.NewGuid().ToString();
var name = _name ?? Guid.NewGuid().ToString();
var parentObjectType = _parentObjectType ?? null;
var childObjectType = _childObjectType ?? null;
var id = _id ?? 1;
var key = _key ?? Guid.NewGuid();
var isBidirectional = _isBidirectional ?? false;
var createDate = _createDate ?? DateTime.Now;
var updateDate = _updateDate ?? DateTime.Now;
var deleteDate = _deleteDate ?? null;
return new RelationType(name, alias, isBidirectional, parentObjectType, childObjectType)
{
Id = id,
Key = key,
CreateDate = createDate,
UpdateDate = updateDate,
DeleteDate = deleteDate
};
}
string IWithAliasBuilder.Alias
{
get => _alias;
@@ -74,46 +115,5 @@ namespace Umbraco.Tests.Common.Builders
get => _updateDate;
set => _updateDate = value;
}
public override IRelationType Build()
{
var alias = _alias ?? Guid.NewGuid().ToString();
var name = _name ?? Guid.NewGuid().ToString();
var parentObjectType = _parentObjectType ?? null;
var childObjectType = _childObjectType ?? null;
var id = _id ?? 1;
var key = _key ?? Guid.NewGuid();
var isBidirectional = _isBidirectional ?? false;
var createDate = _createDate ?? DateTime.Now;
var updateDate = _updateDate ?? DateTime.Now;
var deleteDate = _deleteDate ?? null;
return new RelationType(name, alias, isBidirectional, parentObjectType, childObjectType)
{
Id = id,
Key = key,
CreateDate = createDate,
UpdateDate = updateDate,
DeleteDate = deleteDate
};
}
public RelationTypeBuilder WithIsBidirectional(bool isBidirectional)
{
_isBidirectional = isBidirectional;
return this;
}
public RelationTypeBuilder WithChildObjectType(Guid childObjectType)
{
_childObjectType = childObjectType;
return this;
}
public RelationTypeBuilder WithParentObjectType(Guid parentObjectType)
{
_parentObjectType = parentObjectType;
return this;
}
}
}

View File

@@ -9,65 +9,64 @@ namespace Umbraco.Tests.Common.Builders
}
}
public class SmtpSettingsBuilder<TParent>
: ChildBuilderBase<TParent, ISmtpSettings>
{
private string _from;
private string _host;
private int? _port;
private string _pickupDirectoryLocation;
public class SmtpSettingsBuilder<TParent>
: ChildBuilderBase<TParent, ISmtpSettings>
{
private string _from;
private string _host;
private int? _port;
private string _pickupDirectoryLocation;
public SmtpSettingsBuilder(TParent parentBuilder) : base(parentBuilder)
{
}
public SmtpSettingsBuilder(TParent parentBuilder) : base(parentBuilder)
{
}
public SmtpSettingsBuilder<TParent> WithFrom(string from)
{
_from = from;
return this;
}
public SmtpSettingsBuilder<TParent> WithFrom(string from)
{
_from = from;
return this;
}
public SmtpSettingsBuilder<TParent> WithHost(string host)
{
_host = host;
return this;
}
public SmtpSettingsBuilder<TParent> WithHost(string host)
{
_host = host;
return this;
}
public SmtpSettingsBuilder<TParent> WithPost(int port)
{
_port = port;
return this;
}
public SmtpSettingsBuilder<TParent> WithPost(int port)
{
_port = port;
return this;
}
public SmtpSettingsBuilder<TParent> WithPickupDirectoryLocation(string pickupDirectoryLocation)
{
_pickupDirectoryLocation = pickupDirectoryLocation;
return this;
}
public SmtpSettingsBuilder<TParent> WithPickupDirectoryLocation(string pickupDirectoryLocation)
{
_pickupDirectoryLocation = pickupDirectoryLocation;
return this;
}
public override ISmtpSettings Build()
{
var from = _from ?? null;
var host = _host ?? null;
var port = _port ?? 25;
var pickupDirectoryLocation = _pickupDirectoryLocation ?? null;
public override ISmtpSettings Build()
{
var from = _from ?? null;
var host = _host ?? null;
var port = _port ?? 25;
var pickupDirectoryLocation = _pickupDirectoryLocation ?? null;
return new TestSmtpSettings()
{
return new TestSmtpSettings()
{
From = from,
Host = host,
Port = port,
PickupDirectoryLocation = pickupDirectoryLocation,
};
}
};
}
private class TestSmtpSettings : ISmtpSettings
{
public string From { get; set; }
public string Host { get; set; }
public int Port { get; set; }
public string PickupDirectoryLocation { get; set; }
}
}
private class TestSmtpSettings : ISmtpSettings
{
public string From { get; set; }
public string Host { get; set; }
public int Port { get; set; }
public string PickupDirectoryLocation { get; set; }
}
}
}

View File

@@ -57,6 +57,7 @@ namespace Umbraco.Tests.Common.Builders
var masterTemplateId = _masterTemplateId ?? null;
var shortStringHelper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig());
return new Template(shortStringHelper, name, alias)
{
Id = id,

View File

@@ -1,41 +1,69 @@
using Umbraco.Configuration.Models;
using System;
using Umbraco.Core.Models.Membership;
using Umbraco.Tests.Common.Builders.Interfaces;
namespace Umbraco.Tests.Common.Builders
{
public class UserBuilder : UserBuilder<object>
{
public UserBuilder() : base(null)
{
}
}
public class UserBuilder<TParent>
: ChildBuilderBase<TParent, User>,
IWithIdBuilder,
IWithKeyBuilder,
IWithCreateDateBuilder,
IWithUpdateDateBuilder,
IWithNameBuilder,
IWithApprovedBuilder
IAccountBuilder
{
private int? _id;
private Guid? _key;
private DateTime? _createDate;
private DateTime? _updateDate;
private string _language;
private bool? _approved;
private string _name;
private string _rawPassword;
private bool? _isLockedOut;
private string _email;
private string _username;
private string _rawPasswordValue;
private string _email;
private int? _failedPasswordAttempts;
private bool? _isApproved;
private bool? _isLockedOut;
private DateTime? _lastLockoutDate;
private DateTime? _lastLoginDate;
private DateTime? _lastPasswordChangeDate;
private string _suffix = string.Empty;
private string _defaultLang;
private string _comments;
private int? _sessionTimeout;
private int[] _startContentIds;
private int[] _startMediaIds;
public UserBuilder(TParent parentBuilder) : base(parentBuilder)
{
}
public UserBuilder<TParent> WithDefaultUILanguage(string defaultLang)
Guid? IWithKeyBuilder.Key
{
get => _key;
set => _key = value;
}
DateTime? IWithCreateDateBuilder.CreateDate
{
get => _createDate;
set => _createDate = value;
}
DateTime? IWithUpdateDateBuilder.UpdateDate
{
get => _updateDate;
set => _updateDate = value;
}
public UserBuilder<TParent> WithDefaultUILanguage(string defaultLang)
{
_defaultLang = defaultLang;
return this;
@@ -47,27 +75,27 @@ namespace Umbraco.Tests.Common.Builders
return this;
}
public UserBuilder<TParent> WithRawPassword(string rawPassword)
public UserBuilder<TParent> WithComments(string comments)
{
_rawPassword = rawPassword;
_comments = comments;
return this;
}
public UserBuilder<TParent> WithEmail(string email)
public UserBuilder<TParent> WithSessionTimeout(int sessionTimeout)
{
_email = email;
_sessionTimeout = sessionTimeout;
return this;
}
public UserBuilder<TParent> WithUsername(string username)
public UserBuilder<TParent> WithStartContentIds(int[] startContentIds)
{
_username = username;
_startContentIds = startContentIds;
return this;
}
public UserBuilder<TParent> WithLockedOut(bool isLockedOut)
public UserBuilder<TParent> WithStartMediaIds(int[] startMediaIds)
{
_isLockedOut = isLockedOut;
_startMediaIds = startMediaIds;
return this;
}
@@ -84,25 +112,50 @@ namespace Umbraco.Tests.Common.Builders
public override User Build()
{
var globalSettings = new GlobalSettingsBuilder().WithDefaultUiLanguage(_defaultLang).Build();
var id = _id ?? 1;
var defaultLang = _defaultLang ?? "en";
var globalSettings = new GlobalSettingsBuilder().WithDefaultUiLanguage(defaultLang).Build();
var key = _key ?? Guid.NewGuid();
var createDate = _createDate ?? DateTime.Now;
var updateDate = _updateDate ?? DateTime.Now;
var name = _name ?? "TestUser" + _suffix;
var email = _email ?? "test" + _suffix + "@test.com";
var username = _username ?? "TestUser" + _suffix;
var rawPassword = _rawPassword ?? "abcdefghijklmnopqrstuvwxyz";
var language = _language ?? globalSettings.DefaultUILanguage;
var username = _username ?? "TestUser" + _suffix;
var email = _email ?? "test" + _suffix + "@test.com";
var rawPasswordValue = _rawPasswordValue ?? "abcdefghijklmnopqrstuvwxyz";
var failedPasswordAttempts = _failedPasswordAttempts ?? 0;
var isApproved = _isApproved ?? false;
var isLockedOut = _isLockedOut ?? false;
var approved = _approved ?? true;
var lastLockoutDate = _lastLockoutDate ?? DateTime.Now;
var lastLoginDate = _lastLoginDate ?? DateTime.Now;
var lastPasswordChangeDate = _lastPasswordChangeDate ?? DateTime.Now;
var comments = _comments ?? string.Empty;
var sessionTimeout = _sessionTimeout ?? 0;
var startContentIds = _startContentIds ?? new int[0];
var startMediaIds = _startMediaIds ?? new int[0];
return new User(
globalSettings,
name,
email,
username,
rawPassword)
rawPasswordValue)
{
Id = id,
Key = key,
CreateDate = createDate,
UpdateDate = updateDate,
Language = language,
FailedPasswordAttempts = failedPasswordAttempts,
IsApproved = isApproved,
IsLockedOut = isLockedOut,
IsApproved = approved
LastLockoutDate = lastLockoutDate,
LastLoginDate = lastLoginDate,
LastPasswordChangeDate = lastPasswordChangeDate,
Comments = comments,
SessionTimeout = sessionTimeout,
StartContentIds = startContentIds,
StartMediaIds = startMediaIds,
};
}
@@ -118,10 +171,58 @@ namespace Umbraco.Tests.Common.Builders
set => _name = value;
}
bool? IWithApprovedBuilder.Approved
string IWithLoginBuilder.Username
{
get => _approved;
set => _approved = value;
get => _username;
set => _username = value;
}
string IWithLoginBuilder.RawPasswordValue
{
get => _rawPasswordValue;
set => _rawPasswordValue = value;
}
string IWithEmailBuilder.Email
{
get => _email;
set => _email = value;
}
int? IWithFailedPasswordAttemptsBuilder.FailedPasswordAttempts
{
get => _failedPasswordAttempts;
set => _failedPasswordAttempts = value;
}
bool? IWithIsApprovedBuilder.IsApproved
{
get => _isApproved;
set => _isApproved = value;
}
bool? IWithIsLockedOutBuilder.IsLockedOut
{
get => _isLockedOut;
set => _isLockedOut = value;
}
DateTime? IWithIsLockedOutBuilder.LastLockoutDate
{
get => _lastLockoutDate;
set => _lastLockoutDate = value;
}
DateTime? IWithLastLoginDateBuilder.LastLoginDate
{
get => _lastLoginDate;
set => _lastLoginDate = value;
}
DateTime? IWithLastPasswordChangeDateBuilder.LastPasswordChangeDate
{
get => _lastPasswordChangeDate;
set => _lastPasswordChangeDate = value;
}
}
}

View File

@@ -6,7 +6,6 @@ using Umbraco.Tests.Common.Builders.Interfaces;
namespace Umbraco.Tests.Common.Builders
{
public class UserGroupBuilder : UserGroupBuilder<object>
{
public UserGroupBuilder() : base(null)
@@ -61,7 +60,7 @@ namespace Umbraco.Tests.Common.Builders
public override IUserGroup Build()
{
return Mock.Of<IUserGroup>(x =>
var userGroup = Mock.Of<IUserGroup>(x =>
x.StartContentId == _startContentId &&
x.StartMediaId == _startMediaId &&
x.Name == (_name ?? ("TestUserGroup" + _suffix)) &&
@@ -69,9 +68,10 @@ namespace Umbraco.Tests.Common.Builders
x.Icon == _icon &&
x.Permissions == _permissions &&
x.AllowedSections == _sectionCollection);
return userGroup;
}
int? IWithIdBuilder.Id
int? IWithIdBuilder.Id
{
get => _id;
set => _id = value;

View File

@@ -1,21 +1,19 @@
using System.Linq;
using System;
using System.Linq;
using Moq;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Cache;
using Umbraco.Core.Logging;
using Umbraco.Core.Configuration;
using Umbraco.Core.Models.Membership;
using Umbraco.Core.Persistence;
using Umbraco.Core.Persistence.Mappers;
using Umbraco.Core.Persistence.Repositories;
using Umbraco.Core.Persistence.Repositories.Implement;
using Umbraco.Core.Scoping;
using Umbraco.Tests.Testing;
using Umbraco.Core.Persistence;
using Umbraco.Core.PropertyEditors;
using System;
using Umbraco.Core.Configuration;
using Umbraco.Core.Services.Implement;
using Umbraco.Tests.Common.Builders.Extensions;
using Umbraco.Tests.Integration.Testing;
using Umbraco.Tests.Testing;
namespace Umbraco.Tests.Persistence.Repositories
{
@@ -89,7 +87,7 @@ namespace Umbraco.Tests.Persistence.Repositories
{
var repository = CreateRepository(provider);
var user = UserBuilder.Build();
var user = UserBuilder.WithoutIdentity().Build();
repository.Save(user);
@@ -367,10 +365,9 @@ namespace Umbraco.Tests.Persistence.Repositories
private User CreateAndCommitUserWithGroup(IUserRepository repository, IUserGroupRepository userGroupRepository)
{
var user = UserBuilder.Build();
var user = UserBuilder.WithoutIdentity().Build();
repository.Save(user);
var group = UserGroupBuilder.Build();
userGroupRepository.AddOrUpdateGroupWithUsers(@group, new[] { user.Id });
@@ -381,9 +378,9 @@ namespace Umbraco.Tests.Persistence.Repositories
private IUser[] CreateAndCommitMultipleUsers(IUserRepository repository)
{
var user1 = UserBuilder.WithSuffix("1").Build();
var user2 = UserBuilder.WithSuffix("2").Build();
var user3 = UserBuilder.WithSuffix("3").Build();
var user1 = UserBuilder.WithoutIdentity().WithSuffix("1").Build();
var user2 = UserBuilder.WithoutIdentity().WithSuffix("2").Build();
var user3 = UserBuilder.WithoutIdentity().WithSuffix("3").Build();
repository.Save(user1);
repository.Save(user2);
repository.Save(user3);

View File

@@ -1,11 +1,8 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using NPoco.Expressions;
using NUnit.Framework;
using Umbraco.Core.Cache;
using Umbraco.Core.Composing;
@@ -21,7 +18,6 @@ using Umbraco.Tests.Common.Builders;
using Umbraco.Tests.Integration.Extensions;
using Umbraco.Tests.Integration.Implementations;
using Umbraco.Web.BackOffice.AspNetCore;
using Umbraco.Web.Common.AspNetCore;
using Umbraco.Web.Common.Extensions;
namespace Umbraco.Tests.Integration.Testing

View File

@@ -9,7 +9,13 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Infrastructure.Models
[TestFixture]
public class DataTypeTests
{
private readonly DataTypeBuilder _builder = new DataTypeBuilder();
private DataTypeBuilder _builder;
[SetUp]
public void SetUp()
{
_builder = new DataTypeBuilder();
}
[Test]
public void Can_Deep_Clone()

View File

@@ -9,7 +9,13 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Infrastructure.Models
[TestFixture]
public class DictionaryItemTests
{
private readonly DictionaryItemBuilder _builder = new DictionaryItemBuilder();
private DictionaryItemBuilder _builder = new DictionaryItemBuilder();
[SetUp]
public void SetUp()
{
_builder = new DictionaryItemBuilder();
}
[Test]
public void Can_Deep_Clone()

View File

@@ -8,7 +8,13 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Infrastructure.Models
[TestFixture]
public class LanguageTests
{
private readonly LanguageBuilder _builder = new LanguageBuilder();
private LanguageBuilder _builder = new LanguageBuilder();
[SetUp]
public void SetUp()
{
_builder = new LanguageBuilder();
}
[Test]
public void Can_Deep_Clone()

View File

@@ -3,18 +3,42 @@ using System.Linq;
using NUnit.Framework;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Entities;
using Umbraco.Tests.TestHelpers;
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 MacroTests
{
private MacroBuilder _builder;
[SetUp]
public void SetUp()
{
_builder = new MacroBuilder();
}
[Test]
public void Can_Deep_Clone()
{
var macro = new Macro(TestHelper.ShortStringHelper, 1, Guid.NewGuid(), true, 3, "test", "Test", false, true, true, "~/script.cshtml");
macro.Properties.Add(new MacroProperty(6, Guid.NewGuid(), "rewq", "REWQ", 1, "asdfasdf"));
var macro = _builder
.WithId(1)
.WithUseInEditor(true)
.WithCacheDuration(3)
.WithAlias("test")
.WithName("Test")
.WithSource("~/script.cshtml")
.WithCacheByMember(true)
.WithDontRender(true)
.AddProperty()
.WithId(6)
.WithAlias("rewq")
.WithName("REWQ")
.WithSortOrder(1)
.WithEditorAlias("asdfasdf")
.Done()
.Build();
var clone = (Macro)macro.DeepClone();
@@ -24,7 +48,7 @@ namespace Umbraco.Tests.Models
Assert.AreEqual(clone.Properties.Count, macro.Properties.Count);
for (int i = 0; i < clone.Properties.Count; i++)
for (var i = 0; i < clone.Properties.Count; i++)
{
Assert.AreEqual(clone.Properties[i], macro.Properties[i]);
Assert.AreNotSame(clone.Properties[i], macro.Properties[i]);
@@ -37,9 +61,7 @@ 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(macro, null));
}
//need to ensure the event handlers are wired
@@ -51,8 +73,6 @@ namespace Umbraco.Tests.Models
Assert.AreEqual(1, clone.AddedProperties.Count());
clone.Properties.Remove("rewq");
Assert.AreEqual(1, clone.RemovedProperties.Count());
}
}
}

View File

@@ -11,7 +11,13 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Infrastructure.Models
[TestFixture]
public class MemberGroupTests
{
private readonly MemberGroupBuilder _builder = new MemberGroupBuilder();
private MemberGroupBuilder _builder;
[SetUp]
public void SetUp()
{
_builder = new MemberGroupBuilder();
}
[Test]
public void Can_Deep_Clone()

View File

@@ -13,7 +13,13 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Infrastructure.Models
[TestFixture]
public class MemberTests
{
private readonly MemberBuilder _builder = new MemberBuilder();
private MemberBuilder _builder;
[SetUp]
public void SetUp()
{
_builder = new MemberBuilder();
}
[Test]
public void Can_Deep_Clone()
@@ -116,14 +122,10 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Infrastructure.Models
.Done()
.Done()
.WithId(10)
.WithKey(Guid.NewGuid())
.WithName("Fred")
.WithUserName("fred")
.WithRawPasswordValue("raw pass")
.WithLogin("fred", "raw pass")
.WithEmail("email@email.com")
.WithCreatorId(22)
.WithCreateDate(DateTime.Now)
.WithUpdateDate(DateTime.Now)
.WithFailedPasswordAttempts(22)
.WithLevel(3)
.WithPath("-1, 4, 10")

View File

@@ -4,16 +4,28 @@ using NUnit.Framework;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Entities;
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 PathValidationTests
{
private EntitySlimBuilder _builder;
[SetUp]
public void SetUp()
{
_builder = new EntitySlimBuilder();
}
[Test]
public void Validate_Path()
{
var entity = new EntitySlim();
var entity = _builder
.WithoutIdentity()
.Build();
//it's empty with no id so we need to allow it
Assert.IsTrue(entity.ValidatePath());
@@ -37,7 +49,9 @@ namespace Umbraco.Tests.Models
[Test]
public void Ensure_Path_Throws_Without_Id()
{
var entity = new EntitySlim();
var entity = _builder
.WithoutIdentity()
.Build();
//no id assigned
Assert.Throws<InvalidOperationException>(() => entity.EnsureValidPath(Mock.Of<ILogger>(), umbracoEntity => new EntitySlim(), umbracoEntity => { }));
@@ -46,7 +60,10 @@ namespace Umbraco.Tests.Models
[Test]
public void Ensure_Path_Throws_Without_Parent()
{
var entity = new EntitySlim { Id = 1234 };
var entity = _builder
.WithId(1234)
.WithNoParentId()
.Build();
//no parent found
Assert.Throws<NullReferenceException>(() => entity.EnsureValidPath(Mock.Of<ILogger>(), umbracoEntity => null, umbracoEntity => { }));
@@ -55,12 +72,9 @@ namespace Umbraco.Tests.Models
[Test]
public void Ensure_Path_Entity_At_Root()
{
var entity = new EntitySlim
{
Id = 1234,
ParentId = -1
};
var entity = _builder
.WithId(1234)
.Build();
entity.EnsureValidPath(Mock.Of<ILogger>(), umbracoEntity => null, umbracoEntity => { });
@@ -71,11 +85,10 @@ namespace Umbraco.Tests.Models
[Test]
public void Ensure_Path_Entity_Valid_Parent()
{
var entity = new EntitySlim
{
Id = 1234,
ParentId = 888
};
var entity = _builder
.WithId(1234)
.WithParentId(888)
.Build();
entity.EnsureValidPath(Mock.Of<ILogger>(), umbracoEntity => umbracoEntity.ParentId == 888 ? new EntitySlim { Id = 888, Path = "-1,888" } : null, umbracoEntity => { });
@@ -86,29 +99,28 @@ namespace Umbraco.Tests.Models
[Test]
public void Ensure_Path_Entity_Valid_Recursive_Parent()
{
var parentA = new EntitySlim
{
Id = 999,
ParentId = -1
};
var parentA = _builder
.WithId(999)
.Build();
var parentB = new EntitySlim
{
Id = 888,
ParentId = 999
};
// Re-creating the class-level builder as we need to reset before usage when creating multiple entities.
_builder = new EntitySlimBuilder();
var parentB = _builder
.WithId(888)
.WithParentId(999)
.Build();
var parentC = new EntitySlim
{
Id = 777,
ParentId = 888
};
_builder = new EntitySlimBuilder();
var parentC = _builder
.WithId(777)
.WithParentId(888)
.Build();
var entity = new EntitySlim
{
Id = 1234,
ParentId = 777
};
_builder = new EntitySlimBuilder();
var entity = _builder
.WithId(1234)
.WithParentId(777)
.Build();
Func<IUmbracoEntity, IUmbracoEntity> getParent = umbracoEntity =>
{
@@ -136,4 +148,4 @@ namespace Umbraco.Tests.Models
Assert.AreEqual("-1,999,888,777,1234", entity.Path);
}
}
}
}

View File

@@ -11,7 +11,13 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Infrastructure.Models
[TestFixture]
public class PropertyGroupTests
{
private readonly PropertyGroupBuilder _builder = new PropertyGroupBuilder();
private PropertyGroupBuilder _builder;
[SetUp]
public void SetUp()
{
_builder = new PropertyGroupBuilder();
}
[Test]
public void Can_Deep_Clone()

View File

@@ -10,7 +10,13 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Infrastructure.Models
[TestFixture]
public class PropertyTests
{
private readonly PropertyBuilder _builder = new PropertyBuilder();
private PropertyBuilder _builder;
[SetUp]
public void SetUp()
{
_builder = new PropertyBuilder();
}
[Test]
public void Can_Deep_Clone()

View File

@@ -13,7 +13,13 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Infrastructure.Models
[TestFixture]
public class PropertyTypeTests
{
private readonly PropertyTypeBuilder _builder = new PropertyTypeBuilder();
private PropertyTypeBuilder _builder;
[SetUp]
public void SetUp()
{
_builder = new PropertyTypeBuilder();
}
[Test]
public void Can_Deep_Clone()

View File

@@ -11,7 +11,13 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Infrastructure.Models
[TestFixture]
public class RelationTests
{
private readonly RelationBuilder _builder = new RelationBuilder();
private RelationBuilder _builder;
[SetUp]
public void SetUp()
{
_builder = new RelationBuilder();
}
[Test]
public void Can_Deep_Clone()

View File

@@ -9,7 +9,13 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Infrastructure.Models
[TestFixture]
public class RelationTypeTests
{
private readonly RelationTypeBuilder _builder = new RelationTypeBuilder();
private RelationTypeBuilder _builder;
[SetUp]
public void SetUp()
{
_builder = new RelationTypeBuilder();
}
[Test]
public void Can_Deep_Clone()

View File

@@ -10,7 +10,13 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Infrastructure.Models
[TestFixture]
public class StylesheetTests
{
private readonly StylesheetBuilder _builder = new StylesheetBuilder();
private StylesheetBuilder _builder;
[SetUp]
public void SetUp()
{
_builder = new StylesheetBuilder();
}
[Test]
public void Can_Create_Stylesheet()

View File

@@ -6,7 +6,6 @@ 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
@@ -14,7 +13,13 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Infrastructure.Models
[TestFixture]
public class TemplateTests
{
private readonly TemplateBuilder _builder = new TemplateBuilder();
private TemplateBuilder _builder;
[SetUp]
public void SetUp()
{
_builder = new TemplateBuilder();
}
[Test]
public void Can_Deep_Clone()

View File

@@ -5,14 +5,22 @@ using Moq;
using NUnit.Framework;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Entities;
using Umbraco.Core.Models.Membership;
using Umbraco.Core.Services;
using Umbraco.Tests.Common.Builders;
namespace Umbraco.Tests.Models
namespace Umbraco.Tests.UnitTests.Umbraco.Infrastructure.Models
{
[TestFixture]
public class UserExtensionsTests
{
private UserBuilder _userBuilder;
[SetUp]
public void SetUp()
{
_userBuilder = new UserBuilder();
}
[TestCase(-1, "-1", "-1,1,2,3,4,5", true)] // below root start node
[TestCase(2, "-1,1,2", "-1,1,2,3,4,5", true)] // below start node
[TestCase(5, "-1,1,2,3,4,5", "-1,1,2,3,4,5", true)] // at start node
@@ -24,9 +32,10 @@ namespace Umbraco.Tests.Models
public void Determines_Path_Based_Access_To_Content(int startNodeId, string startNodePath, string contentPath, bool outcome)
{
var userMock = new Mock<IUser>();
userMock.Setup(u => u.StartContentIds).Returns(new[] { startNodeId });
var user = userMock.Object;
var user = _userBuilder
.WithStartContentIds(new[] { startNodeId })
.Build();
var content = Mock.Of<IContent>(c => c.Path == contentPath && c.Id == 5);
var esmock = new Mock<IEntityService>();

View File

@@ -0,0 +1,67 @@
using System;
using System.Diagnostics;
using System.Linq;
using Newtonsoft.Json;
using NUnit.Framework;
using Umbraco.Core.Models.Membership;
using Umbraco.Tests.Common.Builders;
using Umbraco.Tests.Common.Builders.Extensions;
namespace Umbraco.Tests.UnitTests.Umbraco.Infrastructure.Models
{
[TestFixture]
public class UserTests
{
private UserBuilder _builder;
[SetUp]
public void SetUp()
{
_builder = new UserBuilder();
}
[Test]
public void Can_Deep_Clone()
{
var item = BuildUser();
var clone = (User)item.DeepClone();
Assert.AreNotSame(clone, item);
Assert.AreEqual(clone, item);
Assert.AreEqual(clone.AllowedSections.Count(), item.AllowedSections.Count());
//Verify normal properties with 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 = BuildUser();
var json = JsonConvert.SerializeObject(item);
Debug.Print(json);
}
private User BuildUser()
{
return _builder
.WithId(3)
.WithLogin("username", "test pass")
.WithName("Test")
.WithEmail("test@test.com")
.WithFailedPasswordAttempts(3)
.WithIsApproved(true)
.WithIsLockedOut(true)
.WithComments("comments")
.WithSessionTimeout(5)
.WithStartContentIds(new[] { 3 })
.WithStartMediaIds(new[] { 8 })
.Build();
}
}
}

View File

@@ -0,0 +1,73 @@
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 MacroBuilderTests
{
[Test]
public void Is_Built_Correctly()
{
// Arrange
const int id = 1;
var key = Guid.NewGuid();
const bool useInEditor = true;
const int cacheDuration = 3;
const string alias = "test";
const string name = "Test";
const string source = "~/script.cshtml";
const bool cacheByPage = false;
const bool cacheByMember = true;
const bool dontRender = true;
const int propertyId = 6;
const string propertyAlias = "rewq";
const string propertyName = "REWQ";
const int propertySortOrder = 1;
const string propertyEditorAlias = "asdfasdf";
var builder = new MacroBuilder();
// Act
var macro = builder
.WithId(id)
.WithKey(key)
.WithUseInEditor(useInEditor)
.WithCacheDuration(cacheDuration)
.WithAlias(alias)
.WithName(name)
.WithSource(source)
.WithCacheByPage(cacheByPage)
.WithCacheByMember(cacheByMember)
.WithDontRender(dontRender)
.AddProperty()
.WithId(propertyId)
.WithAlias(propertyAlias)
.WithName(propertyName)
.WithSortOrder(propertySortOrder)
.WithEditorAlias(propertyEditorAlias)
.Done()
.Build();
// Assert
Assert.AreEqual(id, macro.Id);
Assert.AreEqual(key, macro.Key);
Assert.AreEqual(useInEditor, macro.UseInEditor);
Assert.AreEqual(cacheDuration, macro.CacheDuration);
Assert.AreEqual(alias, macro.Alias);
Assert.AreEqual(name, macro.Name);
Assert.AreEqual(source, macro.MacroSource);
Assert.AreEqual(cacheByPage, macro.CacheByPage);
Assert.AreEqual(cacheByMember, macro.CacheByMember);
Assert.AreEqual(dontRender, macro.DontRender);
Assert.AreEqual(1, macro.Properties.Count);
Assert.AreEqual(propertyId, macro.Properties[0].Id);
Assert.AreEqual(propertyAlias, macro.Properties[0].Alias);
Assert.AreEqual(propertyName, macro.Properties[0].Name);
Assert.AreEqual(propertySortOrder, macro.Properties[0].SortOrder);
Assert.AreEqual(propertyEditorAlias, macro.Properties[0].EditorAlias);
}
}
}

View File

@@ -48,6 +48,7 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Tests.Common.Builders
var testKey = Guid.NewGuid();
var testCreateDate = DateTime.Now.AddHours(-1);
var testUpdateDate = DateTime.Now;
const int testFailedPasswordAttempts = 22;
var testLastLockoutDate = DateTime.Now.AddHours(-2);
var testLastLoginDate = DateTime.Now.AddHours(-3);
var testLastPasswordChangeDate = DateTime.Now.AddHours(-4);
@@ -104,18 +105,16 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Tests.Common.Builders
.WithId(testId)
.WithKey(testKey)
.WithName(testName)
.WithUserName(testUsername)
.WithRawPasswordValue(testRawPasswordValue)
.WithLogin(testUsername, testRawPasswordValue)
.WithEmail(testEmail)
.WithCreatorId(testCreatorId)
.WithCreateDate(testCreateDate)
.WithUpdateDate(testUpdateDate)
.WithFailedPasswordAttempts(22)
.WithLevel(testLevel)
.WithPath(testPath)
.WithFailedPasswordAttempts(testFailedPasswordAttempts)
.WithIsApproved(testIsApproved)
.WithIsLockedOut(testIsLockedOut)
.WithLastLockoutDate(testLastLockoutDate)
.WithIsLockedOut(testIsLockedOut, testLastLockoutDate)
.WithLastLoginDate(testLastLoginDate)
.WithLastPasswordChangeDate(testLastPasswordChangeDate)
.WithSortOrder(testSortOrder)
@@ -146,6 +145,12 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Tests.Common.Builders
Assert.AreEqual(testCreateDate, member.CreateDate);
Assert.AreEqual(testUpdateDate, member.UpdateDate);
Assert.AreEqual(testCreatorId, member.CreatorId);
Assert.AreEqual(testFailedPasswordAttempts, member.FailedPasswordAttempts);
Assert.AreEqual(testIsApproved, member.IsApproved);
Assert.AreEqual(testIsLockedOut, member.IsLockedOut);
Assert.AreEqual(testLastLockoutDate, member.LastLockoutDate);
Assert.AreEqual(testLastLoginDate, member.LastLoginDate);
Assert.AreEqual(testLastPasswordChangeDate, member.LastPasswordChangeDate);
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));

View File

@@ -0,0 +1,74 @@
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 UserBuilderTests
{
[Test]
public void Is_Built_Correctly()
{
// Arrange
const int testId = 10;
const string testName = "Fred";
const string testUsername = "fred";
const string testRawPasswordValue = "raw pass";
const string testEmail = "email@email.com";
const bool testIsApproved = true;
const bool testIsLockedOut = true;
var testKey = Guid.NewGuid();
var testCreateDate = DateTime.Now.AddHours(-1);
var testUpdateDate = DateTime.Now;
const int testFailedPasswordAttempts = 22;
var testLastLockoutDate = DateTime.Now.AddHours(-2);
var testLastLoginDate = DateTime.Now.AddHours(-3);
var testLastPasswordChangeDate = DateTime.Now.AddHours(-4);
var testComments = "comments";
var testSessionTimeout = 5;
var testStartContentIds = new[] { 3 };
var testStartMediaIds = new[] { 8 };
var builder = new UserBuilder();
// Act
var user = builder
.WithId(testId)
.WithKey(testKey)
.WithName(testName)
.WithLogin(testUsername, testRawPasswordValue)
.WithEmail(testEmail)
.WithCreateDate(testCreateDate)
.WithUpdateDate(testUpdateDate)
.WithFailedPasswordAttempts(testFailedPasswordAttempts)
.WithIsApproved(testIsApproved)
.WithIsLockedOut(testIsLockedOut, testLastLockoutDate)
.WithLastLoginDate(testLastLoginDate)
.WithLastPasswordChangeDate(testLastPasswordChangeDate)
.WithComments(testComments)
.WithSessionTimeout(5)
.WithStartContentIds(new[] { 3 })
.WithStartMediaIds(new[] { 8 })
.Build();
// Assert
Assert.AreEqual(testId, user.Id);
Assert.AreEqual(testKey, user.Key);
Assert.AreEqual(testName, user.Name);
Assert.AreEqual(testCreateDate, user.CreateDate);
Assert.AreEqual(testUpdateDate, user.UpdateDate);
Assert.AreEqual(testFailedPasswordAttempts, user.FailedPasswordAttempts);
Assert.AreEqual(testIsApproved, user.IsApproved);
Assert.AreEqual(testIsLockedOut, user.IsLockedOut);
Assert.AreEqual(testLastLockoutDate, user.LastLockoutDate);
Assert.AreEqual(testLastLoginDate, user.LastLoginDate);
Assert.AreEqual(testLastPasswordChangeDate, user.LastPasswordChangeDate);
Assert.AreEqual(testComments, user.Comments);
Assert.AreEqual(testSessionTimeout, user.SessionTimeout);
Assert.AreEqual(testStartContentIds, user.StartContentIds);
Assert.AreEqual(testStartMediaIds, user.StartMediaIds);
}
}
}

View File

@@ -1,90 +0,0 @@
using System;
using System.Diagnostics;
using System.Linq;
using Newtonsoft.Json;
using NUnit.Framework;
using Umbraco.Core.Composing;
using Umbraco.Core.Configuration;
using Umbraco.Core.Models.Membership;
using Umbraco.Core.Serialization;
using Umbraco.Tests.TestHelpers;
namespace Umbraco.Tests.Models
{
[TestFixture]
public class UserTests
{
private IGlobalSettings GlobalSettings { get; } = SettingsForTests.DefaultGlobalSettings;
[Test]
public void Can_Deep_Clone()
{
var item = new User(GlobalSettings)
{
Id = 3,
Key = Guid.NewGuid(),
UpdateDate = DateTime.Now,
CreateDate = DateTime.Now,
Name = "Test",
Comments = "comments",
Email = "test@test.com",
Language = "en",
FailedPasswordAttempts = 3,
IsApproved = true,
IsLockedOut = true,
LastLockoutDate = DateTime.Now,
LastLoginDate = DateTime.Now,
LastPasswordChangeDate = DateTime.Now,
//Password = "test pass",
SessionTimeout = 5,
StartContentIds = new[] { 3 },
StartMediaIds = new[] { 8 },
Username = "username"
};
var clone = (User)item.DeepClone();
Assert.AreNotSame(clone, item);
Assert.AreEqual(clone, item);
Assert.AreEqual(clone.AllowedSections.Count(), item.AllowedSections.Count());
//Verify normal properties with 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 User(GlobalSettings)
{
Id = 3,
Key = Guid.NewGuid(),
UpdateDate = DateTime.Now,
CreateDate = DateTime.Now,
Name = "Test",
Comments = "comments",
Email = "test@test.com",
Language = "en",
FailedPasswordAttempts = 3,
IsApproved = true,
IsLockedOut = true,
LastLockoutDate = DateTime.Now,
LastLoginDate = DateTime.Now,
LastPasswordChangeDate = DateTime.Now,
//Password = "test pass",
SessionTimeout = 5,
StartContentIds = new[] { 3 },
StartMediaIds = new[] { 8 },
Username = "username"
};
var json = JsonConvert.SerializeObject(item);
Debug.Print(json);
}
}
}

View File

@@ -107,13 +107,16 @@ namespace Umbraco.Tests.Persistence.Repositories
var repository = CreateRepository(provider);
// Act
var relationType = repository.Get(RelationTypeDto.NodeIdSeed);
var relationType = repository.Get(RelationTypeDto.NodeIdSeed + 2);
// Assert
Assert.That(relationType, Is.Not.Null);
Assert.That(relationType.HasIdentity, Is.True);
Assert.That(relationType.Alias, Is.EqualTo("relateContentOnCopy"));
Assert.That(relationType.Name, Is.EqualTo("Relate Content on Copy"));
Assert.That(relationType.IsBidirectional, Is.True);
Assert.That(relationType.Alias, Is.EqualTo("relateContentToMedia"));
Assert.That(relationType.Name, Is.EqualTo("Relate Content to Media"));
Assert.That(relationType.ChildObjectType, Is.EqualTo(Constants.ObjectTypes.Media));
Assert.That(relationType.ParentObjectType, Is.EqualTo(Constants.ObjectTypes.Document));
}
}
@@ -133,7 +136,7 @@ namespace Umbraco.Tests.Persistence.Repositories
Assert.That(relationTypes, Is.Not.Null);
Assert.That(relationTypes.Any(), Is.True);
Assert.That(relationTypes.Any(x => x == null), Is.False);
Assert.That(relationTypes.Count(), Is.EqualTo(7));
Assert.That(relationTypes.Count(), Is.EqualTo(8));
}
}
@@ -190,7 +193,7 @@ namespace Umbraco.Tests.Persistence.Repositories
int count = repository.Count(query);
// Assert
Assert.That(count, Is.EqualTo(5));
Assert.That(count, Is.EqualTo(6));
}
}
@@ -224,8 +227,9 @@ namespace Umbraco.Tests.Persistence.Repositories
public void CreateTestData()
{
var relateContent = new RelationType("Relate Content on Copy", "relateContentOnCopy", true, Constants.ObjectTypes.Document, new Guid("C66BA18E-EAF3-4CFF-8A22-41B16D66A972"));
var relateContentType = new RelationType("Relate ContentType on Copy", "relateContentTypeOnCopy", true, Constants.ObjectTypes.DocumentType, new Guid("A2CB7800-F571-4787-9638-BC48539A0EFB"));
var relateContent = new RelationType("Relate Content on Copy", "relateContentOnCopy", true, Constants.ObjectTypes.Document, Constants.ObjectTypes.Document);
var relateContentType = new RelationType("Relate ContentType on Copy", "relateContentTypeOnCopy", true, Constants.ObjectTypes.DocumentType, Constants.ObjectTypes.DocumentType);
var relateContentMedia = new RelationType("Relate Content to Media", "relateContentToMedia", true, Constants.ObjectTypes.Document, Constants.ObjectTypes.Media);
var provider = TestObjects.GetScopeProvider(Logger);
using (var scope = ScopeProvider.CreateScope())
@@ -234,6 +238,7 @@ namespace Umbraco.Tests.Persistence.Repositories
repository.Save(relateContent);//Id 2
repository.Save(relateContentType);//Id 3
repository.Save(relateContentMedia);//Id 4
scope.Complete();
}
}

View File

@@ -53,7 +53,7 @@ namespace Umbraco.Tests.PublishedContent
_snapshotService?.Dispose();
}
private void Init(IEnumerable<ContentNodeKit> kits)
private void Init(Func<IEnumerable<ContentNodeKit>> kits)
{
Current.Reset();
@@ -142,7 +142,7 @@ namespace Umbraco.Tests.PublishedContent
_snapshotAccessor = new TestPublishedSnapshotAccessor();
// create a data source for NuCache
_source = new TestDataSource(kits);
_source = new TestDataSource(kits());
var typeFinder = TestHelper.GetTypeFinder();
var settings = Mock.Of<INuCacheSettings>();
@@ -387,7 +387,7 @@ namespace Umbraco.Tests.PublishedContent
[Test]
public void EmptyTest()
{
Init(Enumerable.Empty<ContentNodeKit>());
Init(() => Enumerable.Empty<ContentNodeKit>());
var snapshot = _snapshotService.CreatePublishedSnapshot(previewToken: null);
_snapshotAccessor.PublishedSnapshot = snapshot;
@@ -399,7 +399,7 @@ namespace Umbraco.Tests.PublishedContent
[Test]
public void ChildrenTest()
{
Init(GetInvariantKits());
Init(GetInvariantKits);
var snapshot = _snapshotService.CreatePublishedSnapshot(previewToken: null);
_snapshotAccessor.PublishedSnapshot = snapshot;
@@ -426,7 +426,7 @@ namespace Umbraco.Tests.PublishedContent
[Test]
public void ParentTest()
{
Init(GetInvariantKits());
Init(GetInvariantKits);
var snapshot = _snapshotService.CreatePublishedSnapshot(previewToken: null);
_snapshotAccessor.PublishedSnapshot = snapshot;
@@ -452,7 +452,7 @@ namespace Umbraco.Tests.PublishedContent
[Test]
public void MoveToRootTest()
{
Init(GetInvariantKits());
Init(GetInvariantKits);
// get snapshot
var snapshot = _snapshotService.CreatePublishedSnapshot(previewToken: null);
@@ -494,7 +494,7 @@ namespace Umbraco.Tests.PublishedContent
[Test]
public void MoveFromRootTest()
{
Init(GetInvariantKits());
Init(GetInvariantKits);
// get snapshot
var snapshot = _snapshotService.CreatePublishedSnapshot(previewToken: null);
@@ -536,7 +536,7 @@ namespace Umbraco.Tests.PublishedContent
[Test]
public void ReOrderTest()
{
Init(GetInvariantKits());
Init(GetInvariantKits);
// get snapshot
var snapshot = _snapshotService.CreatePublishedSnapshot(previewToken: null);
@@ -611,7 +611,7 @@ namespace Umbraco.Tests.PublishedContent
[Test]
public void MoveTest()
{
Init(GetInvariantKits());
Init(GetInvariantKits);
// get snapshot
var snapshot = _snapshotService.CreatePublishedSnapshot(previewToken: null);
@@ -712,11 +712,61 @@ namespace Umbraco.Tests.PublishedContent
Assert.AreEqual(1, snapshot.Content.GetById(7).Parent?.Id);
}
[Test]
public void Clear_Branch_Locked()
{
// This test replicates an issue we saw here https://github.com/umbraco/Umbraco-CMS/pull/7907#issuecomment-610259393
// The data was sent to me and this replicates it's structure
var paths = new Dictionary<int, string> { { -1, "-1" } };
Init(() => new List<ContentNodeKit>
{
CreateInvariantKit(1, -1, 1, paths), // first level
CreateInvariantKit(2, 1, 1, paths), // second level
CreateInvariantKit(3, 2, 1, paths), // third level
CreateInvariantKit(4, 3, 1, paths), // fourth level (we'll copy this one to the same level)
CreateInvariantKit(5, 4, 1, paths), // 6th level
CreateInvariantKit(6, 5, 2, paths), // 7th level
CreateInvariantKit(7, 5, 3, paths),
CreateInvariantKit(8, 5, 4, paths),
CreateInvariantKit(9, 5, 5, paths),
CreateInvariantKit(10, 5, 6, paths)
});
// get snapshot
var snapshot = _snapshotService.CreatePublishedSnapshot(previewToken: null);
_snapshotAccessor.PublishedSnapshot = snapshot;
var snapshotService = (PublishedSnapshotService)_snapshotService;
var contentStore = snapshotService.GetContentStore();
//This will set a flag to force creating a new Gen next time the store is locked (i.e. In Notify)
contentStore.CreateSnapshot();
// notify - which ensures there are 2 generations in the cache meaning each LinkedNode has a Next value.
_snapshotService.Notify(new[]
{
new ContentCacheRefresher.JsonPayload(4, Guid.Empty, TreeChangeTypes.RefreshBranch)
}, out _, out _);
// refresh the branch again, this used to show the issue where a null ref exception would occur
// because in the ClearBranchLocked logic, when SetValueLocked was called within a recursive call
// to a child, we null out the .Value of the LinkedNode within the while loop because we didn't capture
// this value before recursing.
Assert.DoesNotThrow(() =>
_snapshotService.Notify(new[]
{
new ContentCacheRefresher.JsonPayload(4, Guid.Empty, TreeChangeTypes.RefreshBranch)
}, out _, out _));
}
[Test]
public void NestedVariationChildrenTest()
{
var mixedKits = GetNestedVariantKits();
Init(mixedKits);
Init(GetNestedVariantKits);
var snapshot = _snapshotService.CreatePublishedSnapshot(previewToken: null);
_snapshotAccessor.PublishedSnapshot = snapshot;
@@ -805,7 +855,7 @@ namespace Umbraco.Tests.PublishedContent
[Test]
public void VariantChildrenTest()
{
Init(GetVariantKits());
Init(GetVariantKits);
var snapshot = _snapshotService.CreatePublishedSnapshot(previewToken: null);
_snapshotAccessor.PublishedSnapshot = snapshot;
@@ -877,7 +927,7 @@ namespace Umbraco.Tests.PublishedContent
[Test]
public void RemoveTest()
{
Init(GetInvariantKits());
Init(GetInvariantKits);
var snapshot = _snapshotService.CreatePublishedSnapshot(previewToken: null);
_snapshotAccessor.PublishedSnapshot = snapshot;
@@ -926,7 +976,7 @@ namespace Umbraco.Tests.PublishedContent
[Test]
public void UpdateTest()
{
Init(GetInvariantKits());
Init(GetInvariantKits);
var snapshot = _snapshotService.CreatePublishedSnapshot(previewToken: null);
_snapshotAccessor.PublishedSnapshot = snapshot;
@@ -979,7 +1029,7 @@ namespace Umbraco.Tests.PublishedContent
[Test]
public void AtRootTest()
{
Init(GetVariantWithDraftKits());
Init(GetVariantWithDraftKits);
var snapshot = _snapshotService.CreatePublishedSnapshot(previewToken: null);
_snapshotAccessor.PublishedSnapshot = snapshot;
@@ -1008,7 +1058,7 @@ namespace Umbraco.Tests.PublishedContent
yield return CreateInvariantKit(2, 1, 1, paths);
}
Init(GetKits());
Init(GetKits);
var snapshotService = (PublishedSnapshotService)_snapshotService;
var contentStore = snapshotService.GetContentStore();
@@ -1047,7 +1097,7 @@ namespace Umbraco.Tests.PublishedContent
yield return CreateInvariantKit(4, 1, 3, paths);
}
Init(GetKits());
Init(GetKits);
var snapshotService = (PublishedSnapshotService)_snapshotService;
var contentStore = snapshotService.GetContentStore();
@@ -1127,7 +1177,7 @@ namespace Umbraco.Tests.PublishedContent
yield return CreateInvariantKit(40, 1, 3, paths);
}
Init(GetKits());
Init(GetKits);
var snapshotService = (PublishedSnapshotService)_snapshotService;
var contentStore = snapshotService.GetContentStore();
@@ -1199,7 +1249,7 @@ namespace Umbraco.Tests.PublishedContent
}
//init with all published
Init(GetKits());
Init(GetKits);
var snapshotService = (PublishedSnapshotService)_snapshotService;
var contentStore = snapshotService.GetContentStore();
@@ -1216,7 +1266,7 @@ namespace Umbraco.Tests.PublishedContent
//Change the root publish flag
var kit = rootKit.Clone(PublishedModelFactory);
kit.DraftData = published ? null : kit.PublishedData;
kit.PublishedData = published? kit.PublishedData : null;
kit.PublishedData = published ? kit.PublishedData : null;
_source.Kits[1] = kit;
_snapshotService.Notify(new[]
@@ -1269,7 +1319,7 @@ namespace Umbraco.Tests.PublishedContent
yield return CreateInvariantKit(4, 1, 3, paths);
}
Init(GetKits());
Init(GetKits);
var snapshotService = (PublishedSnapshotService)_snapshotService;
var contentStore = snapshotService.GetContentStore();
@@ -1329,14 +1379,13 @@ namespace Umbraco.Tests.PublishedContent
public void MultipleCacheIteration()
{
//see https://github.com/umbraco/Umbraco-CMS/issues/7798
this.Init(this.GetInvariantKits());
Init(GetInvariantKits);
var snapshot = this._snapshotService.CreatePublishedSnapshot(previewToken: null);
this._snapshotAccessor.PublishedSnapshot = snapshot;
_snapshotAccessor.PublishedSnapshot = snapshot;
var items = snapshot.Content.GetByXPath("/root/itype");
Assert.AreEqual(items.Count(), items.Count());
}
private void AssertLinkedNode(ContentNode node, int parent, int prevSibling, int nextSibling, int firstChild, int lastChild)
{
Assert.AreEqual(parent, node.ParentContentId);

View File

@@ -110,8 +110,8 @@ namespace Umbraco.Tests.Services
Assert.AreEqual("Test", rt.Name);
Assert.AreEqual("repeatedEventOccurence", rt.Alias);
Assert.AreEqual(false, rt.IsBidirectional);
Assert.AreEqual(Constants.ObjectTypes.Document, rt.ChildObjectType.Value);
Assert.AreEqual(Constants.ObjectTypes.Media, rt.ParentObjectType.Value);
Assert.AreEqual(Constants.ObjectTypes.Document, rt.ParentObjectType.Value);
Assert.AreEqual(Constants.ObjectTypes.Media, rt.ChildObjectType.Value);
}
[Test]

View File

@@ -142,7 +142,6 @@
<Compile Include="Models\ContentScheduleTests.cs" />
<Compile Include="Models\CultureImpactTests.cs" />
<Compile Include="Models\ImageProcessorImageUrlGeneratorTest.cs" />
<Compile Include="Models\PathValidationTests.cs" />
<Compile Include="Models\VariationTests.cs" />
<Compile Include="Persistence\Mappers\MapperTestBase.cs" />
<Compile Include="Persistence\Repositories\DocumentRepositoryTest.cs" />
@@ -290,7 +289,6 @@
<Compile Include="Migrations\Stubs\FourElevenMigration.cs" />
<Compile Include="Migrations\Stubs\SixZeroMigration2.cs" />
<Compile Include="Testing\TestingTests\MockTests.cs" />
<Compile Include="Models\MacroTests.cs" />
<Compile Include="Models\Collections\Item.cs" />
<Compile Include="Models\Collections\OrderItem.cs" />
<Compile Include="Models\Collections\SimpleOrder.cs" />
@@ -298,7 +296,6 @@
<Compile Include="Models\DeepCloneHelperTests.cs" />
<Compile Include="Models\DictionaryTranslationTests.cs" />
<Compile Include="Models\LightEntityTest.cs" />
<Compile Include="Models\UserTests.cs" />
<Compile Include="Web\Mvc\RenderModelBinderTests.cs" />
<Compile Include="Web\Mvc\SurfaceControllerTests.cs" />
<Compile Include="Web\Mvc\UmbracoViewPageTests.cs" />
@@ -326,7 +323,6 @@
<Compile Include="Clr\ReflectionTests.cs" />
<Compile Include="Macros\MacroParserTests.cs" />
<Compile Include="Models\ContentExtensionsTests.cs" />
<Compile Include="Models\UserExtensionsTests.cs" />
<Compile Include="Web\Mvc\MergeParentContextViewDataAttributeTests.cs" />
<Compile Include="Web\Mvc\ViewDataDictionaryExtensionTests.cs" />
<Compile Include="Persistence\NPocoTests\NPocoBulkInsertTests.cs" />

View File

@@ -342,6 +342,10 @@
<DevelopmentServerPort>9000</DevelopmentServerPort>
<DevelopmentServerVPath>/</DevelopmentServerVPath>
<IISUrl>http://localhost:9000/</IISUrl>
<IISUrl>http://localhost:8700</IISUrl>
<DevelopmentServerPort>8610</DevelopmentServerPort>
<DevelopmentServerVPath>/</DevelopmentServerVPath>
<IISUrl>http://localhost:8610</IISUrl>
<NTLMAuthentication>False</NTLMAuthentication>
<UseCustomServer>False</UseCustomServer>
<CustomServerUrl>