Post merge + Added new SmtpSettingsBuilder

This commit is contained in:
Bjarke Berg
2020-03-18 07:42:35 +01:00
parent 9bf2d650ec
commit 8c8a9764cd
34 changed files with 163 additions and 447 deletions

View File

@@ -1,7 +0,0 @@
namespace Umbraco.Tests.Shared.Builders
{
public abstract class BuilderBase<T>
{
public abstract T Build();
}
}

View File

@@ -1,19 +0,0 @@
namespace Umbraco.Tests.Shared.Builders
{
public abstract class ChildBuilderBase<TParent, TType> : BuilderBase<TType>
{
private readonly TParent _parentBuilder;
protected ChildBuilderBase(TParent parentBuilder)
{
_parentBuilder = parentBuilder;
}
public TParent Done()
{
return _parentBuilder;
}
}
}

View File

@@ -1,33 +0,0 @@
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,
};
}
}
}

View File

@@ -1,54 +0,0 @@
using System.Collections.Generic;
using Moq;
using Umbraco.Core.Logging;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Services;
using Umbraco.Core.Strings;
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 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>()
)
{
DefaultConfiguration = defaultConfiguration,
ExplicitConfigurationEditor = explicitConfigurationEditor,
ExplicitValueEditor = explicitValueEditor
};
}
}
}

View File

@@ -1,160 +0,0 @@
using System;
using Umbraco.Core.Models;
using Umbraco.Tests.Shared.Builders.Interfaces;
namespace Umbraco.Tests.Shared.Builders
{
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 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 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
{
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;
}
}
}

View File

@@ -1,66 +0,0 @@
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,
};
}
}
}

View File

@@ -1,112 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core.Models;
using Umbraco.Tests.Shared.Builders.Interfaces;
namespace Umbraco.Tests.Shared.Builders
{
public class DictionaryItemBuilder
: BuilderBase<DictionaryItem>,
IWithIdBuilder,
IWithCreateDateBuilder,
IWithUpdateDateBuilder,
IWithDeleteDateBuilder,
IWithKeyBuilder
{
private readonly List<DictionaryTranslationBuilder> _translationBuilders =
new List<DictionaryTranslationBuilder>();
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)
{
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);
_translationBuilders.Add(builder);
return builder;
}
public DictionaryItemBuilder WithRandomTranslations(int count)
{
for (var i = 0; i < count; i++)
{
AddTranslation().Done();
}
return this;
}
}
}

View File

@@ -1,90 +0,0 @@
using System;
using Umbraco.Core.Models;
using Umbraco.Tests.Shared.Builders.Interfaces;
namespace Umbraco.Tests.Shared.Builders
{
public class DictionaryTranslationBuilder
: ChildBuilderBase<DictionaryItemBuilder, IDictionaryTranslation>,
IWithIdBuilder,
IWithCreateDateBuilder,
IWithUpdateDateBuilder,
IWithDeleteDateBuilder,
IWithKeyBuilder
{
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;
public DictionaryTranslationBuilder(DictionaryItemBuilder parentBuilder) : base(parentBuilder)
{
_languageBuilder = new LanguageBuilder<DictionaryTranslationBuilder>(this);
}
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 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

@@ -1,50 +0,0 @@
using System;
using Umbraco.Tests.Shared.Builders.Interfaces;
namespace Umbraco.Tests.Shared.Builders.Extensions
{
public static class BuilderExtensions
{
public static T WithId<T>(this T builder, int id)
where T : IWithIdBuilder
{
builder.Id = id;
return builder;
}
public static T WithCreateDate<T>(this T builder, DateTime createDate)
where T : IWithCreateDateBuilder
{
builder.CreateDate = createDate;
return builder;
}
public static T WithUpdateDate<T>(this T builder, DateTime updateDate)
where T : IWithUpdateDateBuilder
{
builder.UpdateDate = updateDate;
return builder;
}
public static T WithAlias<T>(this T builder, string alias)
where T : IWithAliasBuilder
{
builder.Alias = alias;
return builder;
}
public static T WithName<T>(this T builder, string name)
where T : IWithNameBuilder
{
builder.Name = name;
return builder;
}
public static T WithKey<T>(this T builder, Guid key)
where T : IWithKeyBuilder
{
builder.Key = key;
return builder;
}
}
}

View File

@@ -1,224 +0,0 @@
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; }
}
}
}

View File

@@ -1,7 +0,0 @@
namespace Umbraco.Tests.Shared.Builders.Interfaces
{
public interface IWithAliasBuilder
{
string Alias { get; set; }
}
}

View File

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

View File

@@ -1,9 +0,0 @@
using System.Globalization;
namespace Umbraco.Tests.Shared.Builders.Interfaces
{
public interface IWithCultureInfoBuilder
{
CultureInfo CultureInfo { get; set; }
}
}

View File

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

View File

@@ -1,7 +0,0 @@
namespace Umbraco.Tests.Shared.Builders.Interfaces
{
public interface IWithIdBuilder
{
int? Id { get; set; }
}
}

View File

@@ -1,9 +0,0 @@
using System;
namespace Umbraco.Tests.Shared.Builders.Interfaces
{
public interface IWithKeyBuilder
{
Guid? Key { get; set; }
}
}

View File

@@ -1,7 +0,0 @@
namespace Umbraco.Tests.Shared.Builders.Interfaces
{
public interface IWithNameBuilder
{
string Name { get; set; }
}
}

View File

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

View File

@@ -1,120 +0,0 @@
using System;
using System.Globalization;
using Moq;
using Umbraco.Core.Configuration;
using Umbraco.Core.Models;
using Umbraco.Tests.Shared.Builders.Interfaces;
namespace Umbraco.Tests.Shared.Builders
{
public class LanguageBuilder : LanguageBuilder<object>
{
public LanguageBuilder() : base(null)
{
}
}
public class LanguageBuilder<TParent>
: ChildBuilderBase<TParent, ILanguage>,
IWithIdBuilder,
IWithKeyBuilder,
IWithCreateDateBuilder,
IWithUpdateDateBuilder,
IWithDeleteDateBuilder,
IWithCultureInfoBuilder
{
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)
{
}
DateTime? IWithCreateDateBuilder.CreateDate
{
get => _createDate;
set => _createDate = value;
}
CultureInfo IWithCultureInfoBuilder.CultureInfo
{
get => _cultureInfo;
set => _cultureInfo = 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 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

@@ -1,123 +0,0 @@
using System;
using Umbraco.Core.Models;
using Umbraco.Tests.Shared.Builders.Interfaces;
namespace Umbraco.Tests.Shared.Builders
{
public class RelationTypeBuilder : RelationTypeBuilder<object>
{
public RelationTypeBuilder() : base(null)
{
}
}
public class RelationTypeBuilder<TParent>
: ChildBuilderBase<TParent, IRelationType>,
IWithIdBuilder,
IWithAliasBuilder,
IWithNameBuilder,
IWithKeyBuilder,
IWithCreateDateBuilder,
IWithUpdateDateBuilder,
IWithDeleteDateBuilder
{
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 Guid? _parentObjectType;
private DateTime? _updateDate;
public RelationTypeBuilder(TParent parentBuilder) : base(parentBuilder)
{
}
string IWithAliasBuilder.Alias
{
get => _alias;
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;
}
}
}

View File

@@ -27,8 +27,4 @@
<PackageReference Include="Moq" Version="4.13.1" />
</ItemGroup>
<ItemGroup>
<Folder Include="Fakers" />
</ItemGroup>
</Project>