Introduced a reset of the unit test builders to support re-use within a test.

This commit is contained in:
Andy Butland
2020-04-12 09:47:44 +02:00
parent a5aa1e19a5
commit f961916245
26 changed files with 513 additions and 195 deletions
@@ -3,5 +3,7 @@ namespace Umbraco.Tests.Common.Builders
public abstract class BuilderBase<T>
{
public abstract T Build();
protected abstract void Reset();
}
}
@@ -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;
@@ -23,11 +21,16 @@ namespace Umbraco.Tests.Common.Builders
{
var defaultConfiguration = _defaultConfiguration ?? new Dictionary<string, object>();
Reset();
return new ConfigurationEditor()
{
DefaultConfiguration = defaultConfiguration,
};
}
protected override void Reset()
{
_defaultConfiguration = null;
}
}
}
@@ -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)
@@ -37,6 +37,7 @@ namespace Umbraco.Tests.Common.Builders
var explicitConfigurationEditor = _explicitConfigurationEditorBuilder.Build();
var explicitValueEditor = _explicitValueEditorBuilder.Build();
Reset();
return new DataEditor(
Mock.Of<ILogger>(),
Mock.Of<IDataTypeService>(),
@@ -50,5 +51,12 @@ namespace Umbraco.Tests.Common.Builders
ExplicitValueEditor = explicitValueEditor
};
}
protected override void Reset()
{
_defaultConfiguration = null;
_explicitConfigurationEditorBuilder = new ConfigurationEditorBuilder<DataEditorBuilder<TParent>>(this);
_explicitValueEditorBuilder = new DataValueEditorBuilder<DataEditorBuilder<TParent>>(this);
}
}
}
@@ -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,13 +60,13 @@ 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;
var databaseType = _databaseType ?? ValueStorageType.Ntext;
var sortOrder = _sortOrder ?? 0;
Reset();
return new DataType(editor, parentId)
{
Id = id,
@@ -91,6 +84,24 @@ namespace Umbraco.Tests.Common.Builders
};
}
protected override void Reset()
{
_dataEditorBuilder = new DataEditorBuilder<DataTypeBuilder>(this);
_id = null;
_parentId = null;
_key = null;
_createDate = null;
_updateDate = null;
_deleteDate = null;
_name = null;
_trashed = null;
_level = null;
_path = null;
_creatorId = null;
_databaseType = null;
_sortOrder = null;
}
int? IWithIdBuilder.Id
{
get => _id;
@@ -13,7 +13,6 @@ namespace Umbraco.Tests.Common.Builders
private bool? _hideLabel;
private string _valueType;
public DataValueEditorBuilder(TParent parentBuilder) : base(parentBuilder)
{
}
@@ -49,6 +48,7 @@ namespace Umbraco.Tests.Common.Builders
var hideLabel = _hideLabel ?? false;
var valueType = _valueType ?? Guid.NewGuid().ToString();
Reset();
return new DataValueEditor(
Mock.Of<IDataTypeService>(),
Mock.Of<ILocalizationService>(),
@@ -62,5 +62,13 @@ namespace Umbraco.Tests.Common.Builders
ValueType = valueType,
};
}
protected override void Reset()
{
_configuration = null;
_view = null;
_hideLabel = null;
_valueType = null;
}
}
}
@@ -65,6 +65,7 @@ namespace Umbraco.Tests.Common.Builders
var parentId = _parentId ?? null;
var itemKey = _itemKey ?? Guid.NewGuid().ToString();
Reset();
var result = new DictionaryItem(itemKey)
{
Translations = _translationBuilders.Select(x => x.Build()),
@@ -78,6 +79,17 @@ namespace Umbraco.Tests.Common.Builders
return result;
}
protected override void Reset()
{
_createDate = null;
_deleteDate = null;
_id = null;
_itemKey = null;
_key = null;
_parentId = null;
_updateDate = null;
}
public DictionaryItemBuilder WithParentId(Guid parentId)
{
_parentId = parentId;
@@ -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,48 @@ 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
};
Reset();
return result;
}
protected override void Reset()
{
_languageBuilder = new LanguageBuilder<DictionaryTranslationBuilder>(this);
_createDate = null;
_deleteDate = null;
_id = null;
_key = null;
_updateDate = null;
_value = null;
}
DateTime? IWithCreateDateBuilder.CreateDate
{
get => _createDate;
@@ -55,35 +96,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;
}
}
}
@@ -16,6 +16,7 @@ namespace Umbraco.Tests.Common.Builders
var id = _id ?? 1;
var parentId = _parentId ?? -1;
Reset();
return new EntitySlim
{
Id = id,
@@ -23,6 +24,12 @@ namespace Umbraco.Tests.Common.Builders
};
}
protected override void Reset()
{
_id = null;
_parentId = null;
}
public EntitySlimBuilder WithNoParentId()
{
_parentId = 0;
@@ -1,24 +1,36 @@
using System.Collections.Generic;
using System.Linq;
namespace Umbraco.Tests.Common.Builders
{
public class GenericCollectionBuilder<TBuilder, T>
: ChildBuilderBase<TBuilder, IEnumerable<T>>
{
private readonly IList<T> _collection;
private IList<T> _collection;
public GenericCollectionBuilder(TBuilder parentBuilder) : base(parentBuilder)
{
_collection = new List<T>();
}
public override IEnumerable<T> Build()
{
return _collection;
var collection = _collection?.ToList() ?? Enumerable.Empty<T>();
Reset();
return collection;
}
protected override void Reset()
{
_collection = null;
}
public GenericCollectionBuilder<TBuilder, T> WithValue(T value)
{
if (_collection == null)
{
_collection = new List<T>();
}
_collection.Add(value);
return this;
}
@@ -5,20 +5,34 @@ namespace Umbraco.Tests.Common.Builders
public class GenericDictionaryBuilder<TBuilder, TKey, TValue>
: ChildBuilderBase<TBuilder, IDictionary<TKey, TValue>>
{
private readonly IDictionary<TKey, TValue> _dictionary;
private IDictionary<TKey, TValue> _dictionary;
public GenericDictionaryBuilder(TBuilder parentBuilder) : base(parentBuilder)
{
_dictionary = new Dictionary<TKey, TValue>();
}
public override IDictionary<TKey, TValue> Build()
{
return _dictionary;
var dictionary = _dictionary == null
? new Dictionary<TKey, TValue>()
: new Dictionary<TKey, TValue>(_dictionary);
Reset();
return dictionary;
}
protected override void Reset()
{
_dictionary = null;
}
public GenericDictionaryBuilder<TBuilder, TKey, TValue> WithKeyValue(TKey key, TValue value)
{
if (_dictionary == null)
{
_dictionary = new Dictionary<TKey, TValue>();
}
_dictionary.Add(key, value);
return this;
}
@@ -32,8 +32,7 @@ namespace Umbraco.Tests.Common.Builders
private string _noNodesViewPath;
private bool? _useHttps;
private int? _versionCheckPeriod;
private readonly SmtpSettingsBuilder<GlobalSettingsBuilder<TParent>> _smtpSettingsBuilder;
private SmtpSettingsBuilder<GlobalSettingsBuilder<TParent>> _smtpSettingsBuilder;
public GlobalSettingsBuilder(TParent parentBuilder) : base(parentBuilder)
{
@@ -192,7 +191,7 @@ namespace Umbraco.Tests.Common.Builders
var mainDomLock = _mainDomLock ?? string.Empty;
var noNodesViewPath = _noNodesViewPath ?? "~/config/splashes/NoNodes.cshtml";
Reset();
return new TestGlobalSettings
{
ConfigurationStatus = configurationStatus,
@@ -220,6 +219,32 @@ namespace Umbraco.Tests.Common.Builders
};
}
protected override void Reset()
{
_configurationStatus = null;
_databaseFactoryServerVersion = null;
_defaultUiLanguage = null;
_disableElectionForSingleServer = null;
_hideTopLevelNodeFromPath = null;
_installEmptyDatabase = null;
_installMissingDatabase = null;
_isSmtpServerConfigured = null;
_path = null;
_registerType = null;
_reservedPaths = null;
_reservedUrls = null;
_timeOutInMinutes = null;
_umbracoCssPath = null;
_umbracoMediaPath = null;
_umbracoPath = null;
_umbracoScriptsPath = null;
_mainDomLock = null;
_noNodesViewPath = null;
_useHttps = null;
_versionCheckPeriod = null;
_smtpSettingsBuilder = new SmtpSettingsBuilder<GlobalSettingsBuilder<TParent>>(this);
}
private class TestGlobalSettings : IGlobalSettings
{
public string ReservedUrls { get; set; }
@@ -37,6 +37,64 @@ 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;
Reset();
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
};
}
protected override void Reset()
{
_createDate = null;
_cultureInfo = null;
_deleteDate = null;
_fallbackLanguageId = null;
_id = null;
_isDefault = null;
_isMandatory = null;
_key = null;
_updateDate = null;
}
DateTime? IWithCreateDateBuilder.CreateDate
{
get => _createDate;
@@ -72,49 +130,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;
}
}
}
@@ -161,9 +161,34 @@ namespace Umbraco.Tests.Common.Builders
member.ResetDirtyProperties(false);
}
Reset();
return member;
}
protected override void Reset()
{
_id = null;
_key = null;
_createDate = null;
_updateDate = null;
_name = null;
_creatorId = null;
_level = null;
_path = null;
_username = null;
_rawPasswordValue = null;
_email = null;
_failedPasswordAttempts = null;
_isApproved = null;
_isLockedOut = null;
_lastLockoutDate = null;
_lastLoginDate = null;
_lastPasswordChangeDate = null;
_sortOrder = null;
_trashed = null;
_propertyIdsIncrementingFrom = null;
}
int? IWithIdBuilder.Id
{
get => _id;
@@ -57,9 +57,20 @@ namespace Umbraco.Tests.Common.Builders
}
}
Reset();
return memberGroup;
}
protected override void Reset()
{
_id = null;
_key = null;
_createDate = null;
_updateDate = null;
_name = null;
_creatorId = null;
}
int? IWithIdBuilder.Id
{
get => _id;
@@ -134,9 +134,25 @@ namespace Umbraco.Tests.Common.Builders
memberType.ResetDirtyProperties(false);
Reset();
return memberType;
}
protected override void Reset()
{
_id = null;
_alias = null;
_name = null;
_parentId = null;
_sortOrder = null;
_creatorId = null;
_description = null;
_icon = null;
_thumbnail = null;
_trashed = null;
_propertyGroupBuilders.Clear();
}
int? IWithIdBuilder.Id
{
get => _id;
@@ -36,6 +36,7 @@ namespace Umbraco.Tests.Common.Builders
// Needs to be within collection to support publishing.
var propertyTypeCollection = new PropertyTypeCollection(true, new[] { _propertyTypeBuilder.Build() });
Reset();
return new Property(id, propertyTypeCollection[0])
{
Key = key,
@@ -44,6 +45,14 @@ namespace Umbraco.Tests.Common.Builders
};
}
protected override void Reset()
{
_id = null;
_key = null;
_createDate = null;
_updateDate = null;
}
int? IWithIdBuilder.Id
{
get => _id;
@@ -62,6 +62,7 @@ namespace Umbraco.Tests.Common.Builders
properties.Add(propertyType);
}
Reset();
return new PropertyGroup(properties)
{
Id = id,
@@ -73,6 +74,17 @@ namespace Umbraco.Tests.Common.Builders
};
}
protected override void Reset()
{
_id = null;
_key = null;
_createDate = null;
_updateDate = null;
_name = null;
_sortOrder = null;
_propertyTypeBuilders.Clear();
}
int? IWithIdBuilder.Id
{
get => _id;
@@ -108,6 +108,7 @@ namespace Umbraco.Tests.Common.Builders
var shortStringHelper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig());
Reset();
return new PropertyType(shortStringHelper, propertyEditorAlias, valueStorageType)
{
Id = id,
@@ -126,6 +127,26 @@ namespace Umbraco.Tests.Common.Builders
ValidationRegExpMessage = validationRegExpMessage,
};
}
protected override void Reset()
{
_id = null;
_key = null;
_propertyEditorAlias = null;
_valueStorageType = null;
_alias = null;
_name = null;
_createDate = null;
_updateDate = null;
_sortOrder = null;
_description = null;
_dataTypeId = null;
_propertyGroupId = null;
_mandatory = null;
_mandatoryMessage = null;
_validationRegExp = null;
_validationRegExpMessage = null;
}
int? IWithIdBuilder.Id
{
@@ -58,6 +58,7 @@ namespace Umbraco.Tests.Common.Builders
var relationType = _relationTypeBuilder.Build();
Reset();
return new Relation(parentId, childId, relationType)
{
Comment = comment,
@@ -68,6 +69,17 @@ namespace Umbraco.Tests.Common.Builders
};
}
protected override void Reset()
{
_id = null;
_parentId = null;
_childId = null;
_key = null;
_createDate = null;
_updateDate = null;
_comment = null;
}
int? IWithIdBuilder.Id
{
get => _id;
@@ -33,6 +33,62 @@ 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;
Reset();
return new RelationType(name, alias, isBidirectional, parentObjectType, childObjectType)
{
Id = id,
Key = key,
CreateDate = createDate,
UpdateDate = updateDate,
DeleteDate = deleteDate
};
}
protected override void Reset()
{
_alias = null;
_childObjectType = null;
_createDate = null;
_deleteDate = null;
_id = null;
_isBidirectional = null;
_key = null;
_name = null;
_parentObjectType = null;
_updateDate = null;
}
string IWithAliasBuilder.Alias
{
get => _alias;
@@ -74,46 +130,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;
}
}
}
@@ -9,65 +9,73 @@ 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()
{
Reset();
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; }
}
}
protected override void Reset()
{
_from = null;
_host = null;
_port = null;
_pickupDirectoryLocation = null;
}
private class TestSmtpSettings : ISmtpSettings
{
public string From { get; set; }
public string Host { get; set; }
public int Port { get; set; }
public string PickupDirectoryLocation { get; set; }
}
}
}
@@ -25,10 +25,17 @@ namespace Umbraco.Tests.Common.Builders
var path = _path ?? string.Empty;
var content = _content ?? string.Empty;
Reset();
return new Stylesheet(path)
{
Content = content,
};
}
protected override void Reset()
{
_path = null;
_content = null;
}
}
}
@@ -57,6 +57,8 @@ namespace Umbraco.Tests.Common.Builders
var masterTemplateId = _masterTemplateId ?? null;
var shortStringHelper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig());
Reset();
return new Template(shortStringHelper, name, alias)
{
Id = id,
@@ -71,6 +73,21 @@ namespace Umbraco.Tests.Common.Builders
};
}
protected override void Reset()
{
_id = null;
_key = null;
_alias = null;
_name = null;
_createDate = null;
_updateDate = null;
_path = null;
_content = null;
_isMasterTemplate = null;
_masterTemplateAlias = null;
_masterTemplateId = null;
}
int? IWithIdBuilder.Id
{
get => _id;
@@ -10,7 +10,6 @@ namespace Umbraco.Tests.Common.Builders
{
}
}
public class UserBuilder<TParent>
: ChildBuilderBase<TParent, User>,
IWithIdBuilder,
@@ -135,6 +134,7 @@ namespace Umbraco.Tests.Common.Builders
var startContentIds = _startContentIds ?? new int[0];
var startMediaIds = _startMediaIds ?? new int[0];
Reset();
return new User(
globalSettings,
name,
@@ -160,6 +160,31 @@ namespace Umbraco.Tests.Common.Builders
};
}
protected override void Reset()
{
_id = null;
_key = null;
_createDate = null;
_updateDate = null;
_language = null;
_name = null;
_username = null;
_rawPasswordValue = null;
_email = null;
_failedPasswordAttempts = null;
_isApproved = null;
_isLockedOut = null;
_lastLockoutDate = null;
_lastLoginDate = null;
_lastPasswordChangeDate = null;
_suffix = string.Empty;
_defaultLang = null;
_comments = null;
_sessionTimeout = null;
_startContentIds = null;
_startMediaIds = null;
}
int? IWithIdBuilder.Id
{
get => _id;
@@ -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,6 +68,21 @@ namespace Umbraco.Tests.Common.Builders
x.Icon == _icon &&
x.Permissions == _permissions &&
x.AllowedSections == _sectionCollection);
Reset();
return userGroup;
}
protected override void Reset()
{
_startContentId = null;
_startMediaId = null;
_alias = null;
_icon = null;
_name = null;
_permissions = Enumerable.Empty<string>();
_sectionCollection = Enumerable.Empty<string>();
_suffix = null;
_id = null;
}
int? IWithIdBuilder.Id
@@ -87,7 +87,7 @@ namespace Umbraco.Tests.Persistence.Repositories
{
var repository = CreateRepository(provider);
var user = UserBuilder.Build();
var user = UserBuilder.WithoutIdentity().Build();
repository.Save(user);
@@ -365,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 });