Added more options on the test builders
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
using System.Collections.Generic;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
|
||||
namespace Umbraco.Tests.Shared.Builders
|
||||
{
|
||||
public class ConfigurationEditorBuilder<TParent> : ChildBuilderBase<TParent, IConfigurationEditor>
|
||||
{
|
||||
private IDictionary<string, object> _defaultConfiguration;
|
||||
|
||||
|
||||
public ConfigurationEditorBuilder(TParent parentBuilder) : base(parentBuilder)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public ConfigurationEditorBuilder<TParent> WithDefaultConfiguration(IDictionary<string, object> defaultConfiguration)
|
||||
{
|
||||
_defaultConfiguration = defaultConfiguration;
|
||||
return this;
|
||||
}
|
||||
|
||||
public override IConfigurationEditor Build()
|
||||
{
|
||||
var defaultConfiguration = _defaultConfiguration ?? new Dictionary<string, object>();
|
||||
|
||||
return new ConfigurationEditor()
|
||||
{
|
||||
DefaultConfiguration = defaultConfiguration,
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using Moq;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
@@ -8,21 +9,46 @@ namespace Umbraco.Tests.Shared.Builders
|
||||
{
|
||||
public class DataEditorBuilder<TParent> : ChildBuilderBase<TParent, IDataEditor>
|
||||
{
|
||||
private readonly ConfigurationEditorBuilder<DataEditorBuilder<TParent>> _explicitConfigurationEditorBuilder;
|
||||
private readonly DataValueEditorBuilder<DataEditorBuilder<TParent>> _explicitValueEditorBuilder;
|
||||
private IDictionary<string, object> _defaultConfiguration;
|
||||
|
||||
public DataEditorBuilder(TParent parentBuilder) : base(parentBuilder)
|
||||
{
|
||||
_explicitConfigurationEditorBuilder = new ConfigurationEditorBuilder<DataEditorBuilder<TParent>>(this);
|
||||
_explicitValueEditorBuilder = new DataValueEditorBuilder<DataEditorBuilder<TParent>>(this);
|
||||
}
|
||||
|
||||
public DataEditorBuilder<TParent> WithDefaultConfiguration(IDictionary<string, object> defaultConfiguration)
|
||||
{
|
||||
_defaultConfiguration = defaultConfiguration;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ConfigurationEditorBuilder<DataEditorBuilder<TParent>> AddExplicitConfigurationEditorBuilder() =>
|
||||
_explicitConfigurationEditorBuilder;
|
||||
|
||||
public DataValueEditorBuilder<DataEditorBuilder<TParent>> AddExplicitValueEditorBuilder() =>
|
||||
_explicitValueEditorBuilder;
|
||||
|
||||
public override IDataEditor Build()
|
||||
{
|
||||
var result = new DataEditor(
|
||||
var defaultConfiguration = _defaultConfiguration ?? new Dictionary<string, object>();
|
||||
var explicitConfigurationEditor = _explicitConfigurationEditorBuilder.Build();
|
||||
var explicitValueEditor = _explicitValueEditorBuilder.Build();
|
||||
|
||||
return new DataEditor(
|
||||
Mock.Of<ILogger>(),
|
||||
Mock.Of<IDataTypeService>(),
|
||||
Mock.Of<ILocalizationService>(),
|
||||
Mock.Of<ILocalizedTextService>(),
|
||||
Mock.Of<IShortStringHelper>()
|
||||
);
|
||||
|
||||
return result;
|
||||
)
|
||||
{
|
||||
DefaultConfiguration = defaultConfiguration,
|
||||
ExplicitConfigurationEditor = explicitConfigurationEditor,
|
||||
ExplicitValueEditor = explicitValueEditor
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +1,124 @@
|
||||
using System;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Tests.Shared.Builders.Interfaces;
|
||||
|
||||
namespace Umbraco.Tests.Shared.Builders
|
||||
{
|
||||
public class DataTypeBuilder : BuilderBase<DataType>, IWithIdBuilder
|
||||
public class DataTypeBuilder
|
||||
: BuilderBase<DataType>,
|
||||
IWithIdBuilder,
|
||||
IWithKeyBuilder,
|
||||
IWithCreateDateBuilder,
|
||||
IWithUpdateDateBuilder,
|
||||
IWithDeleteDateBuilder,
|
||||
IWithNameBuilder
|
||||
{
|
||||
private readonly DataEditorBuilder<DataTypeBuilder> _dataEditorBuilder;
|
||||
private int? _id;
|
||||
private int? _parentId;
|
||||
private Guid? _key;
|
||||
private DateTime? _createDate;
|
||||
private DateTime? _updateDate;
|
||||
private DateTime? _deleteDate;
|
||||
private string _name;
|
||||
private bool? _trashed;
|
||||
// private object _configuration;
|
||||
private int? _level;
|
||||
private string _path;
|
||||
private int? _creatorId;
|
||||
private ValueStorageType? _databaseType;
|
||||
private int? _sortOrder;
|
||||
|
||||
public DataTypeBuilder()
|
||||
{
|
||||
_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;
|
||||
}
|
||||
|
||||
public override DataType Build()
|
||||
{
|
||||
var editor = _dataEditorBuilder.Build();
|
||||
var parentId = _parentId ?? -1;
|
||||
var id = _id ?? 1;
|
||||
var result = new DataType(editor)
|
||||
{
|
||||
Id = id
|
||||
};
|
||||
var key = _key ?? Guid.NewGuid();
|
||||
var createDate = _createDate ?? DateTime.Now;
|
||||
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;
|
||||
var databaseType = _databaseType ?? ValueStorageType.Ntext;
|
||||
var sortOrder = _sortOrder ?? 0;
|
||||
|
||||
return result;
|
||||
return new DataType(editor, parentId)
|
||||
{
|
||||
Id = id,
|
||||
Key = key,
|
||||
CreateDate = createDate,
|
||||
UpdateDate = updateDate,
|
||||
DeleteDate = deleteDate,
|
||||
Name = name,
|
||||
Trashed = _trashed ?? false,
|
||||
Level = level,
|
||||
Path = path,
|
||||
CreatorId = creatorId,
|
||||
DatabaseType = databaseType,
|
||||
SortOrder = sortOrder,
|
||||
};
|
||||
}
|
||||
|
||||
int? IWithIdBuilder.Id
|
||||
@@ -30,5 +126,35 @@ namespace Umbraco.Tests.Shared.Builders
|
||||
get => _id;
|
||||
set => _id = value;
|
||||
}
|
||||
|
||||
Guid? IWithKeyBuilder.Key
|
||||
{
|
||||
get => _key;
|
||||
set => _key = value;
|
||||
}
|
||||
|
||||
DateTime? IWithCreateDateBuilder.CreateDate
|
||||
{
|
||||
get => _createDate;
|
||||
set => _createDate = value;
|
||||
}
|
||||
|
||||
DateTime? IWithUpdateDateBuilder.UpdateDate
|
||||
{
|
||||
get => _updateDate;
|
||||
set => _updateDate = value;
|
||||
}
|
||||
|
||||
DateTime? IWithDeleteDateBuilder.DeleteDate
|
||||
{
|
||||
get => _deleteDate;
|
||||
set => _deleteDate = value;
|
||||
}
|
||||
|
||||
string IWithNameBuilder.Name
|
||||
{
|
||||
get => _name;
|
||||
set => _name = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
66
src/Umbraco.Tests.Shared/Builders/DataValueEditorBuilder.cs
Normal file
66
src/Umbraco.Tests.Shared/Builders/DataValueEditorBuilder.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using Moq;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Core.Strings;
|
||||
|
||||
namespace Umbraco.Tests.Shared.Builders
|
||||
{
|
||||
public class DataValueEditorBuilder<TParent> : ChildBuilderBase<TParent, IDataValueEditor>
|
||||
{
|
||||
private string _configuration;
|
||||
private string _view;
|
||||
private bool? _hideLabel;
|
||||
private string _valueType;
|
||||
|
||||
|
||||
public DataValueEditorBuilder(TParent parentBuilder) : base(parentBuilder)
|
||||
{
|
||||
}
|
||||
|
||||
public DataValueEditorBuilder<TParent> WithConfiguration(string configuration)
|
||||
{
|
||||
_configuration = configuration;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DataValueEditorBuilder<TParent> WithView(string view)
|
||||
{
|
||||
_view = view;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DataValueEditorBuilder<TParent> WithHideLabel(bool hideLabel)
|
||||
{
|
||||
_hideLabel = hideLabel;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DataValueEditorBuilder<TParent> WithValueType(string valueType)
|
||||
{
|
||||
_valueType = valueType;
|
||||
return this;
|
||||
}
|
||||
|
||||
public override IDataValueEditor Build()
|
||||
{
|
||||
var configuration = _configuration ?? null;
|
||||
var view = _view ?? null;
|
||||
var hideLabel = _hideLabel ?? false;
|
||||
var valueType = _valueType ?? Guid.NewGuid().ToString();
|
||||
|
||||
return new DataValueEditor(
|
||||
Mock.Of<IDataTypeService>(),
|
||||
Mock.Of<ILocalizationService>(),
|
||||
Mock.Of<ILocalizedTextService>(),
|
||||
Mock.Of<IShortStringHelper>()
|
||||
)
|
||||
{
|
||||
Configuration = configuration,
|
||||
View = view,
|
||||
HideLabel = hideLabel,
|
||||
ValueType = valueType,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,28 +6,90 @@ using Umbraco.Tests.Shared.Builders.Interfaces;
|
||||
|
||||
namespace Umbraco.Tests.Shared.Builders
|
||||
{
|
||||
public class DictionaryItemBuilder : IWithIdBuilder, IWithCreateDateBuilder, IWithUpdateDateBuilder
|
||||
public class DictionaryItemBuilder
|
||||
: BuilderBase<DictionaryItem>,
|
||||
IWithIdBuilder,
|
||||
IWithCreateDateBuilder,
|
||||
IWithUpdateDateBuilder,
|
||||
IWithDeleteDateBuilder,
|
||||
IWithKeyBuilder
|
||||
{
|
||||
private string _itemkey = null;
|
||||
private readonly List<DictionaryTranslationBuilder> _translationBuilders = new List<DictionaryTranslationBuilder>();
|
||||
private DateTime? _createDate;
|
||||
private DateTime? _updateDate;
|
||||
private int? _id = null;
|
||||
private readonly List<DictionaryTranslationBuilder> _translationBuilders =
|
||||
new List<DictionaryTranslationBuilder>();
|
||||
|
||||
public DictionaryItem Build()
|
||||
private DateTime? _createDate;
|
||||
private DateTime? _deleteDate;
|
||||
private int? _id;
|
||||
private string _itemKey;
|
||||
private Guid? _key;
|
||||
private Guid? _parentId;
|
||||
private DateTime? _updateDate;
|
||||
|
||||
DateTime? IWithCreateDateBuilder.CreateDate
|
||||
{
|
||||
get => _createDate;
|
||||
set => _createDate = value;
|
||||
}
|
||||
|
||||
DateTime? IWithDeleteDateBuilder.DeleteDate
|
||||
{
|
||||
get => _deleteDate;
|
||||
set => _deleteDate = value;
|
||||
}
|
||||
|
||||
int? IWithIdBuilder.Id
|
||||
{
|
||||
get => _id;
|
||||
set => _id = value;
|
||||
}
|
||||
|
||||
Guid? IWithKeyBuilder.Key
|
||||
{
|
||||
get => _key;
|
||||
set => _key = value;
|
||||
}
|
||||
|
||||
DateTime? IWithUpdateDateBuilder.UpdateDate
|
||||
{
|
||||
get => _updateDate;
|
||||
set => _updateDate = value;
|
||||
}
|
||||
|
||||
public override DictionaryItem 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 parentId = _parentId ?? null;
|
||||
var itemKey = _itemKey ?? Guid.NewGuid().ToString();
|
||||
|
||||
var result = new DictionaryItem(_itemkey ?? Guid.NewGuid().ToString());
|
||||
result.Translations = _translationBuilders.Select(x => x.Build());
|
||||
result.CreateDate = createDate;
|
||||
result.UpdateDate = updateDate;
|
||||
result.Id = id;
|
||||
var result = new DictionaryItem(itemKey)
|
||||
{
|
||||
Translations = _translationBuilders.Select(x => x.Build()),
|
||||
CreateDate = createDate,
|
||||
UpdateDate = updateDate,
|
||||
DeleteDate = deleteDate,
|
||||
Id = id,
|
||||
ParentId = parentId,
|
||||
Key = key,
|
||||
};
|
||||
return result;
|
||||
}
|
||||
|
||||
public DictionaryItemBuilder WithParentId(Guid parentId)
|
||||
{
|
||||
_parentId = parentId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DictionaryItemBuilder WithItemKey(string itemKey)
|
||||
{
|
||||
_itemKey = itemKey;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DictionaryTranslationBuilder AddTranslation()
|
||||
{
|
||||
var builder = new DictionaryTranslationBuilder(this);
|
||||
@@ -43,25 +105,8 @@ namespace Umbraco.Tests.Shared.Builders
|
||||
{
|
||||
AddTranslation().Done();
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
int? IWithIdBuilder.Id
|
||||
{
|
||||
get => _id;
|
||||
set => _id = value;
|
||||
}
|
||||
|
||||
DateTime? IWithCreateDateBuilder.CreateDate
|
||||
{
|
||||
get => _createDate;
|
||||
set => _createDate = value;
|
||||
}
|
||||
|
||||
DateTime? IWithUpdateDateBuilder.UpdateDate
|
||||
{
|
||||
get => _updateDate;
|
||||
set => _updateDate = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,56 +4,27 @@ using Umbraco.Tests.Shared.Builders.Interfaces;
|
||||
|
||||
namespace Umbraco.Tests.Shared.Builders
|
||||
{
|
||||
public class DictionaryTranslationBuilder : ChildBuilderBase<DictionaryItemBuilder,IDictionaryTranslation>, IWithIdBuilder, IWithCreateDateBuilder, IWithUpdateDateBuilder
|
||||
public class DictionaryTranslationBuilder
|
||||
: ChildBuilderBase<DictionaryItemBuilder, IDictionaryTranslation>,
|
||||
IWithIdBuilder,
|
||||
IWithCreateDateBuilder,
|
||||
IWithUpdateDateBuilder,
|
||||
IWithDeleteDateBuilder,
|
||||
IWithKeyBuilder
|
||||
{
|
||||
private string _value = null;
|
||||
private Guid? _uniqueId = null;
|
||||
private readonly LanguageBuilder<DictionaryTranslationBuilder> _languageBuilder;
|
||||
private readonly Guid? _uniqueId = null;
|
||||
private DateTime? _createDate;
|
||||
private DateTime? _deleteDate;
|
||||
private int? _id;
|
||||
private Guid? _key;
|
||||
private DateTime? _updateDate;
|
||||
private string _value;
|
||||
|
||||
|
||||
private LanguageBuilder<DictionaryTranslationBuilder> _languageBuilder;
|
||||
private int? _id = null;
|
||||
|
||||
public DictionaryTranslationBuilder(DictionaryItemBuilder parentBuilder) : base(parentBuilder)
|
||||
{
|
||||
_languageBuilder = new LanguageBuilder<DictionaryTranslationBuilder>(this);
|
||||
|
||||
}
|
||||
|
||||
public override IDictionaryTranslation Build()
|
||||
{
|
||||
var createDate = _createDate ?? DateTime.Now;
|
||||
var updateDate = _updateDate ?? DateTime.Now;
|
||||
var id = _id ?? 1;
|
||||
|
||||
var result = new DictionaryTranslation(
|
||||
_languageBuilder.Build(),
|
||||
_value ?? Guid.NewGuid().ToString(),
|
||||
_uniqueId ?? Guid.NewGuid());
|
||||
|
||||
result.CreateDate = createDate;
|
||||
result.UpdateDate = updateDate;
|
||||
result.Id = id;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public LanguageBuilder<DictionaryTranslationBuilder> WithLanguage()
|
||||
{
|
||||
return _languageBuilder;
|
||||
}
|
||||
|
||||
public DictionaryTranslationBuilder WithValue(string value)
|
||||
{
|
||||
_value = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
int? IWithIdBuilder.Id
|
||||
{
|
||||
get => _id;
|
||||
set => _id = value;
|
||||
}
|
||||
|
||||
DateTime? IWithCreateDateBuilder.CreateDate
|
||||
@@ -62,10 +33,58 @@ namespace Umbraco.Tests.Shared.Builders
|
||||
set => _createDate = value;
|
||||
}
|
||||
|
||||
DateTime? IWithDeleteDateBuilder.DeleteDate
|
||||
{
|
||||
get => _deleteDate;
|
||||
set => _deleteDate = value;
|
||||
}
|
||||
|
||||
int? IWithIdBuilder.Id
|
||||
{
|
||||
get => _id;
|
||||
set => _id = value;
|
||||
}
|
||||
|
||||
Guid? IWithKeyBuilder.Key
|
||||
{
|
||||
get => _key;
|
||||
set => _key = value;
|
||||
}
|
||||
|
||||
DateTime? IWithUpdateDateBuilder.UpdateDate
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,5 +39,12 @@ namespace Umbraco.Tests.Shared.Builders.Extensions
|
||||
builder.Name = name;
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static T WithKey<T>(this T builder, Guid key)
|
||||
where T : IWithKeyBuilder
|
||||
{
|
||||
builder.Key = key;
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
224
src/Umbraco.Tests.Shared/Builders/GlobalSettingsBuilder.cs
Normal file
224
src/Umbraco.Tests.Shared/Builders/GlobalSettingsBuilder.cs
Normal file
@@ -0,0 +1,224 @@
|
||||
using Umbraco.Core.Configuration;
|
||||
|
||||
namespace Umbraco.Tests.Shared.Builders
|
||||
{
|
||||
public class GlobalSettingsBuilder : GlobalSettingsBuilder<object>
|
||||
{
|
||||
public GlobalSettingsBuilder() : base(null)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class GlobalSettingsBuilder<TParent> : ChildBuilderBase<TParent, IGlobalSettings>
|
||||
|
||||
{
|
||||
private string _configurationStatus;
|
||||
private string _databaseFactoryServerVersion;
|
||||
private string _defaultUiLanguage;
|
||||
private bool? _disableElectionForSingleServer;
|
||||
private bool? _hideTopLevelNodeFromPath;
|
||||
private bool? _installEmptyDatabase;
|
||||
private bool? _installMissingDatabase;
|
||||
private bool? _isSmtpServerConfigured;
|
||||
private string _path;
|
||||
private string _registerType;
|
||||
private string _reservedPaths;
|
||||
private string _reservedUrls;
|
||||
private int? _timeOutInMinutes;
|
||||
private string _umbracoCssPath;
|
||||
private string _umbracoMediaPath;
|
||||
private string _umbracoPath;
|
||||
private string _umbracoScriptsPath;
|
||||
private bool? _useHttps;
|
||||
private int? _versionCheckPeriod;
|
||||
|
||||
|
||||
public GlobalSettingsBuilder(TParent parentBuilder) : base(parentBuilder)
|
||||
{
|
||||
}
|
||||
|
||||
public GlobalSettingsBuilder<TParent> WithConfigurationStatus(string configurationStatus)
|
||||
{
|
||||
_configurationStatus = configurationStatus;
|
||||
return this;
|
||||
}
|
||||
|
||||
public GlobalSettingsBuilder<TParent> WithDatabaseFactoryServerVersion(string databaseFactoryServerVersion)
|
||||
{
|
||||
_databaseFactoryServerVersion = databaseFactoryServerVersion;
|
||||
return this;
|
||||
}
|
||||
|
||||
public GlobalSettingsBuilder<TParent> WithDefaultUiLanguage(string defaultUiLanguage)
|
||||
{
|
||||
_defaultUiLanguage = defaultUiLanguage;
|
||||
return this;
|
||||
}
|
||||
|
||||
public GlobalSettingsBuilder<TParent> WithDisableElectionForSingleServer(bool disableElectionForSingleServer)
|
||||
{
|
||||
_disableElectionForSingleServer = disableElectionForSingleServer;
|
||||
return this;
|
||||
}
|
||||
|
||||
public GlobalSettingsBuilder<TParent> WithHideTopLevelNodeFromPath(bool hideTopLevelNodeFromPath)
|
||||
{
|
||||
_hideTopLevelNodeFromPath = hideTopLevelNodeFromPath;
|
||||
return this;
|
||||
}
|
||||
|
||||
public GlobalSettingsBuilder<TParent> WithInstallEmptyDatabase(bool installEmptyDatabase)
|
||||
{
|
||||
_installEmptyDatabase = installEmptyDatabase;
|
||||
return this;
|
||||
}
|
||||
|
||||
public GlobalSettingsBuilder<TParent> WithInstallMissingDatabase(bool installMissingDatabase)
|
||||
{
|
||||
_installMissingDatabase = installMissingDatabase;
|
||||
return this;
|
||||
}
|
||||
|
||||
public GlobalSettingsBuilder<TParent> WithIsSmtpServerConfigured(bool isSmtpServerConfigured)
|
||||
{
|
||||
_isSmtpServerConfigured = isSmtpServerConfigured;
|
||||
return this;
|
||||
}
|
||||
|
||||
public GlobalSettingsBuilder<TParent> WithPath(string path)
|
||||
{
|
||||
_path = path;
|
||||
return this;
|
||||
}
|
||||
|
||||
public GlobalSettingsBuilder<TParent> WithRegisterType(string registerType)
|
||||
{
|
||||
_registerType = registerType;
|
||||
return this;
|
||||
}
|
||||
|
||||
public GlobalSettingsBuilder<TParent> WithReservedPaths(string reservedPaths)
|
||||
{
|
||||
_reservedPaths = reservedPaths;
|
||||
return this;
|
||||
}
|
||||
|
||||
public GlobalSettingsBuilder<TParent> WithReservedUrls(string reservedUrls)
|
||||
{
|
||||
_reservedUrls = reservedUrls;
|
||||
return this;
|
||||
}
|
||||
|
||||
public GlobalSettingsBuilder<TParent> WithUmbracoPath(string umbracoPath)
|
||||
{
|
||||
_umbracoPath = umbracoPath;
|
||||
return this;
|
||||
}
|
||||
|
||||
public GlobalSettingsBuilder<TParent> WithUseHttps(bool useHttps)
|
||||
{
|
||||
_useHttps = useHttps;
|
||||
return this;
|
||||
}
|
||||
|
||||
public GlobalSettingsBuilder<TParent> WithUmbracoCssPath(string umbracoCssPath)
|
||||
{
|
||||
_umbracoCssPath = umbracoCssPath;
|
||||
return this;
|
||||
}
|
||||
|
||||
public GlobalSettingsBuilder<TParent> WithUmbracoMediaPath(string umbracoMediaPath)
|
||||
{
|
||||
_umbracoMediaPath = umbracoMediaPath;
|
||||
return this;
|
||||
}
|
||||
|
||||
public GlobalSettingsBuilder<TParent> WithUmbracoScriptsPath(string umbracoScriptsPath)
|
||||
{
|
||||
_umbracoScriptsPath = umbracoScriptsPath;
|
||||
return this;
|
||||
}
|
||||
|
||||
public GlobalSettingsBuilder<TParent> WithVersionCheckPeriod(int versionCheckPeriod)
|
||||
{
|
||||
_versionCheckPeriod = versionCheckPeriod;
|
||||
return this;
|
||||
}
|
||||
|
||||
public GlobalSettingsBuilder<TParent> WithTimeOutInMinutes(int timeOutInMinutes)
|
||||
{
|
||||
_timeOutInMinutes = timeOutInMinutes;
|
||||
return this;
|
||||
}
|
||||
|
||||
public override IGlobalSettings Build()
|
||||
{
|
||||
var configurationStatus = _configurationStatus ?? "9.0.0";
|
||||
var databaseFactoryServerVersion = _databaseFactoryServerVersion ?? null;
|
||||
var defaultUiLanguage = _defaultUiLanguage ?? "en";
|
||||
var disableElectionForSingleServer = _disableElectionForSingleServer ?? false;
|
||||
var hideTopLevelNodeFromPath = _hideTopLevelNodeFromPath ?? false;
|
||||
var installEmptyDatabase = _installEmptyDatabase ?? false;
|
||||
var installMissingDatabase = _installMissingDatabase ?? false;
|
||||
var isSmtpServerConfigured = _isSmtpServerConfigured ?? false;
|
||||
var path = _path ?? "/umbraco";
|
||||
var registerType = _registerType ?? null;
|
||||
var reservedPaths = _reservedPaths ?? "~/app_plugins/,~/install/,~/mini-profiler-resources/,";
|
||||
var reservedUrls = _reservedUrls ?? "~/config/splashes/noNodes.aspx,~/.well-known,";
|
||||
var umbracoPath = _umbracoPath ?? "~/umbraco";
|
||||
var useHttps = _useHttps ?? false;
|
||||
var umbracoCssPath = _umbracoCssPath ?? "~/css";
|
||||
var umbracoMediaPath = _umbracoMediaPath ?? "~/media";
|
||||
var umbracoScriptsPath = _umbracoScriptsPath ?? "~/scripts";
|
||||
var versionCheckPeriod = _versionCheckPeriod ?? 0;
|
||||
var timeOutInMinutes = _timeOutInMinutes ?? 20;
|
||||
|
||||
|
||||
return new TestGlobalSettings
|
||||
{
|
||||
ConfigurationStatus = configurationStatus,
|
||||
DatabaseFactoryServerVersion = databaseFactoryServerVersion,
|
||||
DefaultUILanguage = defaultUiLanguage,
|
||||
DisableElectionForSingleServer = disableElectionForSingleServer,
|
||||
HideTopLevelNodeFromPath = hideTopLevelNodeFromPath,
|
||||
InstallEmptyDatabase = installEmptyDatabase,
|
||||
InstallMissingDatabase = installMissingDatabase,
|
||||
IsSmtpServerConfigured = isSmtpServerConfigured,
|
||||
Path = path,
|
||||
RegisterType = registerType,
|
||||
ReservedPaths = reservedPaths,
|
||||
ReservedUrls = reservedUrls,
|
||||
UmbracoPath = umbracoPath,
|
||||
UseHttps = useHttps,
|
||||
UmbracoCssPath = umbracoCssPath,
|
||||
UmbracoMediaPath = umbracoMediaPath,
|
||||
UmbracoScriptsPath = umbracoScriptsPath,
|
||||
VersionCheckPeriod = versionCheckPeriod,
|
||||
TimeOutInMinutes = timeOutInMinutes
|
||||
};
|
||||
}
|
||||
|
||||
private class TestGlobalSettings : IGlobalSettings
|
||||
{
|
||||
public string ReservedUrls { get; set; }
|
||||
public string ReservedPaths { get; set; }
|
||||
public string Path { get; set; }
|
||||
public string ConfigurationStatus { get; set; }
|
||||
public int TimeOutInMinutes { get; set; }
|
||||
public string DefaultUILanguage { get; set; }
|
||||
public bool HideTopLevelNodeFromPath { get; set; }
|
||||
public bool UseHttps { get; set; }
|
||||
public int VersionCheckPeriod { get; set; }
|
||||
public string UmbracoPath { get; set; }
|
||||
public string UmbracoCssPath { get; set; }
|
||||
public string UmbracoScriptsPath { get; set; }
|
||||
public string UmbracoMediaPath { get; set; }
|
||||
public bool IsSmtpServerConfigured { get; set; }
|
||||
public bool InstallMissingDatabase { get; set; }
|
||||
public bool InstallEmptyDatabase { get; set; }
|
||||
public bool DisableElectionForSingleServer { get; set; }
|
||||
public string RegisterType { get; set; }
|
||||
public string DatabaseFactoryServerVersion { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using System.Globalization;
|
||||
|
||||
namespace Umbraco.Tests.Shared.Builders.Interfaces
|
||||
{
|
||||
public interface IWithCultureInfoBuilder
|
||||
{
|
||||
CultureInfo CultureInfo { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using System;
|
||||
|
||||
namespace Umbraco.Tests.Shared.Builders.Interfaces
|
||||
{
|
||||
public interface IWithDeleteDateBuilder
|
||||
{
|
||||
DateTime? DeleteDate { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using System;
|
||||
|
||||
namespace Umbraco.Tests.Shared.Builders.Interfaces
|
||||
{
|
||||
public interface IWithKeyBuilder
|
||||
{
|
||||
Guid? Key { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using Moq;
|
||||
using Umbraco.Core.Configuration;
|
||||
@@ -13,27 +14,45 @@ namespace Umbraco.Tests.Shared.Builders
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class LanguageBuilder<TParent> : ChildBuilderBase<TParent, ILanguage>, IWithIdBuilder
|
||||
public class LanguageBuilder<TParent>
|
||||
: ChildBuilderBase<TParent, ILanguage>,
|
||||
IWithIdBuilder,
|
||||
IWithKeyBuilder,
|
||||
IWithCreateDateBuilder,
|
||||
IWithUpdateDateBuilder,
|
||||
IWithDeleteDateBuilder,
|
||||
IWithCultureInfoBuilder
|
||||
{
|
||||
|
||||
private string _isoCode = null;
|
||||
private DateTime? _createDate;
|
||||
private CultureInfo _cultureInfo;
|
||||
private DateTime? _deleteDate;
|
||||
private int? _fallbackLanguageId;
|
||||
private int? _id;
|
||||
private bool? _isDefault;
|
||||
private bool? _isMandatory;
|
||||
private Guid? _key;
|
||||
private DateTime? _updateDate;
|
||||
|
||||
public LanguageBuilder(TParent parentBuilder) : base(parentBuilder)
|
||||
{
|
||||
}
|
||||
|
||||
public override ILanguage Build()
|
||||
DateTime? IWithCreateDateBuilder.CreateDate
|
||||
{
|
||||
var culture = CultureInfo.GetCultureInfo("en-US");
|
||||
var isoCode = _isoCode ?? culture.Name;
|
||||
return new Language(Mock.Of<IGlobalSettings>(), isoCode)
|
||||
{
|
||||
Id = _id ?? 1,
|
||||
CultureName = culture.TwoLetterISOLanguageName,
|
||||
IsoCode = new RegionInfo(culture.LCID).Name,
|
||||
};
|
||||
get => _createDate;
|
||||
set => _createDate = value;
|
||||
}
|
||||
|
||||
CultureInfo IWithCultureInfoBuilder.CultureInfo
|
||||
{
|
||||
get => _cultureInfo;
|
||||
set => _cultureInfo = value;
|
||||
}
|
||||
|
||||
DateTime? IWithDeleteDateBuilder.DeleteDate
|
||||
{
|
||||
get => _deleteDate;
|
||||
set => _deleteDate = value;
|
||||
}
|
||||
|
||||
int? IWithIdBuilder.Id
|
||||
@@ -41,5 +60,61 @@ namespace Umbraco.Tests.Shared.Builders
|
||||
get => _id;
|
||||
set => _id = value;
|
||||
}
|
||||
|
||||
Guid? IWithKeyBuilder.Key
|
||||
{
|
||||
get => _key;
|
||||
set => _key = value;
|
||||
}
|
||||
|
||||
DateTime? IWithUpdateDateBuilder.UpdateDate
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ using Umbraco.Tests.Shared.Builders.Interfaces;
|
||||
|
||||
namespace Umbraco.Tests.Shared.Builders
|
||||
{
|
||||
|
||||
public class RelationTypeBuilder : RelationTypeBuilder<object>
|
||||
{
|
||||
public RelationTypeBuilder() : base(null)
|
||||
@@ -12,39 +11,30 @@ namespace Umbraco.Tests.Shared.Builders
|
||||
}
|
||||
}
|
||||
|
||||
public class RelationTypeBuilder<TParent> : ChildBuilderBase<TParent, IRelationType>, IWithIdBuilder, IWithAliasBuilder, IWithNameBuilder
|
||||
public class RelationTypeBuilder<TParent>
|
||||
: ChildBuilderBase<TParent, IRelationType>,
|
||||
IWithIdBuilder,
|
||||
IWithAliasBuilder,
|
||||
IWithNameBuilder,
|
||||
IWithKeyBuilder,
|
||||
IWithCreateDateBuilder,
|
||||
IWithUpdateDateBuilder,
|
||||
IWithDeleteDateBuilder
|
||||
{
|
||||
private int? _id;
|
||||
private string _alias;
|
||||
private Guid? _childObjectType;
|
||||
private DateTime? _createDate;
|
||||
private DateTime? _deleteDate;
|
||||
private int? _id;
|
||||
private bool? _isBidirectional;
|
||||
private Guid? _key;
|
||||
private string _name;
|
||||
private readonly Guid? _parentObjectType = null;
|
||||
private readonly Guid? _childObjectType = null;
|
||||
private Guid? _parentObjectType;
|
||||
private DateTime? _updateDate;
|
||||
|
||||
public RelationTypeBuilder(TParent parentBuilder) : base(parentBuilder)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public override IRelationType Build()
|
||||
{
|
||||
var alias = _alias ?? Guid.NewGuid().ToString();
|
||||
var name = _name ?? Guid.NewGuid().ToString();
|
||||
var parentObjectType = _parentObjectType ?? Guid.NewGuid();
|
||||
var childObjectType = _childObjectType ?? Guid.NewGuid();
|
||||
var id = _id ?? 1;
|
||||
|
||||
return new RelationType(name, alias, false, parentObjectType,
|
||||
childObjectType)
|
||||
{
|
||||
Id = id
|
||||
};
|
||||
}
|
||||
|
||||
int? IWithIdBuilder.Id
|
||||
{
|
||||
get => _id;
|
||||
set => _id = value;
|
||||
}
|
||||
|
||||
string IWithAliasBuilder.Alias
|
||||
{
|
||||
@@ -52,10 +42,82 @@ namespace Umbraco.Tests.Shared.Builders
|
||||
set => _alias = value;
|
||||
}
|
||||
|
||||
DateTime? IWithCreateDateBuilder.CreateDate
|
||||
{
|
||||
get => _createDate;
|
||||
set => _createDate = value;
|
||||
}
|
||||
|
||||
DateTime? IWithDeleteDateBuilder.DeleteDate
|
||||
{
|
||||
get => _deleteDate;
|
||||
set => _deleteDate = value;
|
||||
}
|
||||
|
||||
int? IWithIdBuilder.Id
|
||||
{
|
||||
get => _id;
|
||||
set => _id = value;
|
||||
}
|
||||
|
||||
Guid? IWithKeyBuilder.Key
|
||||
{
|
||||
get => _key;
|
||||
set => _key = value;
|
||||
}
|
||||
|
||||
string IWithNameBuilder.Name
|
||||
{
|
||||
get => _name;
|
||||
set => _name = value;
|
||||
}
|
||||
|
||||
DateTime? IWithUpdateDateBuilder.UpdateDate
|
||||
{
|
||||
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<TParent> WithIsBidirectional(bool isBidirectional)
|
||||
{
|
||||
_isBidirectional = isBidirectional;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RelationTypeBuilder<TParent> WithChildObjectType(Guid childObjectType)
|
||||
{
|
||||
_childObjectType = childObjectType;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RelationTypeBuilder<TParent> WithParentObjectType(Guid parentObjectType)
|
||||
{
|
||||
_parentObjectType = parentObjectType;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Umbraco.Abstractions\Umbraco.Abstractions.csproj" />
|
||||
<ProjectReference Include="..\Umbraco.Configuration\Umbraco.Configuration.csproj" />
|
||||
<ProjectReference Include="..\Umbraco.Infrastructure\Umbraco.Infrastructure.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Tests.Shared.Builders;
|
||||
using Umbraco.Tests.Shared.Builders.Extensions;
|
||||
|
||||
namespace Umbraco.Tests.UnitTests.Umbraco.Infrastructure.Models
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Tests.Shared.Builders;
|
||||
@@ -13,7 +14,10 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Infrastructure.Models
|
||||
[Test]
|
||||
public void Can_Deep_Clone()
|
||||
{
|
||||
var item = _builder.Build();
|
||||
var item = _builder
|
||||
.WithParentObjectType(Guid.NewGuid())
|
||||
.WithChildObjectType(Guid.NewGuid())
|
||||
.Build();
|
||||
|
||||
var clone = (RelationType) item.DeepClone();
|
||||
|
||||
@@ -21,11 +25,13 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Infrastructure.Models
|
||||
Assert.AreEqual(clone, item);
|
||||
Assert.AreEqual(clone.Alias, item.Alias);
|
||||
Assert.AreEqual(clone.ChildObjectType, item.ChildObjectType);
|
||||
Assert.AreEqual(clone.ParentObjectType, item.ParentObjectType);
|
||||
Assert.AreEqual(clone.IsBidirectional, item.IsBidirectional);
|
||||
Assert.AreEqual(clone.Id, item.Id);
|
||||
Assert.AreEqual(clone.Key, item.Key);
|
||||
Assert.AreEqual(clone.Name, item.Name);
|
||||
Assert.AreNotSame(clone.ParentObjectType, item.ParentObjectType);
|
||||
Assert.AreNotSame(clone.ChildObjectType, item.ChildObjectType);
|
||||
Assert.AreEqual(clone.UpdateDate, item.UpdateDate);
|
||||
|
||||
//This double verifies by reflection
|
||||
|
||||
Reference in New Issue
Block a user