2020-12-05 11:12:55 +01:00
|
|
|
// Copyright (c) Umbraco.
|
|
|
|
|
// See LICENSE for more details.
|
|
|
|
|
|
2020-01-09 15:32:19 +01:00
|
|
|
using System;
|
2020-04-19 09:39:30 +02:00
|
|
|
using System.Globalization;
|
2021-02-18 11:06:02 +01:00
|
|
|
using Umbraco.Cms.Core.Models;
|
|
|
|
|
using Umbraco.Cms.Tests.Common.Builders.Interfaces;
|
2020-01-09 15:32:19 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
namespace Umbraco.Cms.Tests.Common.Builders.Extensions;
|
|
|
|
|
|
|
|
|
|
public static class BuilderExtensions
|
2020-01-09 15:32:19 +01:00
|
|
|
{
|
2022-06-21 08:09:38 +02:00
|
|
|
public static T WithId<T>(this T builder, int id)
|
|
|
|
|
where T : IWithIdBuilder
|
2020-01-09 15:32:19 +01:00
|
|
|
{
|
2022-06-21 08:09:38 +02:00
|
|
|
builder.Id = id;
|
|
|
|
|
return builder;
|
|
|
|
|
}
|
2020-03-28 20:54:10 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
public static T WithId<T, TId>(this T builder, TId id)
|
|
|
|
|
where T : IWithIdBuilder<TId>
|
|
|
|
|
{
|
|
|
|
|
builder.Id = id;
|
|
|
|
|
return builder;
|
|
|
|
|
}
|
2021-03-26 16:43:49 +11:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
public static T WithoutIdentity<T>(this T builder)
|
|
|
|
|
where T : IWithIdBuilder
|
|
|
|
|
{
|
|
|
|
|
builder.Id = 0;
|
|
|
|
|
return builder;
|
|
|
|
|
}
|
2020-04-11 18:37:10 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
public static T WithCreatorId<T>(this T builder, int creatorId)
|
|
|
|
|
where T : IWithCreatorIdBuilder
|
|
|
|
|
{
|
|
|
|
|
builder.CreatorId = creatorId;
|
|
|
|
|
return builder;
|
|
|
|
|
}
|
2020-01-09 15:32:19 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
public static T WithCreateDate<T>(this T builder, DateTime createDate)
|
|
|
|
|
where T : IWithCreateDateBuilder
|
|
|
|
|
{
|
|
|
|
|
builder.CreateDate = createDate;
|
|
|
|
|
return builder;
|
|
|
|
|
}
|
2020-01-09 15:32:19 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
public static T WithUpdateDate<T>(this T builder, DateTime updateDate)
|
|
|
|
|
where T : IWithUpdateDateBuilder
|
|
|
|
|
{
|
|
|
|
|
builder.UpdateDate = updateDate;
|
|
|
|
|
return builder;
|
|
|
|
|
}
|
2020-01-09 16:37:24 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
public static T WithDeleteDate<T>(this T builder, DateTime deleteDate)
|
|
|
|
|
where T : IWithDeleteDateBuilder
|
|
|
|
|
{
|
|
|
|
|
builder.DeleteDate = deleteDate;
|
|
|
|
|
return builder;
|
|
|
|
|
}
|
2020-04-04 11:11:47 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
public static T WithAlias<T>(this T builder, string alias)
|
|
|
|
|
where T : IWithAliasBuilder
|
|
|
|
|
{
|
|
|
|
|
builder.Alias = alias;
|
|
|
|
|
return builder;
|
|
|
|
|
}
|
2020-01-09 16:37:24 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
public static T WithName<T>(this T builder, string name)
|
|
|
|
|
where T : IWithNameBuilder
|
|
|
|
|
{
|
|
|
|
|
builder.Name = name;
|
|
|
|
|
return builder;
|
|
|
|
|
}
|
2020-01-13 07:29:12 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
public static T WithKey<T>(this T builder, Guid key)
|
|
|
|
|
where T : IWithKeyBuilder
|
|
|
|
|
{
|
|
|
|
|
builder.Key = key;
|
|
|
|
|
return builder;
|
|
|
|
|
}
|
2020-03-29 16:17:06 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
public static T WithParentId<T>(this T builder, int parentId)
|
|
|
|
|
where T : IWithParentIdBuilder
|
|
|
|
|
{
|
|
|
|
|
builder.ParentId = parentId;
|
|
|
|
|
return builder;
|
|
|
|
|
}
|
2020-03-29 16:17:06 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
public static T WithParentContentType<T>(this T builder, IContentTypeComposition parent)
|
|
|
|
|
where T : IWithParentContentTypeBuilder
|
|
|
|
|
{
|
|
|
|
|
builder.Parent = parent;
|
|
|
|
|
return builder;
|
|
|
|
|
}
|
2020-10-07 14:54:14 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
public static T WithTrashed<T>(this T builder, bool trashed)
|
|
|
|
|
where T : IWithTrashedBuilder
|
|
|
|
|
{
|
|
|
|
|
builder.Trashed = trashed;
|
|
|
|
|
return builder;
|
|
|
|
|
}
|
2020-03-29 16:17:06 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
public static T WithLevel<T>(this T builder, int level)
|
|
|
|
|
where T : IWithLevelBuilder
|
|
|
|
|
{
|
|
|
|
|
builder.Level = level;
|
|
|
|
|
return builder;
|
|
|
|
|
}
|
2020-03-29 16:17:06 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
public static T WithPath<T>(this T builder, string path)
|
|
|
|
|
where T : IWithPathBuilder
|
|
|
|
|
{
|
|
|
|
|
builder.Path = path;
|
|
|
|
|
return builder;
|
|
|
|
|
}
|
2020-03-29 16:17:06 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
public static T WithSortOrder<T>(this T builder, int sortOrder)
|
|
|
|
|
where T : IWithSortOrderBuilder
|
|
|
|
|
{
|
|
|
|
|
builder.SortOrder = sortOrder;
|
|
|
|
|
return builder;
|
|
|
|
|
}
|
2020-03-29 16:17:06 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
public static T WithDescription<T>(this T builder, string description)
|
|
|
|
|
where T : IWithDescriptionBuilder
|
|
|
|
|
{
|
|
|
|
|
builder.Description = description;
|
|
|
|
|
return builder;
|
|
|
|
|
}
|
2020-03-29 16:17:06 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
public static T WithIcon<T>(this T builder, string icon)
|
|
|
|
|
where T : IWithIconBuilder
|
|
|
|
|
{
|
|
|
|
|
builder.Icon = icon;
|
|
|
|
|
return builder;
|
|
|
|
|
}
|
2020-03-29 16:17:06 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
public static T WithThumbnail<T>(this T builder, string thumbnail)
|
|
|
|
|
where T : IWithThumbnailBuilder
|
|
|
|
|
{
|
|
|
|
|
builder.Thumbnail = thumbnail;
|
|
|
|
|
return builder;
|
|
|
|
|
}
|
2020-04-11 16:35:33 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
public static T WithLogin<T>(this T builder, string username, string rawPasswordValue)
|
|
|
|
|
where T : IWithLoginBuilder
|
|
|
|
|
{
|
|
|
|
|
builder.Username = username;
|
|
|
|
|
builder.RawPasswordValue = rawPasswordValue;
|
|
|
|
|
return builder;
|
|
|
|
|
}
|
2020-04-11 16:35:33 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
public static T WithEmail<T>(this T builder, string email)
|
|
|
|
|
where T : IWithEmailBuilder
|
|
|
|
|
{
|
|
|
|
|
builder.Email = email;
|
|
|
|
|
return builder;
|
|
|
|
|
}
|
2020-04-11 16:35:33 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
public static T WithFailedPasswordAttempts<T>(this T builder, int failedPasswordAttempts)
|
|
|
|
|
where T : IWithFailedPasswordAttemptsBuilder
|
|
|
|
|
{
|
|
|
|
|
builder.FailedPasswordAttempts = failedPasswordAttempts;
|
|
|
|
|
return builder;
|
|
|
|
|
}
|
2020-04-11 16:35:33 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
public static T WithIsApproved<T>(this T builder, bool isApproved)
|
|
|
|
|
where T : IWithIsApprovedBuilder
|
|
|
|
|
{
|
|
|
|
|
builder.IsApproved = isApproved;
|
|
|
|
|
return builder;
|
|
|
|
|
}
|
2020-04-11 16:35:33 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
public static T WithIsLockedOut<T>(this T builder, bool isLockedOut, DateTime? lastLockoutDate = null)
|
|
|
|
|
where T : IWithIsLockedOutBuilder
|
|
|
|
|
{
|
|
|
|
|
builder.IsLockedOut = isLockedOut;
|
|
|
|
|
if (lastLockoutDate.HasValue)
|
2020-04-11 16:35:33 +02:00
|
|
|
{
|
2022-06-21 08:09:38 +02:00
|
|
|
builder.LastLockoutDate = lastLockoutDate.Value;
|
2020-04-11 16:35:33 +02:00
|
|
|
}
|
|
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
return builder;
|
|
|
|
|
}
|
2020-04-11 16:35:33 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
public static T WithLastLoginDate<T>(this T builder, DateTime lastLoginDate)
|
|
|
|
|
where T : IWithLastLoginDateBuilder
|
|
|
|
|
{
|
|
|
|
|
builder.LastLoginDate = lastLoginDate;
|
|
|
|
|
return builder;
|
|
|
|
|
}
|
2020-04-19 09:05:09 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
public static T WithLastPasswordChangeDate<T>(this T builder, DateTime lastPasswordChangeDate)
|
|
|
|
|
where T : IWithLastPasswordChangeDateBuilder
|
|
|
|
|
{
|
|
|
|
|
builder.LastPasswordChangeDate = lastPasswordChangeDate;
|
|
|
|
|
return builder;
|
|
|
|
|
}
|
2020-04-19 09:05:09 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
public static T WithPropertyTypeIdsIncrementingFrom<T>(this T builder, int propertyTypeIdsIncrementingFrom)
|
|
|
|
|
where T : IWithPropertyTypeIdsIncrementingFrom
|
|
|
|
|
{
|
|
|
|
|
builder.PropertyTypeIdsIncrementingFrom = propertyTypeIdsIncrementingFrom;
|
|
|
|
|
return builder;
|
|
|
|
|
}
|
2020-04-19 09:39:30 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
public static T WithIsContainer<T>(this T builder, bool isContainer)
|
|
|
|
|
where T : IWithIsContainerBuilder
|
|
|
|
|
{
|
|
|
|
|
builder.IsContainer = isContainer;
|
|
|
|
|
return builder;
|
|
|
|
|
}
|
2020-10-07 11:23:31 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
public static T WithCultureInfo<T>(this T builder, string cultureCode)
|
|
|
|
|
where T : IWithCultureInfoBuilder
|
|
|
|
|
{
|
|
|
|
|
builder.CultureInfo = CultureInfo.GetCultureInfo(cultureCode);
|
|
|
|
|
return builder;
|
|
|
|
|
}
|
2020-10-11 09:13:31 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
public static T WithSupportsPublishing<T>(this T builder, bool supportsPublishing)
|
|
|
|
|
where T : IWithSupportsPublishing
|
|
|
|
|
{
|
|
|
|
|
builder.SupportsPublishing = supportsPublishing;
|
|
|
|
|
return builder;
|
|
|
|
|
}
|
2021-10-07 14:09:34 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
public static T WithPropertyValues<T>(this T builder, object propertyValues, string? culture = null, string? segment = null)
|
|
|
|
|
where T : IWithPropertyValues
|
|
|
|
|
{
|
|
|
|
|
builder.PropertyValues = propertyValues;
|
|
|
|
|
builder.PropertyValuesCulture = culture;
|
|
|
|
|
builder.PropertyValuesSegment = segment;
|
|
|
|
|
return builder;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static T WithDate<T>(this T builder, DateTime date) where T : IWithDateBuilder
|
|
|
|
|
{
|
|
|
|
|
builder.Date = date;
|
|
|
|
|
return builder;
|
2020-01-09 15:32:19 +01:00
|
|
|
}
|
|
|
|
|
}
|