Merge remote-tracking branch 'origin/netcore/dev' into netcore/bugfix/integration-tests-running
This commit is contained in:
@@ -100,6 +100,9 @@ src/Umbraco.Web.UI/[Uu]mbraco/[Jj]s/loader.dev.js
|
||||
src/Umbraco.Web.UI/[Uu]mbraco/[Jj]s/main.js
|
||||
src/Umbraco.Web.UI/[Uu]mbraco/[Jj]s/app.js
|
||||
src/Umbraco.Web.UI/[Uu]mbraco/[Jj]s/canvasdesigner.*.js
|
||||
src/Umbraco.Web.UI/[Uu]mbraco/[Jj]s/navigation.controller.js
|
||||
src/Umbraco.Web.UI/[Uu]mbraco/[Jj]s/main.controller.js
|
||||
src/Umbraco.Web.UI/[Uu]mbraco/[Jj]s/utilities.js
|
||||
|
||||
src/Umbraco.Web.UI/[Uu]mbraco/[Vv]iews/
|
||||
src/Umbraco.Web.UI/[Uu]mbraco/[Vv]iews/**/*.js
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace Umbraco.Configuration.Models
|
||||
/// </summary>
|
||||
internal class GlobalSettings : IGlobalSettings
|
||||
{
|
||||
public const string Prefix = Constants.Configuration.ConfigPrefix + "Global:";
|
||||
private const string Prefix = Constants.Configuration.ConfigGlobalPrefix;
|
||||
|
||||
internal const string
|
||||
StaticReservedPaths = "~/app_plugins/,~/install/,~/mini-profiler-resources/,"; //must end with a comma!
|
||||
|
||||
@@ -22,6 +22,6 @@ namespace Umbraco.Configuration.Models
|
||||
/// Gets a value indicating whether umbraco is running in [debug mode].
|
||||
/// </summary>
|
||||
/// <value><c>true</c> if [debug mode]; otherwise, <c>false</c>.</value>
|
||||
public bool DebugMode => _configuration.GetValue(Prefix+":Debug", false);
|
||||
public bool DebugMode => _configuration.GetValue(Prefix+"Debug", false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,9 @@ namespace Umbraco.Core.Composing
|
||||
"Umbraco.PublishedCache.NuCache",
|
||||
"Umbraco.ModelsBuilder.Embedded",
|
||||
"Umbraco.Examine.Lucene",
|
||||
"Umbraco.Web.Common",
|
||||
"Umbraco.Web.BackOffice",
|
||||
"Umbraco.Web.Website",
|
||||
};
|
||||
|
||||
public DefaultUmbracoAssemblyProvider(Assembly entryPointAssembly)
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
/// </remarks>
|
||||
public const string ConfigPrefix = "Umbraco:CMS:";
|
||||
public const string ConfigSecurityPrefix = ConfigPrefix+"Security:";
|
||||
public const string ConfigGlobalPrefix = ConfigPrefix + "Global:";
|
||||
public const string ConfigModelsBuilderPrefix = ConfigPrefix+"ModelsBuilder:";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,8 +25,10 @@
|
||||
public const string UnknownUserName = "SYTEM";
|
||||
|
||||
public const string AdminGroupAlias = "admin";
|
||||
public const string EditorGroupAlias = "editor";
|
||||
public const string SensitiveDataGroupAlias = "sensitiveData";
|
||||
public const string TranslatorGroupAlias = "translator";
|
||||
public const string WriterGroupAlias = "writer";
|
||||
|
||||
public const string BackOfficeAuthenticationType = "UmbracoBackOffice";
|
||||
public const string BackOfficeExternalAuthenticationType = "UmbracoExternalCookie";
|
||||
|
||||
+3
-1
@@ -1,4 +1,6 @@
|
||||
namespace Umbraco.Core.Models
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Core.Media
|
||||
{
|
||||
public interface IImageUrlGenerator
|
||||
{
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using Umbraco.Core.Models.Entities;
|
||||
|
||||
namespace Umbraco.Core.Models
|
||||
{
|
||||
public interface IKeyValue : IEntity
|
||||
{
|
||||
string Identifier { get; set; }
|
||||
|
||||
string Value { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
using Umbraco.Core.Models.Entities;
|
||||
|
||||
namespace Umbraco.Core.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Implements <see cref="IKeyValue"/>.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
[DataContract(IsReference = true)]
|
||||
public class KeyValue : EntityBase, IKeyValue, IEntity
|
||||
{
|
||||
private string _identifier;
|
||||
private string _value;
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Identifier
|
||||
{
|
||||
get => _identifier;
|
||||
set => SetPropertyValueAndDetectChanges(value, ref _identifier, nameof(Identifier));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Value
|
||||
{
|
||||
get => _value;
|
||||
set => SetPropertyValueAndDetectChanges(value, ref _value, nameof(Value));
|
||||
}
|
||||
|
||||
bool IEntity.HasIdentity => !string.IsNullOrEmpty(Identifier);
|
||||
}
|
||||
}
|
||||
@@ -111,7 +111,7 @@ namespace Umbraco.Web.Models.PublishedContent
|
||||
var propertyType = content.ContentType.GetPropertyType(alias);
|
||||
if (propertyType != null)
|
||||
{
|
||||
_variationContextAccessor.ContextualizeVariation(propertyType.Variations, ref culture, ref segment);
|
||||
_variationContextAccessor.ContextualizeVariation(propertyType.Variations, content.Id, ref culture, ref segment);
|
||||
noValueProperty = content.GetProperty(alias);
|
||||
}
|
||||
|
||||
@@ -168,7 +168,7 @@ namespace Umbraco.Web.Models.PublishedContent
|
||||
{
|
||||
culture = null;
|
||||
segment = null;
|
||||
_variationContextAccessor.ContextualizeVariation(propertyType.Variations, ref culture, ref segment);
|
||||
_variationContextAccessor.ContextualizeVariation(propertyType.Variations, content.Id, ref culture, ref segment);
|
||||
}
|
||||
|
||||
property = content?.GetProperty(alias);
|
||||
|
||||
@@ -23,5 +23,12 @@
|
||||
/// Gets the segment.
|
||||
/// </summary>
|
||||
public string Segment { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the segment for the content item
|
||||
/// </summary>
|
||||
/// <param name="contentId"></param>
|
||||
/// <returns></returns>
|
||||
public virtual string GetSegment(int contentId) => Segment;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,13 +3,32 @@
|
||||
public static class VariationContextAccessorExtensions
|
||||
{
|
||||
public static void ContextualizeVariation(this IVariationContextAccessor variationContextAccessor, ContentVariation variations, ref string culture, ref string segment)
|
||||
=> variationContextAccessor.ContextualizeVariation(variations, null, ref culture, ref segment);
|
||||
|
||||
public static void ContextualizeVariation(this IVariationContextAccessor variationContextAccessor, ContentVariation variations, int contentId, ref string culture, ref string segment)
|
||||
=> variationContextAccessor.ContextualizeVariation(variations, (int?)contentId, ref culture, ref segment);
|
||||
|
||||
private static void ContextualizeVariation(this IVariationContextAccessor variationContextAccessor, ContentVariation variations, int? contentId, ref string culture, ref string segment)
|
||||
{
|
||||
if (culture != null && segment != null) return;
|
||||
|
||||
// use context values
|
||||
var publishedVariationContext = variationContextAccessor?.VariationContext;
|
||||
if (culture == null) culture = variations.VariesByCulture() ? publishedVariationContext?.Culture : "";
|
||||
if (segment == null) segment = variations.VariesBySegment() ? publishedVariationContext?.Segment : "";
|
||||
|
||||
if (segment == null)
|
||||
{
|
||||
if (variations.VariesBySegment())
|
||||
{
|
||||
segment = contentId == null
|
||||
? publishedVariationContext?.Segment
|
||||
: publishedVariationContext?.GetSegment(contentId.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
segment = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
using System;
|
||||
|
||||
namespace Umbraco.Net
|
||||
{
|
||||
// TODO: This shouldn't be in this namespace?
|
||||
@@ -11,5 +13,13 @@ namespace Umbraco.Net
|
||||
/// Terminates the current application. The application restarts the next time a request is received for it.
|
||||
/// </summary>
|
||||
void Restart();
|
||||
|
||||
event EventHandler ApplicationInit;
|
||||
}
|
||||
|
||||
|
||||
public interface IUmbracoApplicationLifetimeManager
|
||||
{
|
||||
void InvokeApplicationInit();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
public interface IKeyValueRepository : IReadRepository<string, IKeyValue>, IWriteRepository<IKeyValue>
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -20,8 +20,24 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
/// </summary>
|
||||
/// <param name="username"></param>
|
||||
/// <returns></returns>
|
||||
[Obsolete("This method will be removed in future versions. Please use ExistsByUserName instead.")]
|
||||
bool Exists(string username);
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a user with the username exists
|
||||
/// </summary>
|
||||
/// <param name="username"></param>
|
||||
/// <returns></returns>
|
||||
bool ExistsByUserName(string username);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a user with the login exists
|
||||
/// </summary>
|
||||
/// <param name="username"></param>
|
||||
/// <returns></returns>
|
||||
bool ExistsByLogin(string login);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of <see cref="IUser"/> objects associated with a given group
|
||||
/// </summary>
|
||||
|
||||
@@ -11,6 +11,9 @@ namespace Umbraco.Core.Services
|
||||
IEnumerable<string> GetAllRoles();
|
||||
IEnumerable<string> GetAllRoles(int memberId);
|
||||
IEnumerable<string> GetAllRoles(string username);
|
||||
IEnumerable<int> GetAllRolesIds();
|
||||
IEnumerable<int> GetAllRolesIds(int memberId);
|
||||
IEnumerable<int> GetAllRolesIds(string username);
|
||||
IEnumerable<T> GetMembersInRole(string roleName);
|
||||
IEnumerable<T> FindMembersInRole(string roleName, string usernameToMatch, StringPropertyMatchType matchType = StringPropertyMatchType.StartsWith);
|
||||
bool DeleteRole(string roleName, bool throwIfBeingUsed);
|
||||
|
||||
@@ -32,12 +32,13 @@ namespace Umbraco.Core.Services
|
||||
private readonly Lazy<IExternalLoginService> _externalLoginService;
|
||||
private readonly Lazy<IRedirectUrlService> _redirectUrlService;
|
||||
private readonly Lazy<IConsentService> _consentService;
|
||||
private readonly Lazy<IKeyValueService> _keyValueService;
|
||||
private readonly Lazy<IContentTypeBaseServiceProvider> _contentTypeBaseServiceProvider;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ServiceContext"/> class with lazy services.
|
||||
/// </summary>
|
||||
public ServiceContext(Lazy<IPublicAccessService> publicAccessService, Lazy<IDomainService> domainService, Lazy<IAuditService> auditService, Lazy<ILocalizedTextService> localizedTextService, Lazy<ITagService> tagService, Lazy<IContentService> contentService, Lazy<IUserService> userService, Lazy<IMemberService> memberService, Lazy<IMediaService> mediaService, Lazy<IContentTypeService> contentTypeService, Lazy<IMediaTypeService> mediaTypeService, Lazy<IDataTypeService> dataTypeService, Lazy<IFileService> fileService, Lazy<ILocalizationService> localizationService, Lazy<IPackagingService> packagingService, Lazy<IServerRegistrationService> serverRegistrationService, Lazy<IEntityService> entityService, Lazy<IRelationService> relationService, Lazy<IMacroService> macroService, Lazy<IMemberTypeService> memberTypeService, Lazy<IMemberGroupService> memberGroupService, Lazy<INotificationService> notificationService, Lazy<IExternalLoginService> externalLoginService, Lazy<IRedirectUrlService> redirectUrlService, Lazy<IConsentService> consentService, Lazy<IContentTypeBaseServiceProvider> contentTypeBaseServiceProvider)
|
||||
public ServiceContext(Lazy<IPublicAccessService> publicAccessService, Lazy<IDomainService> domainService, Lazy<IAuditService> auditService, Lazy<ILocalizedTextService> localizedTextService, Lazy<ITagService> tagService, Lazy<IContentService> contentService, Lazy<IUserService> userService, Lazy<IMemberService> memberService, Lazy<IMediaService> mediaService, Lazy<IContentTypeService> contentTypeService, Lazy<IMediaTypeService> mediaTypeService, Lazy<IDataTypeService> dataTypeService, Lazy<IFileService> fileService, Lazy<ILocalizationService> localizationService, Lazy<IPackagingService> packagingService, Lazy<IServerRegistrationService> serverRegistrationService, Lazy<IEntityService> entityService, Lazy<IRelationService> relationService, Lazy<IMacroService> macroService, Lazy<IMemberTypeService> memberTypeService, Lazy<IMemberGroupService> memberGroupService, Lazy<INotificationService> notificationService, Lazy<IExternalLoginService> externalLoginService, Lazy<IRedirectUrlService> redirectUrlService, Lazy<IConsentService> consentService, Lazy<IKeyValueService> keyValueService, Lazy<IContentTypeBaseServiceProvider> contentTypeBaseServiceProvider)
|
||||
{
|
||||
_publicAccessService = publicAccessService;
|
||||
_domainService = domainService;
|
||||
@@ -64,6 +65,7 @@ namespace Umbraco.Core.Services
|
||||
_externalLoginService = externalLoginService;
|
||||
_redirectUrlService = redirectUrlService;
|
||||
_consentService = consentService;
|
||||
_keyValueService = keyValueService;
|
||||
_contentTypeBaseServiceProvider = contentTypeBaseServiceProvider;
|
||||
}
|
||||
|
||||
@@ -99,6 +101,7 @@ namespace Umbraco.Core.Services
|
||||
IServerRegistrationService serverRegistrationService = null,
|
||||
IRedirectUrlService redirectUrlService = null,
|
||||
IConsentService consentService = null,
|
||||
IKeyValueService keyValueService = null,
|
||||
IContentTypeBaseServiceProvider contentTypeBaseServiceProvider = null)
|
||||
{
|
||||
Lazy<T> Lazy<T>(T service) => service == null ? null : new Lazy<T>(() => service);
|
||||
@@ -129,6 +132,7 @@ namespace Umbraco.Core.Services
|
||||
Lazy(externalLoginService),
|
||||
Lazy(redirectUrlService),
|
||||
Lazy(consentService),
|
||||
Lazy(keyValueService),
|
||||
Lazy(contentTypeBaseServiceProvider)
|
||||
);
|
||||
}
|
||||
@@ -258,6 +262,11 @@ namespace Umbraco.Core.Services
|
||||
/// </summary>
|
||||
public IConsentService ConsentService => _consentService.Value;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the KeyValueService.
|
||||
/// </summary>
|
||||
public IKeyValueService KeyValueService => _keyValueService.Value;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the ContentTypeServiceBaseFactory.
|
||||
/// </summary>
|
||||
|
||||
@@ -8,7 +8,6 @@ using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using Umbraco.Composing;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Strings;
|
||||
|
||||
@@ -72,6 +71,23 @@ namespace Umbraco.Core
|
||||
}
|
||||
|
||||
return fileName;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines the extension of the path or URL
|
||||
/// </summary>
|
||||
/// <param name="file"></param>
|
||||
/// <returns>Extension of the file</returns>
|
||||
public static string GetFileExtension(this string file)
|
||||
{
|
||||
//Find any characters between the last . and the start of a query string or the end of the string
|
||||
const string pattern = @"(?<extension>\.[^\.\?]+)(\?.*|$)";
|
||||
var match = Regex.Match(file, pattern);
|
||||
return match.Success
|
||||
? match.Groups["extension"].Value
|
||||
: string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -146,7 +146,7 @@ namespace Umbraco.Core
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <returns></returns>
|
||||
internal static bool IsClientSideRequest(this Uri url)
|
||||
public static bool IsClientSideRequest(this Uri url)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -47,6 +47,7 @@ namespace Umbraco.Core.Composing.CompositionExtensions
|
||||
composition.RegisterUnique<IScriptRepository, ScriptRepository>();
|
||||
composition.RegisterUnique<IStylesheetRepository, StylesheetRepository>();
|
||||
composition.RegisterUnique<IContentTypeCommonRepository, ContentTypeCommonRepository>();
|
||||
composition.RegisterUnique<IKeyValueRepository, KeyValueRepository>();
|
||||
composition.RegisterUnique<IInstallationRepository, InstallationRepository>();
|
||||
composition.RegisterUnique<IUpgradeCheckRepository, UpgradeCheckRepository>();
|
||||
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ namespace Umbraco.Web.HealthCheck.NotificationMethods
|
||||
|
||||
public EmailNotificationMethod(ILocalizedTextService textService, IRuntimeState runtimeState, ILogger logger, IGlobalSettings globalSettings, IHealthChecksSettings healthChecksSettings, IContentSettings contentSettings) : base(healthChecksSettings)
|
||||
{
|
||||
var recipientEmail = Settings["recipientEmail"]?.Value;
|
||||
var recipientEmail = Settings?["recipientEmail"]?.Value;
|
||||
if (string.IsNullOrWhiteSpace(recipientEmail))
|
||||
{
|
||||
Enabled = false;
|
||||
|
||||
+11
-10
@@ -1,9 +1,10 @@
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Media;
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Web.Models
|
||||
namespace Umbraco.Infrastructure.Media
|
||||
{
|
||||
public class ImageProcessorImageUrlGenerator : IImageUrlGenerator
|
||||
{
|
||||
@@ -27,18 +28,18 @@ namespace Umbraco.Web.Models
|
||||
|
||||
//Only put quality here, if we don't have a format specified.
|
||||
//Otherwise we need to put quality at the end to avoid it being overridden by the format.
|
||||
if (options.Quality != null && hasFormat == false) imageProcessorUrl.Append("&quality=").Append(options.Quality);
|
||||
if (options.HeightRatio != null) imageProcessorUrl.Append("&heightratio=").Append(options.HeightRatio.Value.ToString(CultureInfo.InvariantCulture));
|
||||
if (options.WidthRatio != null) imageProcessorUrl.Append("&widthratio=").Append(options.WidthRatio.Value.ToString(CultureInfo.InvariantCulture));
|
||||
if (options.Width != null) imageProcessorUrl.Append("&width=").Append(options.Width);
|
||||
if (options.Height != null) imageProcessorUrl.Append("&height=").Append(options.Height);
|
||||
if (options.Quality.HasValue && hasFormat == false) imageProcessorUrl.Append("&quality=").Append(options.Quality);
|
||||
if (options.HeightRatio.HasValue) imageProcessorUrl.Append("&heightratio=").Append(options.HeightRatio.Value.ToString(CultureInfo.InvariantCulture));
|
||||
if (options.WidthRatio.HasValue) imageProcessorUrl.Append("&widthratio=").Append(options.WidthRatio.Value.ToString(CultureInfo.InvariantCulture));
|
||||
if (options.Width.HasValue) imageProcessorUrl.Append("&width=").Append(options.Width);
|
||||
if (options.Height.HasValue) imageProcessorUrl.Append("&height=").Append(options.Height);
|
||||
if (options.UpScale == false) imageProcessorUrl.Append("&upscale=false");
|
||||
if (options.AnimationProcessMode != null) imageProcessorUrl.Append("&animationprocessmode=").Append(options.AnimationProcessMode);
|
||||
if (options.FurtherOptions != null) imageProcessorUrl.Append(options.FurtherOptions);
|
||||
if (!string.IsNullOrWhiteSpace(options.AnimationProcessMode)) imageProcessorUrl.Append("&animationprocessmode=").Append(options.AnimationProcessMode);
|
||||
if (!string.IsNullOrWhiteSpace(options.FurtherOptions)) imageProcessorUrl.Append(options.FurtherOptions);
|
||||
|
||||
//If furtherOptions contains a format, we need to put the quality after the format.
|
||||
if (options.Quality != null && hasFormat) imageProcessorUrl.Append("&quality=").Append(options.Quality);
|
||||
if (options.CacheBusterValue != null) imageProcessorUrl.Append("&rnd=").Append(options.CacheBusterValue);
|
||||
if (options.Quality.HasValue && hasFormat) imageProcessorUrl.Append("&quality=").Append(options.Quality);
|
||||
if (!string.IsNullOrWhiteSpace(options.CacheBusterValue)) imageProcessorUrl.Append("&rnd=").Append(options.CacheBusterValue);
|
||||
|
||||
return imageProcessorUrl.ToString();
|
||||
}
|
||||
@@ -175,8 +175,8 @@ namespace Umbraco.Core.Migrations.Install
|
||||
private void CreateUserGroupData()
|
||||
{
|
||||
_database.Insert(Constants.DatabaseSchema.Tables.UserGroup, "id", false, new UserGroupDto { Id = 1, StartMediaId = -1, StartContentId = -1, Alias = Constants.Security.AdminGroupAlias, Name = "Administrators", DefaultPermissions = "CADMOSKTPIURZ:5F7ï", CreateDate = DateTime.Now, UpdateDate = DateTime.Now, Icon = "icon-medal" });
|
||||
_database.Insert(Constants.DatabaseSchema.Tables.UserGroup, "id", false, new UserGroupDto { Id = 2, StartMediaId = -1, StartContentId = -1, Alias = "writer", Name = "Writers", DefaultPermissions = "CAH:F", CreateDate = DateTime.Now, UpdateDate = DateTime.Now, Icon = "icon-edit" });
|
||||
_database.Insert(Constants.DatabaseSchema.Tables.UserGroup, "id", false, new UserGroupDto { Id = 3, StartMediaId = -1, StartContentId = -1, Alias = "editor", Name = "Editors", DefaultPermissions = "CADMOSKTPUZ:5Fï", CreateDate = DateTime.Now, UpdateDate = DateTime.Now, Icon = "icon-tools" });
|
||||
_database.Insert(Constants.DatabaseSchema.Tables.UserGroup, "id", false, new UserGroupDto { Id = 2, StartMediaId = -1, StartContentId = -1, Alias = Constants.Security.WriterGroupAlias, Name = "Writers", DefaultPermissions = "CAH:F", CreateDate = DateTime.Now, UpdateDate = DateTime.Now, Icon = "icon-edit" });
|
||||
_database.Insert(Constants.DatabaseSchema.Tables.UserGroup, "id", false, new UserGroupDto { Id = 3, StartMediaId = -1, StartContentId = -1, Alias = Constants.Security.EditorGroupAlias, Name = "Editors", DefaultPermissions = "CADMOSKTPUZ:5Fï", CreateDate = DateTime.Now, UpdateDate = DateTime.Now, Icon = "icon-tools" });
|
||||
_database.Insert(Constants.DatabaseSchema.Tables.UserGroup, "id", false, new UserGroupDto { Id = 4, StartMediaId = -1, StartContentId = -1, Alias = Constants.Security.TranslatorGroupAlias, Name = "Translators", DefaultPermissions = "AF", CreateDate = DateTime.Now, UpdateDate = DateTime.Now, Icon = "icon-globe" });
|
||||
_database.Insert(Constants.DatabaseSchema.Tables.UserGroup, "id", false, new UserGroupDto { Id = 5, StartMediaId = -1, StartContentId = -1, Alias = Constants.Security.SensitiveDataGroupAlias, Name = "Sensitive data", DefaultPermissions = "", CreateDate = DateTime.Now, UpdateDate = DateTime.Now, Icon = "icon-lock" });
|
||||
}
|
||||
@@ -344,7 +344,7 @@ namespace Umbraco.Core.Migrations.Install
|
||||
var stateValueKey = upgrader.StateValueKey;
|
||||
var finalState = upgrader.Plan.FinalState;
|
||||
|
||||
_database.Insert(Constants.DatabaseSchema.Tables.KeyValue, "key", false, new KeyValueDto { Key = stateValueKey, Value = finalState, Updated = DateTime.Now });
|
||||
_database.Insert(Constants.DatabaseSchema.Tables.KeyValue, "key", false, new KeyValueDto { Key = stateValueKey, Value = finalState, UpdateDate = DateTime.Now });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,6 +169,7 @@ namespace Umbraco.Core.Migrations.Upgrade
|
||||
.As("{0576E786-5C30-4000-B969-302B61E90CA3}");
|
||||
|
||||
To<FixLanguageIsoCodeLength>("{48AD6CCD-C7A4-4305-A8AB-38728AD23FC5}");
|
||||
To<AddPackagesSectionAccess>("{DF470D86-E5CA-42AC-9780-9D28070E25F9}");
|
||||
|
||||
// finish migrating from v7 - recreate all keys and indexes
|
||||
To<CreateKeysAndIndexes>("{3F9764F5-73D0-4D45-8804-1240A66E43A2}");
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Umbraco.Core.Migrations.Upgrade.V_8_0_0
|
||||
{
|
||||
public class AddPackagesSectionAccess : MigrationBase
|
||||
{
|
||||
public AddPackagesSectionAccess(IMigrationContext context)
|
||||
: base(context)
|
||||
{ }
|
||||
|
||||
public override void Migrate()
|
||||
{
|
||||
// Any user group which had access to the Developer section should have access to Packages
|
||||
Database.Execute($@"
|
||||
insert into {Constants.DatabaseSchema.Tables.UserGroup2App}
|
||||
select userGroupId, '{Constants.Applications.Packages}'
|
||||
from {Constants.DatabaseSchema.Tables.UserGroup2App}
|
||||
where app='developer'");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ using Umbraco.Core.Services;
|
||||
using Umbraco.Core.Strings;
|
||||
using Umbraco.Web.Actions;
|
||||
using Umbraco.Web.Services;
|
||||
using Umbraco.Core.Media;
|
||||
|
||||
namespace Umbraco.Web.Models.Mapping
|
||||
{
|
||||
|
||||
@@ -9,6 +9,7 @@ using Umbraco.Core.Models.Entities;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Core.Security;
|
||||
using Umbraco.Core.Media;
|
||||
|
||||
namespace Umbraco.Core.Models
|
||||
{
|
||||
|
||||
@@ -21,6 +21,6 @@ namespace Umbraco.Core.Persistence.Dtos
|
||||
|
||||
[Column("updated")]
|
||||
[Constraint(Default = SystemMethods.CurrentDateTime)]
|
||||
public DateTime Updated { get; set; }
|
||||
public DateTime UpdateDate { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NPoco;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.Dtos;
|
||||
using Umbraco.Core.Persistence.Querying;
|
||||
using Umbraco.Core.Scoping;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
{
|
||||
internal class KeyValueRepository : NPocoRepositoryBase<string, IKeyValue>, IKeyValueRepository
|
||||
{
|
||||
public KeyValueRepository(IScopeAccessor scopeAccessor, ILogger logger)
|
||||
: base(scopeAccessor, AppCaches.NoCache, logger)
|
||||
{ }
|
||||
|
||||
#region Overrides of IReadWriteQueryRepository<string, IKeyValue>
|
||||
|
||||
public override void Save(IKeyValue entity)
|
||||
{
|
||||
if (Get(entity.Identifier) == null)
|
||||
PersistNewItem(entity);
|
||||
else
|
||||
PersistUpdatedItem(entity);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Overrides of NPocoRepositoryBase<string, IKeyValue>
|
||||
|
||||
protected override Guid NodeObjectTypeId => throw new NotSupportedException();
|
||||
|
||||
protected override Sql<ISqlContext> GetBaseQuery(bool isCount)
|
||||
{
|
||||
var sql = SqlContext.Sql();
|
||||
|
||||
sql = isCount
|
||||
? sql.SelectCount()
|
||||
: sql.Select<KeyValueDto>();
|
||||
|
||||
sql
|
||||
.From<KeyValueDto>();
|
||||
|
||||
return sql;
|
||||
}
|
||||
|
||||
protected override string GetBaseWhereClause()
|
||||
{
|
||||
return Constants.DatabaseSchema.Tables.KeyValue + ".key = @id";
|
||||
}
|
||||
|
||||
protected override IEnumerable<string> GetDeleteClauses()
|
||||
{
|
||||
return Enumerable.Empty<string>();
|
||||
}
|
||||
|
||||
protected override IKeyValue PerformGet(string id)
|
||||
{
|
||||
var sql = GetBaseQuery(false).Where<KeyValueDto>(x => x.Key == id);
|
||||
var dto = Database.Fetch<KeyValueDto>(sql).FirstOrDefault();
|
||||
return dto == null ? null : Map(dto);
|
||||
}
|
||||
|
||||
protected override IEnumerable<IKeyValue> PerformGetAll(params string[] ids)
|
||||
{
|
||||
var sql = GetBaseQuery(false).WhereIn<KeyValueDto>(x => x.Key, ids);
|
||||
var dtos = Database.Fetch<KeyValueDto>(sql);
|
||||
return dtos.WhereNotNull().Select(Map);
|
||||
}
|
||||
|
||||
protected override IEnumerable<IKeyValue> PerformGetByQuery(IQuery<IKeyValue> query)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
protected override void PersistNewItem(IKeyValue entity)
|
||||
{
|
||||
var dto = Map(entity);
|
||||
Database.Insert(dto);
|
||||
}
|
||||
|
||||
protected override void PersistUpdatedItem(IKeyValue entity)
|
||||
{
|
||||
var dto = Map(entity);
|
||||
Database.Update(dto);
|
||||
}
|
||||
|
||||
private static KeyValueDto Map(IKeyValue keyValue)
|
||||
{
|
||||
if (keyValue == null) return null;
|
||||
|
||||
return new KeyValueDto
|
||||
{
|
||||
Key = keyValue.Identifier,
|
||||
Value = keyValue.Value,
|
||||
UpdateDate = keyValue.UpdateDate,
|
||||
};
|
||||
}
|
||||
|
||||
private static IKeyValue Map(KeyValueDto dto)
|
||||
{
|
||||
if (dto == null) return null;
|
||||
|
||||
return new KeyValue
|
||||
{
|
||||
Identifier = dto.Key,
|
||||
Value = dto.Value,
|
||||
UpdateDate = dto.UpdateDate,
|
||||
};
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -132,7 +132,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
/// </summary>
|
||||
/// <remarks>This method is backed by an <see cref="IAppPolicyCache"/> cache</remarks>
|
||||
/// <param name="entity"></param>
|
||||
public void Save(TEntity entity)
|
||||
public virtual void Save(TEntity entity)
|
||||
{
|
||||
if (entity.HasIdentity == false)
|
||||
CachePolicy.Create(entity, PersistNewItem);
|
||||
|
||||
+10
-1
@@ -32,8 +32,17 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
|
||||
path = path.EnsureEndsWith(".css");
|
||||
|
||||
if (FileSystem.FileExists(path) == false)
|
||||
// if the css directory is changed, references to the old path can still exist (ie in RTE config)
|
||||
// these old references will throw an error, which breaks the RTE
|
||||
// try-catch here makes the request fail silently, and allows RTE to load correctly
|
||||
try
|
||||
{
|
||||
if (FileSystem.FileExists(path) == false)
|
||||
return null;
|
||||
} catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// content will be lazy-loaded when required
|
||||
var created = FileSystem.GetCreated(path).UtcDateTime;
|
||||
|
||||
@@ -636,6 +636,11 @@ ORDER BY colName";
|
||||
}
|
||||
|
||||
public bool Exists(string username)
|
||||
{
|
||||
return ExistsByUserName(username);
|
||||
}
|
||||
|
||||
public bool ExistsByUserName(string username)
|
||||
{
|
||||
var sql = SqlContext.Sql()
|
||||
.SelectCount()
|
||||
@@ -645,6 +650,16 @@ ORDER BY colName";
|
||||
return Database.ExecuteScalar<int>(sql) > 0;
|
||||
}
|
||||
|
||||
public bool ExistsByLogin(string login)
|
||||
{
|
||||
var sql = SqlContext.Sql()
|
||||
.SelectCount()
|
||||
.From<UserDto>()
|
||||
.Where<UserDto>(x => x.Login == login);
|
||||
|
||||
return Database.ExecuteScalar<int>(sql) > 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of <see cref="IUser"/> objects associated with a given group
|
||||
/// </summary>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Umbraco.Core.Persistence.Dtos;
|
||||
|
||||
namespace Umbraco.Core.Persistence
|
||||
{
|
||||
@@ -10,5 +11,20 @@ namespace Umbraco.Core.Persistence
|
||||
if (asDatabase == null) throw new Exception("oops: database.");
|
||||
return asDatabase;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a key/value directly from the database, no scope, nothing.
|
||||
/// </summary>
|
||||
/// <remarks>Used by <see cref="Runtime.CoreRuntime"/> to determine the runtime state.</remarks>
|
||||
public static string GetFromKeyValueTable(this IUmbracoDatabase database, string key)
|
||||
{
|
||||
if (database is null) return null;
|
||||
|
||||
var sql = database.SqlContext.Sql()
|
||||
.Select<KeyValueDto>()
|
||||
.From<KeyValueDto>()
|
||||
.Where<KeyValueDto>(x => x.Key == key);
|
||||
return database.FirstOrDefault<KeyValueDto>(sql)?.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ using Newtonsoft.Json;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Media;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Editors;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
|
||||
@@ -6,6 +6,7 @@ using Umbraco.Core;
|
||||
using Umbraco.Core.Exceptions;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Media;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Core.Strings;
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Media;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Editors;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
|
||||
@@ -58,7 +58,7 @@ namespace Umbraco.Web.PropertyEditors
|
||||
internal static bool IsValidFileExtension(string fileName, IContentSettings contentSettings)
|
||||
{
|
||||
if (fileName.IndexOf('.') <= 0) return false;
|
||||
var extension = new FileInfo(fileName).Extension.TrimStart(".");
|
||||
var extension = fileName.GetFileExtension().TrimStart(".");
|
||||
return contentSettings.IsFileAllowedForUpload(extension);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
using Umbraco.Core.Media;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Serialization;
|
||||
using Umbraco.Core.Strings;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Composing.CompositionExtensions;
|
||||
@@ -7,9 +6,8 @@ using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Configuration.Grid;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.Dashboards;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.Dictionary;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Manifest;
|
||||
using Umbraco.Core.Migrations;
|
||||
@@ -25,14 +23,14 @@ using Umbraco.Core.Services;
|
||||
using Umbraco.Core.Services.Implement;
|
||||
using Umbraco.Core.Strings;
|
||||
using Umbraco.Core.Sync;
|
||||
using Umbraco.Web.Models.PublishedContent;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.Migrations.PostMigrations;
|
||||
using Umbraco.Web.Install;
|
||||
using Umbraco.Web.Trees;
|
||||
using Umbraco.Web.Migrations.PostMigrations;
|
||||
using Umbraco.Web.Models.PublishedContent;
|
||||
using Umbraco.Web.PropertyEditors;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
using Umbraco.Web.Services;
|
||||
using Umbraco.Web.Trees;
|
||||
using IntegerValidator = Umbraco.Core.PropertyEditors.Validators.IntegerValidator;
|
||||
|
||||
namespace Umbraco.Core.Runtime
|
||||
|
||||
@@ -324,7 +324,7 @@ namespace Umbraco.Core.Runtime
|
||||
{
|
||||
Key = MainDomKey,
|
||||
Value = id,
|
||||
Updated = DateTime.Now
|
||||
UpdateDate = DateTime.Now
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Migrations.Upgrade;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Services.Implement;
|
||||
using Umbraco.Core.Persistence.Repositories.Implement;
|
||||
using Umbraco.Core.Sync;
|
||||
|
||||
namespace Umbraco.Core
|
||||
@@ -225,7 +225,7 @@ namespace Umbraco.Core
|
||||
// no scope, no service - just directly accessing the database
|
||||
using (var database = databaseFactory.CreateDatabase())
|
||||
{
|
||||
CurrentMigrationState = KeyValueService.GetValue(database, stateValueKey);
|
||||
CurrentMigrationState = database.GetFromKeyValueTable(stateValueKey);
|
||||
FinalMigrationState = upgrader.Plan.FinalState;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,168 +1,55 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Migrations;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence.Repositories;
|
||||
using Umbraco.Core.Scoping;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.Dtos;
|
||||
|
||||
namespace Umbraco.Core.Services.Implement
|
||||
{
|
||||
internal class KeyValueService : IKeyValueService
|
||||
{
|
||||
private readonly object _initialock = new object();
|
||||
private readonly IScopeProvider _scopeProvider;
|
||||
private readonly ILogger _logger;
|
||||
private readonly IUmbracoVersion _umbracoVersion;
|
||||
private bool _initialized;
|
||||
private readonly IKeyValueRepository _repository;
|
||||
|
||||
public KeyValueService(IScopeProvider scopeProvider, ILogger logger, IUmbracoVersion umbracoVersion)
|
||||
public KeyValueService(IScopeProvider scopeProvider, IKeyValueRepository repository)
|
||||
{
|
||||
_scopeProvider = scopeProvider;
|
||||
_logger = logger;
|
||||
_umbracoVersion = umbracoVersion;
|
||||
}
|
||||
|
||||
private void EnsureInitialized()
|
||||
{
|
||||
lock (_initialock)
|
||||
{
|
||||
if (_initialized) return;
|
||||
Initialize();
|
||||
}
|
||||
}
|
||||
|
||||
private void Initialize()
|
||||
{
|
||||
// the key/value service is entirely self-managed, because it is used by the
|
||||
// upgrader and anything we might change need to happen before everything else
|
||||
|
||||
// if already running 8, either following an upgrade or an install,
|
||||
// then everything should be ok (the table should exist, etc)
|
||||
|
||||
if (_umbracoVersion.LocalVersion != null && _umbracoVersion.LocalVersion.Major >= 8)
|
||||
{
|
||||
_initialized = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// else we are upgrading from 7, we can assume that the locks table
|
||||
// exists, but we need to create everything for key/value
|
||||
|
||||
using (var scope = _scopeProvider.CreateScope())
|
||||
{
|
||||
var context = new MigrationContext(scope.Database, _logger);
|
||||
var initMigration = new InitializeMigration(context);
|
||||
initMigration.Migrate();
|
||||
scope.Complete();
|
||||
}
|
||||
|
||||
// but don't assume we are initializing
|
||||
// we are upgrading from v7 and if anything goes wrong,
|
||||
// the table and everything will be rolled back
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A custom migration that executes standalone during the Initialize phase of this service.
|
||||
/// </summary>
|
||||
internal class InitializeMigration : MigrationBase
|
||||
{
|
||||
public InitializeMigration(IMigrationContext context)
|
||||
: base(context)
|
||||
{ }
|
||||
|
||||
public override void Migrate()
|
||||
{
|
||||
// as long as we are still running 7 this migration will be invoked,
|
||||
// but due to multiple restarts during upgrades, maybe the table
|
||||
// exists already
|
||||
if (TableExists(Constants.DatabaseSchema.Tables.KeyValue))
|
||||
return;
|
||||
|
||||
Logger.Info<KeyValueService>("Creating KeyValue structure.");
|
||||
|
||||
// the locks table was initially created with an identity (auto-increment) primary key,
|
||||
// but we don't want this, especially as we are about to insert a new row into the table,
|
||||
// so here we drop that identity
|
||||
DropLockTableIdentity();
|
||||
|
||||
// insert the lock object for key/value
|
||||
Insert.IntoTable(Constants.DatabaseSchema.Tables.Lock).Row(new {id = Constants.Locks.KeyValues, name = "KeyValues", value = 1}).Do();
|
||||
|
||||
// create the key-value table
|
||||
Create.Table<KeyValueDto>().Do();
|
||||
}
|
||||
|
||||
private void DropLockTableIdentity()
|
||||
{
|
||||
// one cannot simply drop an identity, that requires a bit of work
|
||||
|
||||
// create a temp. id column and copy values
|
||||
Alter.Table(Constants.DatabaseSchema.Tables.Lock).AddColumn("nid").AsInt32().Nullable().Do();
|
||||
Execute.Sql("update umbracoLock set nid = id").Do();
|
||||
|
||||
// drop the id column entirely (cannot just drop identity)
|
||||
Delete.PrimaryKey("PK_umbracoLock").FromTable(Constants.DatabaseSchema.Tables.Lock).Do();
|
||||
Delete.Column("id").FromTable(Constants.DatabaseSchema.Tables.Lock).Do();
|
||||
|
||||
// recreate the id column without identity and copy values
|
||||
Alter.Table(Constants.DatabaseSchema.Tables.Lock).AddColumn("id").AsInt32().Nullable().Do();
|
||||
Execute.Sql("update umbracoLock set id = nid").Do();
|
||||
|
||||
// drop the temp. id column
|
||||
Delete.Column("nid").FromTable(Constants.DatabaseSchema.Tables.Lock).Do();
|
||||
|
||||
// complete the primary key
|
||||
Alter.Table(Constants.DatabaseSchema.Tables.Lock).AlterColumn("id").AsInt32().NotNullable().PrimaryKey("PK_umbracoLock").Do();
|
||||
}
|
||||
_repository = repository;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public string GetValue(string key)
|
||||
{
|
||||
EnsureInitialized();
|
||||
|
||||
using (var scope = _scopeProvider.CreateScope())
|
||||
{
|
||||
var sql = scope.SqlContext.Sql().Select<KeyValueDto>().From<KeyValueDto>().Where<KeyValueDto>(x => x.Key == key);
|
||||
var dto = scope.Database.Fetch<KeyValueDto>(sql).FirstOrDefault();
|
||||
scope.Complete();
|
||||
return dto?.Value;
|
||||
return _repository.Get(key)?.Value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void SetValue(string key, string value)
|
||||
{
|
||||
EnsureInitialized();
|
||||
|
||||
using (var scope = _scopeProvider.CreateScope())
|
||||
{
|
||||
scope.WriteLock(Constants.Locks.KeyValues);
|
||||
|
||||
var sql = scope.SqlContext.Sql().Select<KeyValueDto>().From<KeyValueDto>().Where<KeyValueDto>(x => x.Key == key);
|
||||
var dto = scope.Database.Fetch<KeyValueDto>(sql).FirstOrDefault();
|
||||
|
||||
if (dto == null)
|
||||
var keyValue = _repository.Get(key);
|
||||
if (keyValue == null)
|
||||
{
|
||||
dto = new KeyValueDto
|
||||
keyValue = new KeyValue
|
||||
{
|
||||
Key = key,
|
||||
Identifier = key,
|
||||
Value = value,
|
||||
Updated = DateTime.Now
|
||||
UpdateDate = DateTime.Now,
|
||||
};
|
||||
|
||||
scope.Database.Insert(dto);
|
||||
}
|
||||
else
|
||||
{
|
||||
dto.Value = value;
|
||||
dto.Updated = DateTime.Now;
|
||||
scope.Database.Update(dto);
|
||||
keyValue.Value = value;
|
||||
keyValue.UpdateDate = DateTime.Now;
|
||||
}
|
||||
|
||||
_repository.Save(keyValue);
|
||||
|
||||
scope.Complete();
|
||||
}
|
||||
}
|
||||
@@ -175,43 +62,26 @@ namespace Umbraco.Core.Services.Implement
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool TrySetValue(string key, string originValue, string newValue)
|
||||
public bool TrySetValue(string key, string originalValue, string newValue)
|
||||
{
|
||||
EnsureInitialized();
|
||||
|
||||
using (var scope = _scopeProvider.CreateScope())
|
||||
{
|
||||
scope.WriteLock(Constants.Locks.KeyValues);
|
||||
|
||||
var sql = scope.SqlContext.Sql().Select<KeyValueDto>().From<KeyValueDto>().Where<KeyValueDto>(x => x.Key == key);
|
||||
var dto = scope.Database.Fetch<KeyValueDto>(sql).FirstOrDefault();
|
||||
|
||||
if (dto == null || dto.Value != originValue)
|
||||
var keyValue = _repository.Get(key);
|
||||
if (keyValue == null || keyValue.Value != originalValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
dto.Value = newValue;
|
||||
dto.Updated = DateTime.Now;
|
||||
scope.Database.Update(dto);
|
||||
keyValue.Value = newValue;
|
||||
keyValue.UpdateDate = DateTime.Now;
|
||||
_repository.Save(keyValue);
|
||||
|
||||
scope.Complete();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value directly from the database, no scope, nothing.
|
||||
/// </summary>
|
||||
/// <remarks>Used by <see cref="Runtime.CoreRuntime"/> to determine the runtime state.</remarks>
|
||||
internal static string GetValue(IUmbracoDatabase database, string key)
|
||||
{
|
||||
if (database is null) return null;
|
||||
|
||||
var sql = database.SqlContext.Sql()
|
||||
.Select<KeyValueDto>()
|
||||
.From<KeyValueDto>()
|
||||
.Where<KeyValueDto>(x => x.Key == key);
|
||||
return database.FirstOrDefault<KeyValueDto>(sql)?.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -756,7 +756,6 @@ namespace Umbraco.Core.Services.Implement
|
||||
throw new ArgumentOutOfRangeException(nameof(matchType)); // causes rollback // causes rollback
|
||||
}
|
||||
|
||||
// TODO: Since this is by property value, we need a GetByPropertyQuery on the repo!
|
||||
// TODO: Since this is by property value, we need a GetByPropertyQuery on the repo!
|
||||
return _memberRepository.Get(query);
|
||||
}
|
||||
@@ -959,6 +958,35 @@ namespace Umbraco.Core.Services.Implement
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<int> GetAllRolesIds()
|
||||
{
|
||||
using (var scope = ScopeProvider.CreateScope(autoComplete: true))
|
||||
{
|
||||
scope.ReadLock(Constants.Locks.MemberTree);
|
||||
return _memberGroupRepository.GetMany().Select(x => x.Id).Distinct();
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<int> GetAllRolesIds(int memberId)
|
||||
{
|
||||
using (var scope = ScopeProvider.CreateScope(autoComplete: true))
|
||||
{
|
||||
scope.ReadLock(Constants.Locks.MemberTree);
|
||||
var result = _memberGroupRepository.GetMemberGroupsForMember(memberId);
|
||||
return result.Select(x => x.Id).Distinct();
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<int> GetAllRolesIds(string username)
|
||||
{
|
||||
using (var scope = ScopeProvider.CreateScope(autoComplete: true))
|
||||
{
|
||||
scope.ReadLock(Constants.Locks.MemberTree);
|
||||
var result = _memberGroupRepository.GetMemberGroupsForMember(username);
|
||||
return result.Select(x => x.Id).Distinct();
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<IMember> GetMembersInRole(string roleName)
|
||||
{
|
||||
using (var scope = ScopeProvider.CreateScope(autoComplete: true))
|
||||
@@ -1196,7 +1224,6 @@ namespace Umbraco.Core.Services.Implement
|
||||
{
|
||||
scope.WriteLock(Constants.Locks.MemberTree);
|
||||
|
||||
// TODO: What about content that has the contenttype as part of its composition?
|
||||
// TODO: What about content that has the contenttype as part of its composition?
|
||||
var query = Query<IMember>().Where(x => x.ContentTypeId == memberTypeId);
|
||||
|
||||
|
||||
@@ -124,7 +124,6 @@ namespace Umbraco.Core.Services.Implement
|
||||
}
|
||||
else
|
||||
{
|
||||
//If they are both the same already then there's nothing to update, exit
|
||||
//If they are both the same already then there's nothing to update, exit
|
||||
return OperationResult.Attempt.Succeed(evtMsgs, entry);
|
||||
}
|
||||
|
||||
@@ -72,7 +72,6 @@ namespace Umbraco.Core.Services.Implement
|
||||
_serverRegistrationRepository.Save(server);
|
||||
_serverRegistrationRepository.DeactiveStaleServers(staleTimeout); // triggers a cache reload
|
||||
|
||||
// reload - cheap, cached
|
||||
// reload - cheap, cached
|
||||
|
||||
// default role is single server, but if registrations contain more
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace Umbraco.Core.Services.Implement
|
||||
{
|
||||
using (var scope = ScopeProvider.CreateScope(autoComplete: true))
|
||||
{
|
||||
return _userRepository.Exists(username);
|
||||
return _userRepository.ExistsByUserName(username);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,9 +109,9 @@ namespace Umbraco.Core.Services.Implement
|
||||
User user;
|
||||
using (var scope = ScopeProvider.CreateScope())
|
||||
{
|
||||
var loginExists = scope.Database.ExecuteScalar<int>("SELECT COUNT(id) FROM umbracoUser WHERE userLogin = @Login", new { Login = username }) != 0;
|
||||
var loginExists = _userRepository.ExistsByLogin(username);
|
||||
if (loginExists)
|
||||
throw new ArgumentException("Login already exists"); // causes rollback // causes rollback
|
||||
throw new ArgumentException("Login already exists"); // causes rollback
|
||||
|
||||
user = new User(_globalSettings)
|
||||
{
|
||||
@@ -340,7 +340,6 @@ namespace Umbraco.Core.Services.Implement
|
||||
|
||||
_userRepository.Save(user);
|
||||
|
||||
//Now we have to check for backwards compat hacks
|
||||
//Now we have to check for backwards compat hacks
|
||||
var explicitUser = user as User;
|
||||
if (explicitUser != null && explicitUser.GroupsToSave.Count > 0)
|
||||
@@ -358,7 +357,6 @@ namespace Umbraco.Core.Services.Implement
|
||||
scope.Events.Dispatch(SavedUser, this, saveEventArgs);
|
||||
}
|
||||
|
||||
//commit the whole lot in one go
|
||||
//commit the whole lot in one go
|
||||
scope.Complete();
|
||||
}
|
||||
@@ -370,7 +368,7 @@ namespace Umbraco.Core.Services.Implement
|
||||
/// <returns></returns>
|
||||
public string GetDefaultMemberType()
|
||||
{
|
||||
return "writer";
|
||||
return Constants.Security.WriterGroupAlias;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -355,6 +355,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
|
||||
private static IEnumerable<IPublishedContent> GetByXPath(XPathNodeIterator iterator)
|
||||
{
|
||||
iterator = iterator.Clone();
|
||||
while (iterator.MoveNext())
|
||||
{
|
||||
var xnav = iterator.Current as NavigableNavigator;
|
||||
|
||||
@@ -90,7 +90,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
// determines whether a property has value
|
||||
public override bool HasValue(string culture = null, string segment = null)
|
||||
{
|
||||
_content.VariationContextAccessor.ContextualizeVariation(_variations, ref culture, ref segment);
|
||||
_content.VariationContextAccessor.ContextualizeVariation(_variations, _content.Id, ref culture, ref segment);
|
||||
|
||||
var value = GetSourceValue(culture, segment);
|
||||
var hasValue = PropertyType.IsValue(value, PropertyValueLevel.Source);
|
||||
@@ -194,7 +194,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
|
||||
public override object GetSourceValue(string culture = null, string segment = null)
|
||||
{
|
||||
_content.VariationContextAccessor.ContextualizeVariation(_variations, ref culture, ref segment);
|
||||
_content.VariationContextAccessor.ContextualizeVariation(_variations, _content.Id, ref culture, ref segment);
|
||||
|
||||
if (culture == "" && segment == "")
|
||||
return _sourceValue;
|
||||
@@ -208,7 +208,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
|
||||
public override object GetValue(string culture = null, string segment = null)
|
||||
{
|
||||
_content.VariationContextAccessor.ContextualizeVariation(_variations, ref culture, ref segment);
|
||||
_content.VariationContextAccessor.ContextualizeVariation(_variations, _content.Id, ref culture, ref segment);
|
||||
|
||||
object value;
|
||||
lock (_locko)
|
||||
@@ -229,7 +229,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
|
||||
public override object GetXPathValue(string culture = null, string segment = null)
|
||||
{
|
||||
_content.VariationContextAccessor.ContextualizeVariation(_variations, ref culture, ref segment);
|
||||
_content.VariationContextAccessor.ContextualizeVariation(_variations, _content.Id, ref culture, ref segment);
|
||||
|
||||
lock (_locko)
|
||||
{
|
||||
|
||||
@@ -9,7 +9,6 @@ namespace Umbraco.Tests.Common.Builders
|
||||
_parentBuilder = parentBuilder;
|
||||
}
|
||||
|
||||
|
||||
public TParent Done()
|
||||
{
|
||||
return _parentBuilder;
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Umbraco.Tests.Common.Builders
|
||||
|
||||
public override IConfigurationEditor Build()
|
||||
{
|
||||
var defaultConfiguration = _defaultConfiguration ?? new Dictionary<string, object>();
|
||||
var defaultConfiguration = _defaultConfiguration ?? new Dictionary<string, object>();
|
||||
|
||||
return new ConfigurationEditor()
|
||||
{
|
||||
|
||||
@@ -8,10 +8,16 @@ namespace Umbraco.Tests.Common.Builders
|
||||
: BuilderBase<DataType>,
|
||||
IWithIdBuilder,
|
||||
IWithKeyBuilder,
|
||||
IWithCreatorIdBuilder,
|
||||
IWithCreateDateBuilder,
|
||||
IWithUpdateDateBuilder,
|
||||
IWithDeleteDateBuilder,
|
||||
IWithNameBuilder
|
||||
IWithNameBuilder,
|
||||
IWithParentIdBuilder,
|
||||
IWithTrashedBuilder,
|
||||
IWithLevelBuilder,
|
||||
IWithPathBuilder,
|
||||
IWithSortOrderBuilder
|
||||
{
|
||||
private readonly DataEditorBuilder<DataTypeBuilder> _dataEditorBuilder;
|
||||
private int? _id;
|
||||
@@ -34,54 +40,18 @@ namespace Umbraco.Tests.Common.Builders
|
||||
_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;
|
||||
@@ -133,6 +103,12 @@ namespace Umbraco.Tests.Common.Builders
|
||||
set => _key = value;
|
||||
}
|
||||
|
||||
int? IWithCreatorIdBuilder.CreatorId
|
||||
{
|
||||
get => _creatorId;
|
||||
set => _creatorId = value;
|
||||
}
|
||||
|
||||
DateTime? IWithCreateDateBuilder.CreateDate
|
||||
{
|
||||
get => _createDate;
|
||||
@@ -156,5 +132,35 @@ namespace Umbraco.Tests.Common.Builders
|
||||
get => _name;
|
||||
set => _name = value;
|
||||
}
|
||||
|
||||
int? IWithParentIdBuilder.ParentId
|
||||
{
|
||||
get => _parentId;
|
||||
set => _parentId = value;
|
||||
}
|
||||
|
||||
bool? IWithTrashedBuilder.Trashed
|
||||
{
|
||||
get => _trashed;
|
||||
set => _trashed = value;
|
||||
}
|
||||
|
||||
int? IWithLevelBuilder.Level
|
||||
{
|
||||
get => _level;
|
||||
set => _level = value;
|
||||
}
|
||||
|
||||
string IWithPathBuilder.Path
|
||||
{
|
||||
get => _path;
|
||||
set => _path = value;
|
||||
}
|
||||
|
||||
int? IWithSortOrderBuilder.SortOrder
|
||||
{
|
||||
get => _sortOrder;
|
||||
set => _sortOrder = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ namespace Umbraco.Tests.Common.Builders
|
||||
private DateTime? _updateDate;
|
||||
private string _value;
|
||||
|
||||
|
||||
public DictionaryTranslationBuilder(DictionaryItemBuilder parentBuilder) : base(parentBuilder)
|
||||
{
|
||||
_languageBuilder = new LanguageBuilder<DictionaryTranslationBuilder>(this);
|
||||
|
||||
@@ -12,6 +12,13 @@ namespace Umbraco.Tests.Common.Builders.Extensions
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static T WithCreatorId<T>(this T builder, int creatorId)
|
||||
where T : IWithCreatorIdBuilder
|
||||
{
|
||||
builder.CreatorId = creatorId;
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static T WithCreateDate<T>(this T builder, DateTime createDate)
|
||||
where T : IWithCreateDateBuilder
|
||||
{
|
||||
@@ -46,5 +53,61 @@ namespace Umbraco.Tests.Common.Builders.Extensions
|
||||
builder.Key = key;
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static T WithParentId<T>(this T builder, int parentId)
|
||||
where T : IWithParentIdBuilder
|
||||
{
|
||||
builder.ParentId = parentId;
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static T WithTrashed<T>(this T builder, bool trashed)
|
||||
where T : IWithTrashedBuilder
|
||||
{
|
||||
builder.Trashed = trashed;
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static T WithLevel<T>(this T builder, int level)
|
||||
where T : IWithLevelBuilder
|
||||
{
|
||||
builder.Level = level;
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static T WithPath<T>(this T builder, string path)
|
||||
where T : IWithPathBuilder
|
||||
{
|
||||
builder.Path = path;
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static T WithSortOrder<T>(this T builder, int sortOrder)
|
||||
where T : IWithSortOrderBuilder
|
||||
{
|
||||
builder.SortOrder = sortOrder;
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static T WithDescription<T>(this T builder, string description)
|
||||
where T : IWithDescriptionBuilder
|
||||
{
|
||||
builder.Description = description;
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static T WithIcon<T>(this T builder, string icon)
|
||||
where T : IWithIconBuilder
|
||||
{
|
||||
builder.Icon = icon;
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static T WithThumbnail<T>(this T builder, string thumbnail)
|
||||
where T : IWithThumbnailBuilder
|
||||
{
|
||||
builder.Thumbnail = thumbnail;
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
namespace Umbraco.Tests.Common.Builders.Extensions
|
||||
{
|
||||
public static class StringExtensions
|
||||
{
|
||||
public static string ToCamelCase(this string s)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(s))
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
if (s.Length == 1)
|
||||
{
|
||||
return s.ToLowerInvariant();
|
||||
}
|
||||
|
||||
return char.ToLowerInvariant(s[0]) + s.Substring(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Umbraco.Tests.Common.Builders
|
||||
{
|
||||
public class GenericCollectionBuilder<TBuilder, T>
|
||||
: ChildBuilderBase<TBuilder, IEnumerable<T>>
|
||||
{
|
||||
private readonly IList<T> _collection;
|
||||
|
||||
public GenericCollectionBuilder(TBuilder parentBuilder) : base(parentBuilder)
|
||||
{
|
||||
_collection = new List<T>();
|
||||
}
|
||||
|
||||
public override IEnumerable<T> Build()
|
||||
{
|
||||
return _collection;
|
||||
}
|
||||
|
||||
public GenericCollectionBuilder<TBuilder, T> WithValue(T value)
|
||||
{
|
||||
_collection.Add(value);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Umbraco.Tests.Common.Builders
|
||||
{
|
||||
public class GenericDictionaryBuilder<TBuilder, TKey, TValue>
|
||||
: ChildBuilderBase<TBuilder, IDictionary<TKey, TValue>>
|
||||
{
|
||||
private readonly IDictionary<TKey, TValue> _dictionary;
|
||||
|
||||
public GenericDictionaryBuilder(TBuilder parentBuilder) : base(parentBuilder)
|
||||
{
|
||||
_dictionary = new Dictionary<TKey, TValue>();
|
||||
}
|
||||
|
||||
public override IDictionary<TKey, TValue> Build()
|
||||
{
|
||||
return _dictionary;
|
||||
}
|
||||
|
||||
public GenericDictionaryBuilder<TBuilder, TKey, TValue> WithKeyValue(TKey key, TValue value)
|
||||
{
|
||||
_dictionary.Add(key, value);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Umbraco.Tests.Common.Builders.Interfaces
|
||||
{
|
||||
public interface IWithApprovedBuilder
|
||||
{
|
||||
bool? Approved { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using System;
|
||||
|
||||
namespace Umbraco.Tests.Common.Builders.Interfaces
|
||||
{
|
||||
public interface IWithCreatorIdBuilder
|
||||
{
|
||||
int? CreatorId { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Umbraco.Tests.Common.Builders.Interfaces
|
||||
{
|
||||
public interface IWithDescriptionBuilder
|
||||
{
|
||||
string Description { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Umbraco.Tests.Common.Builders.Interfaces
|
||||
{
|
||||
public interface IWithIconBuilder
|
||||
{
|
||||
string Icon { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Umbraco.Tests.Common.Builders.Interfaces
|
||||
{
|
||||
public interface IWithLevelBuilder
|
||||
{
|
||||
int? Level { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Umbraco.Tests.Common.Builders.Interfaces
|
||||
{
|
||||
public interface IWithParentIdBuilder
|
||||
{
|
||||
int? ParentId { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Umbraco.Tests.Common.Builders.Interfaces
|
||||
{
|
||||
public interface IWithPathBuilder
|
||||
{
|
||||
string Path { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Umbraco.Tests.Common.Builders.Interfaces
|
||||
{
|
||||
public interface IWithSortOrderBuilder
|
||||
{
|
||||
int? SortOrder { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Umbraco.Tests.Common.Builders.Interfaces
|
||||
{
|
||||
public interface IWithThumbnailBuilder
|
||||
{
|
||||
string Thumbnail { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Umbraco.Tests.Common.Builders.Interfaces
|
||||
{
|
||||
public interface IWithTrashedBuilder
|
||||
{
|
||||
bool? Trashed { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,280 @@
|
||||
using System;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Tests.Common.Builders.Interfaces;
|
||||
|
||||
namespace Umbraco.Tests.Common.Builders
|
||||
{
|
||||
public class MemberBuilder
|
||||
: BuilderBase<Member>,
|
||||
IWithIdBuilder,
|
||||
IWithKeyBuilder,
|
||||
IWithCreatorIdBuilder,
|
||||
IWithCreateDateBuilder,
|
||||
IWithUpdateDateBuilder,
|
||||
IWithNameBuilder,
|
||||
IWithTrashedBuilder,
|
||||
IWithLevelBuilder,
|
||||
IWithPathBuilder,
|
||||
IWithSortOrderBuilder
|
||||
{
|
||||
private MemberTypeBuilder _memberTypeBuilder;
|
||||
private GenericCollectionBuilder<MemberBuilder, string> _memberGroupsBuilder;
|
||||
private GenericDictionaryBuilder<MemberBuilder, string, object> _additionalDataBuilder;
|
||||
private GenericDictionaryBuilder<MemberBuilder, string, object> _propertyDataBuilder;
|
||||
|
||||
private int? _id;
|
||||
private Guid? _key;
|
||||
private DateTime? _createDate;
|
||||
private DateTime? _updateDate;
|
||||
private string _name;
|
||||
private int? _creatorId;
|
||||
private string _username;
|
||||
private string _rawPasswordValue;
|
||||
private string _email;
|
||||
private int? _failedPasswordAttempts;
|
||||
private int? _level;
|
||||
private string _path;
|
||||
private bool? _isApproved;
|
||||
private bool? _isLockedOut;
|
||||
private DateTime? _lastLockoutDate;
|
||||
private DateTime? _lastLoginDate;
|
||||
private DateTime? _lastPasswordChangeDate;
|
||||
private int? _sortOrder;
|
||||
private bool? _trashed;
|
||||
private int? _propertyIdsIncrementingFrom;
|
||||
|
||||
public MemberBuilder WithUserName(string username)
|
||||
{
|
||||
_username = username;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MemberBuilder WithEmail(string email)
|
||||
{
|
||||
_email = email;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MemberBuilder WithRawPasswordValue(string rawPasswordValue)
|
||||
{
|
||||
_rawPasswordValue = rawPasswordValue;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MemberBuilder WithFailedPasswordAttempts(int failedPasswordAttempts)
|
||||
{
|
||||
_failedPasswordAttempts = failedPasswordAttempts;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MemberBuilder WithIsApproved(bool isApproved)
|
||||
{
|
||||
_isApproved = isApproved;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MemberBuilder WithIsLockedOut(bool isLockedOut)
|
||||
{
|
||||
_isLockedOut = isLockedOut;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MemberBuilder WithLastLockoutDate(DateTime lastLockoutDate)
|
||||
{
|
||||
_lastLockoutDate = lastLockoutDate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MemberBuilder WithLastLoginDate(DateTime lastLoginDate)
|
||||
{
|
||||
_lastLoginDate = lastLoginDate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MemberBuilder WithLastPasswordChangeDate(DateTime lastPasswordChangeDate)
|
||||
{
|
||||
_lastPasswordChangeDate = lastPasswordChangeDate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MemberBuilder WithPropertyIdsIncrementingFrom(int propertyIdsIncrementingFrom)
|
||||
{
|
||||
_propertyIdsIncrementingFrom = propertyIdsIncrementingFrom;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MemberTypeBuilder AddMemberType()
|
||||
{
|
||||
var builder = new MemberTypeBuilder(this);
|
||||
_memberTypeBuilder = builder;
|
||||
return builder;
|
||||
}
|
||||
|
||||
public GenericCollectionBuilder<MemberBuilder, string> AddMemberGroups()
|
||||
{
|
||||
var builder = new GenericCollectionBuilder<MemberBuilder, string>(this);
|
||||
_memberGroupsBuilder = builder;
|
||||
return builder;
|
||||
}
|
||||
|
||||
public GenericDictionaryBuilder<MemberBuilder, string, object> AddAdditionalData()
|
||||
{
|
||||
var builder = new GenericDictionaryBuilder<MemberBuilder, string, object>(this);
|
||||
_additionalDataBuilder = builder;
|
||||
return builder;
|
||||
}
|
||||
|
||||
public GenericDictionaryBuilder<MemberBuilder, string, object> AddPropertyData()
|
||||
{
|
||||
var builder = new GenericDictionaryBuilder<MemberBuilder, string, object>(this);
|
||||
_propertyDataBuilder = builder;
|
||||
return builder;
|
||||
}
|
||||
|
||||
public override Member Build()
|
||||
{
|
||||
var id = _id ?? 1;
|
||||
var key = _key ?? Guid.NewGuid();
|
||||
var createDate = _createDate ?? DateTime.Now;
|
||||
var updateDate = _updateDate ?? DateTime.Now;
|
||||
var name = _name ?? Guid.NewGuid().ToString();
|
||||
var creatorId = _creatorId ?? 1;
|
||||
var username = _username ?? string.Empty;
|
||||
var email = _email ?? string.Empty;
|
||||
var rawPasswordValue = _rawPasswordValue ?? string.Empty;
|
||||
var failedPasswordAttempts = _failedPasswordAttempts ?? 0;
|
||||
var level = _level ?? 1;
|
||||
var path = _path ?? "-1";
|
||||
var isApproved = _isApproved ?? false;
|
||||
var isLockedOut = _isLockedOut ?? false;
|
||||
var lastLockoutDate = _lastLockoutDate ?? DateTime.Now;
|
||||
var lastLoginDate = _lastLoginDate ?? DateTime.Now;
|
||||
var lastPasswordChangeDate = _lastPasswordChangeDate ?? DateTime.Now;
|
||||
var sortOrder = _sortOrder ?? 0;
|
||||
var trashed = _trashed ?? false;
|
||||
|
||||
if (_memberTypeBuilder == null)
|
||||
{
|
||||
throw new InvalidOperationException("A member cannot be constructed without providing a member type (use AddMemberType).");
|
||||
}
|
||||
|
||||
var memberType = _memberTypeBuilder.Build();
|
||||
|
||||
var member = new Member(name, email, username, rawPasswordValue, memberType)
|
||||
{
|
||||
Id = id,
|
||||
Key = key,
|
||||
CreateDate = createDate,
|
||||
UpdateDate = updateDate,
|
||||
CreatorId = creatorId,
|
||||
Level = level,
|
||||
Path = path,
|
||||
SortOrder = sortOrder,
|
||||
Trashed = trashed,
|
||||
};
|
||||
|
||||
if (_propertyIdsIncrementingFrom.HasValue)
|
||||
{
|
||||
var i = _propertyIdsIncrementingFrom.Value;
|
||||
foreach (var property in member.Properties)
|
||||
{
|
||||
property.Id = ++i;
|
||||
}
|
||||
}
|
||||
|
||||
member.FailedPasswordAttempts = failedPasswordAttempts;
|
||||
member.IsApproved = isApproved;
|
||||
member.IsLockedOut = isLockedOut;
|
||||
member.LastLockoutDate = lastLockoutDate;
|
||||
member.LastLoginDate = lastLoginDate;
|
||||
member.LastPasswordChangeDate = lastPasswordChangeDate;
|
||||
|
||||
if (_memberGroupsBuilder != null)
|
||||
{
|
||||
member.Groups = _memberGroupsBuilder.Build();
|
||||
}
|
||||
|
||||
if (_additionalDataBuilder != null)
|
||||
{
|
||||
var additionalData = _additionalDataBuilder.Build();
|
||||
foreach (var kvp in additionalData)
|
||||
{
|
||||
member.AdditionalData.Add(kvp.Key, kvp.Value);
|
||||
}
|
||||
}
|
||||
|
||||
if (_propertyDataBuilder != null)
|
||||
{
|
||||
var propertyData = _propertyDataBuilder.Build();
|
||||
foreach (var kvp in propertyData)
|
||||
{
|
||||
member.SetValue(kvp.Key, kvp.Value);
|
||||
}
|
||||
|
||||
member.ResetDirtyProperties(false);
|
||||
}
|
||||
|
||||
return member;
|
||||
}
|
||||
|
||||
int? IWithIdBuilder.Id
|
||||
{
|
||||
get => _id;
|
||||
set => _id = value;
|
||||
}
|
||||
|
||||
Guid? IWithKeyBuilder.Key
|
||||
{
|
||||
get => _key;
|
||||
set => _key = value;
|
||||
}
|
||||
|
||||
int? IWithCreatorIdBuilder.CreatorId
|
||||
{
|
||||
get => _creatorId;
|
||||
set => _creatorId = value;
|
||||
}
|
||||
|
||||
DateTime? IWithCreateDateBuilder.CreateDate
|
||||
{
|
||||
get => _createDate;
|
||||
set => _createDate = value;
|
||||
}
|
||||
|
||||
DateTime? IWithUpdateDateBuilder.UpdateDate
|
||||
{
|
||||
get => _updateDate;
|
||||
set => _updateDate = value;
|
||||
}
|
||||
|
||||
string IWithNameBuilder.Name
|
||||
{
|
||||
get => _name;
|
||||
set => _name = value;
|
||||
}
|
||||
|
||||
bool? IWithTrashedBuilder.Trashed
|
||||
{
|
||||
get => _trashed;
|
||||
set => _trashed = value;
|
||||
}
|
||||
|
||||
int? IWithLevelBuilder.Level
|
||||
{
|
||||
get => _level;
|
||||
set => _level = value;
|
||||
}
|
||||
|
||||
string IWithPathBuilder.Path
|
||||
{
|
||||
get => _path;
|
||||
set => _path = value;
|
||||
}
|
||||
|
||||
int? IWithSortOrderBuilder.SortOrder
|
||||
{
|
||||
get => _sortOrder;
|
||||
set => _sortOrder = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
using System;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Tests.Common.Builders.Interfaces;
|
||||
|
||||
namespace Umbraco.Tests.Common.Builders
|
||||
{
|
||||
public class MemberGroupBuilder
|
||||
: BuilderBase<MemberGroup>,
|
||||
IWithIdBuilder,
|
||||
IWithKeyBuilder,
|
||||
IWithCreatorIdBuilder,
|
||||
IWithCreateDateBuilder,
|
||||
IWithUpdateDateBuilder,
|
||||
IWithNameBuilder
|
||||
{
|
||||
private GenericDictionaryBuilder<MemberGroupBuilder, string, object> _additionalDataBuilder;
|
||||
|
||||
private int? _id;
|
||||
private Guid? _key;
|
||||
private DateTime? _createDate;
|
||||
private DateTime? _updateDate;
|
||||
private string _name;
|
||||
private int? _creatorId;
|
||||
|
||||
public GenericDictionaryBuilder<MemberGroupBuilder, string, object> AddAdditionalData()
|
||||
{
|
||||
var builder = new GenericDictionaryBuilder<MemberGroupBuilder, string, object>(this);
|
||||
_additionalDataBuilder = builder;
|
||||
return builder;
|
||||
}
|
||||
|
||||
public override MemberGroup Build()
|
||||
{
|
||||
var id = _id ?? 1;
|
||||
var key = _key ?? Guid.NewGuid();
|
||||
var createDate = _createDate ?? DateTime.Now;
|
||||
var updateDate = _updateDate ?? DateTime.Now;
|
||||
var name = _name ?? Guid.NewGuid().ToString();
|
||||
var creatorId = _creatorId ?? 1;
|
||||
|
||||
var memberGroup = new MemberGroup
|
||||
{
|
||||
Id = id,
|
||||
Key = key,
|
||||
CreateDate = createDate,
|
||||
UpdateDate = updateDate,
|
||||
Name = name,
|
||||
CreatorId = creatorId,
|
||||
};
|
||||
|
||||
if (_additionalDataBuilder != null)
|
||||
{
|
||||
var additionalData = _additionalDataBuilder.Build();
|
||||
foreach (var kvp in additionalData)
|
||||
{
|
||||
memberGroup.AdditionalData.Add(kvp.Key, kvp.Value);
|
||||
}
|
||||
}
|
||||
|
||||
return memberGroup;
|
||||
}
|
||||
|
||||
int? IWithIdBuilder.Id
|
||||
{
|
||||
get => _id;
|
||||
set => _id = value;
|
||||
}
|
||||
|
||||
Guid? IWithKeyBuilder.Key
|
||||
{
|
||||
get => _key;
|
||||
set => _key = value;
|
||||
}
|
||||
|
||||
int? IWithCreatorIdBuilder.CreatorId
|
||||
{
|
||||
get => _creatorId;
|
||||
set => _creatorId = value;
|
||||
}
|
||||
|
||||
DateTime? IWithCreateDateBuilder.CreateDate
|
||||
{
|
||||
get => _createDate;
|
||||
set => _createDate = value;
|
||||
}
|
||||
|
||||
DateTime? IWithUpdateDateBuilder.UpdateDate
|
||||
{
|
||||
get => _updateDate;
|
||||
set => _updateDate = value;
|
||||
}
|
||||
|
||||
string IWithNameBuilder.Name
|
||||
{
|
||||
get => _name;
|
||||
set => _name = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Strings;
|
||||
using Umbraco.Tests.Common.Builders.Extensions;
|
||||
using Umbraco.Tests.Common.Builders.Interfaces;
|
||||
|
||||
namespace Umbraco.Tests.Common.Builders
|
||||
{
|
||||
public class MemberTypeBuilder
|
||||
: ChildBuilderBase<MemberBuilder, MemberType>,
|
||||
IWithIdBuilder,
|
||||
IWithAliasBuilder,
|
||||
IWithNameBuilder,
|
||||
IWithParentIdBuilder,
|
||||
IWithSortOrderBuilder,
|
||||
IWithCreatorIdBuilder,
|
||||
IWithDescriptionBuilder,
|
||||
IWithIconBuilder,
|
||||
IWithThumbnailBuilder,
|
||||
IWithTrashedBuilder
|
||||
{
|
||||
private readonly List<PropertyGroupBuilder> _propertyGroupBuilders = new List<PropertyGroupBuilder>();
|
||||
|
||||
private int? _id;
|
||||
private string _alias;
|
||||
private string _name;
|
||||
private int? _parentId;
|
||||
private int? _sortOrder;
|
||||
private int? _creatorId;
|
||||
private string _description;
|
||||
private string _icon;
|
||||
private string _thumbnail;
|
||||
private bool? _trashed;
|
||||
|
||||
public MemberTypeBuilder(MemberBuilder parentBuilder) : base(parentBuilder)
|
||||
{
|
||||
}
|
||||
|
||||
public MemberTypeBuilder WithMembershipPropertyGroup()
|
||||
{
|
||||
var builder = new PropertyGroupBuilder(this)
|
||||
.WithName(Constants.Conventions.Member.StandardPropertiesGroupName)
|
||||
.WithSortOrder(1)
|
||||
.AddPropertyType()
|
||||
.WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.TextArea)
|
||||
.WithValueStorageType(ValueStorageType.Ntext)
|
||||
.WithAlias(Constants.Conventions.Member.Comments)
|
||||
.WithName(Constants.Conventions.Member.CommentsLabel)
|
||||
.Done()
|
||||
.AddPropertyType()
|
||||
.WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.Boolean)
|
||||
.WithValueStorageType(ValueStorageType.Integer)
|
||||
.WithAlias(Constants.Conventions.Member.IsApproved)
|
||||
.WithName(Constants.Conventions.Member.IsApprovedLabel)
|
||||
.Done()
|
||||
.AddPropertyType()
|
||||
.WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.Boolean)
|
||||
.WithValueStorageType(ValueStorageType.Integer)
|
||||
.WithAlias(Constants.Conventions.Member.IsLockedOut)
|
||||
.WithName(Constants.Conventions.Member.IsLockedOutLabel)
|
||||
.Done()
|
||||
.AddPropertyType()
|
||||
.WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.Label)
|
||||
.WithValueStorageType(ValueStorageType.Date)
|
||||
.WithAlias(Constants.Conventions.Member.LastLoginDate)
|
||||
.WithName(Constants.Conventions.Member.LastLoginDateLabel)
|
||||
.Done()
|
||||
.AddPropertyType()
|
||||
.WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.Label)
|
||||
.WithValueStorageType(ValueStorageType.Date)
|
||||
.WithAlias(Constants.Conventions.Member.LastPasswordChangeDate)
|
||||
.WithName(Constants.Conventions.Member.LastPasswordChangeDateLabel)
|
||||
.Done()
|
||||
.AddPropertyType()
|
||||
.WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.Label)
|
||||
.WithValueStorageType(ValueStorageType.Date)
|
||||
.WithAlias(Constants.Conventions.Member.LastLockoutDate)
|
||||
.WithName(Constants.Conventions.Member.LastLockoutDateLabel)
|
||||
.Done()
|
||||
.AddPropertyType()
|
||||
.WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.Label)
|
||||
.WithValueStorageType(ValueStorageType.Integer)
|
||||
.WithAlias(Constants.Conventions.Member.FailedPasswordAttempts)
|
||||
.WithName(Constants.Conventions.Member.FailedPasswordAttemptsLabel)
|
||||
.Done();
|
||||
_propertyGroupBuilders.Add(builder);
|
||||
return this;
|
||||
}
|
||||
|
||||
public PropertyGroupBuilder AddPropertyGroup()
|
||||
{
|
||||
var builder = new PropertyGroupBuilder(this);
|
||||
_propertyGroupBuilders.Add(builder);
|
||||
return builder;
|
||||
}
|
||||
|
||||
public override MemberType Build()
|
||||
{
|
||||
var id = _id ?? 1;
|
||||
var name = _name ?? Guid.NewGuid().ToString();
|
||||
var alias = _alias ?? name.ToCamelCase();
|
||||
var parentId = _parentId ?? -1;
|
||||
var sortOrder = _sortOrder ?? 0;
|
||||
var description = _description ?? string.Empty;
|
||||
var icon = _icon ?? string.Empty;
|
||||
var thumbnail = _thumbnail ?? string.Empty;
|
||||
var creatorId = _creatorId ?? 0;
|
||||
var trashed = _trashed ?? false;
|
||||
|
||||
var shortStringHelper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig());
|
||||
|
||||
var memberType = new MemberType(shortStringHelper, parentId)
|
||||
{
|
||||
Id = id,
|
||||
Alias = alias,
|
||||
Name = name,
|
||||
SortOrder = sortOrder,
|
||||
Description = description,
|
||||
Icon = icon,
|
||||
Thumbnail = thumbnail,
|
||||
CreatorId = creatorId,
|
||||
Trashed = trashed,
|
||||
};
|
||||
|
||||
foreach (var propertyGroup in _propertyGroupBuilders.Select(x => x.Build()))
|
||||
{
|
||||
memberType.PropertyGroups.Add(propertyGroup);
|
||||
}
|
||||
|
||||
memberType.ResetDirtyProperties(false);
|
||||
|
||||
return memberType;
|
||||
}
|
||||
|
||||
int? IWithIdBuilder.Id
|
||||
{
|
||||
get => _id;
|
||||
set => _id = value;
|
||||
}
|
||||
|
||||
string IWithAliasBuilder.Alias
|
||||
{
|
||||
get => _alias;
|
||||
set => _alias = value;
|
||||
}
|
||||
|
||||
string IWithNameBuilder.Name
|
||||
{
|
||||
get => _name;
|
||||
set => _name = value;
|
||||
}
|
||||
|
||||
int? IWithParentIdBuilder.ParentId
|
||||
{
|
||||
get => _parentId;
|
||||
set => _parentId = value;
|
||||
}
|
||||
|
||||
int? IWithSortOrderBuilder.SortOrder
|
||||
{
|
||||
get => _sortOrder;
|
||||
set => _sortOrder = value;
|
||||
}
|
||||
|
||||
int? IWithCreatorIdBuilder.CreatorId
|
||||
{
|
||||
get => _creatorId;
|
||||
set => _creatorId = value;
|
||||
}
|
||||
|
||||
string IWithDescriptionBuilder.Description
|
||||
{
|
||||
get => _description;
|
||||
set => _description = value;
|
||||
}
|
||||
|
||||
string IWithIconBuilder.Icon
|
||||
{
|
||||
get => _icon;
|
||||
set => _icon = value;
|
||||
}
|
||||
|
||||
string IWithThumbnailBuilder.Thumbnail
|
||||
{
|
||||
get => _thumbnail;
|
||||
set => _thumbnail = value;
|
||||
}
|
||||
|
||||
bool? IWithTrashedBuilder.Trashed
|
||||
{
|
||||
get => _trashed;
|
||||
set => _trashed = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Tests.Common.Builders.Interfaces;
|
||||
|
||||
namespace Umbraco.Tests.Common.Builders
|
||||
{
|
||||
public class PropertyGroupBuilder
|
||||
: ChildBuilderBase<MemberTypeBuilder, PropertyGroup>, // TODO: likely want to generalise this, so can use for document and media types too.
|
||||
IWithNameBuilder,
|
||||
IWithSortOrderBuilder
|
||||
{
|
||||
private readonly List<PropertyTypeBuilder> _propertyTypeBuilders = new List<PropertyTypeBuilder>();
|
||||
|
||||
private string _name;
|
||||
private int? _sortOrder;
|
||||
|
||||
public PropertyGroupBuilder(MemberTypeBuilder parentBuilder) : base(parentBuilder)
|
||||
{
|
||||
}
|
||||
|
||||
public PropertyTypeBuilder AddPropertyType()
|
||||
{
|
||||
var builder = new PropertyTypeBuilder(this);
|
||||
_propertyTypeBuilders.Add(builder);
|
||||
return builder;
|
||||
}
|
||||
|
||||
public override PropertyGroup Build()
|
||||
{
|
||||
var name = _name ?? Guid.NewGuid().ToString();
|
||||
var sortOrder = _sortOrder ?? 0;
|
||||
|
||||
var properties = new PropertyTypeCollection(false);
|
||||
foreach (var propertyType in _propertyTypeBuilders.Select(x => x.Build()))
|
||||
{
|
||||
properties.Add(propertyType);
|
||||
}
|
||||
|
||||
return new PropertyGroup(properties)
|
||||
{
|
||||
Name = name,
|
||||
SortOrder = sortOrder,
|
||||
};
|
||||
}
|
||||
|
||||
string IWithNameBuilder.Name
|
||||
{
|
||||
get => _name;
|
||||
set => _name = value;
|
||||
}
|
||||
|
||||
int? IWithSortOrderBuilder.SortOrder
|
||||
{
|
||||
get => _sortOrder;
|
||||
set => _sortOrder = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
using System;
|
||||
using Moq;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Strings;
|
||||
using Umbraco.Tests.Common.Builders.Extensions;
|
||||
using Umbraco.Tests.Common.Builders.Interfaces;
|
||||
|
||||
namespace Umbraco.Tests.Common.Builders
|
||||
{
|
||||
public class PropertyTypeBuilder
|
||||
: ChildBuilderBase<PropertyGroupBuilder, PropertyType>,
|
||||
IWithAliasBuilder,
|
||||
IWithNameBuilder,
|
||||
IWithSortOrderBuilder,
|
||||
IWithDescriptionBuilder
|
||||
{
|
||||
private string _propertyEditorAlias;
|
||||
private ValueStorageType? _valueStorageType;
|
||||
private string _alias;
|
||||
private string _name;
|
||||
private int? _sortOrder;
|
||||
private string _description;
|
||||
private int? _dataTypeId;
|
||||
|
||||
public PropertyTypeBuilder(PropertyGroupBuilder parentBuilder) : base(parentBuilder)
|
||||
{
|
||||
}
|
||||
|
||||
public PropertyTypeBuilder WithPropertyEditorAlias(string propertyEditorAlias)
|
||||
{
|
||||
_propertyEditorAlias = propertyEditorAlias;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PropertyTypeBuilder WithValueStorageType(ValueStorageType valueStorageType)
|
||||
{
|
||||
_valueStorageType = valueStorageType;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PropertyTypeBuilder WithDataTypeId(int dataTypeId)
|
||||
{
|
||||
_dataTypeId = dataTypeId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public override PropertyType Build()
|
||||
{
|
||||
var propertyEditorAlias = _propertyEditorAlias ?? Guid.NewGuid().ToString().ToCamelCase();
|
||||
var valueStorageType = _valueStorageType ?? ValueStorageType.Ntext;
|
||||
var name = _name ?? Guid.NewGuid().ToString();
|
||||
var alias = _alias ?? name.ToCamelCase();
|
||||
var sortOrder = _sortOrder ?? 0;
|
||||
var dataTypeId = _dataTypeId ?? 0;
|
||||
var description = _description ?? string.Empty;
|
||||
|
||||
var shortStringHelper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig());
|
||||
|
||||
return new PropertyType(shortStringHelper, propertyEditorAlias, valueStorageType)
|
||||
{
|
||||
Alias = alias,
|
||||
Name = name,
|
||||
SortOrder = sortOrder,
|
||||
DataTypeId = dataTypeId,
|
||||
Description = description,
|
||||
};
|
||||
}
|
||||
|
||||
string IWithAliasBuilder.Alias
|
||||
{
|
||||
get => _alias;
|
||||
set => _alias = value;
|
||||
}
|
||||
|
||||
string IWithNameBuilder.Name
|
||||
{
|
||||
get => _name;
|
||||
set => _name = value;
|
||||
}
|
||||
|
||||
int? IWithSortOrderBuilder.SortOrder
|
||||
{
|
||||
get => _sortOrder;
|
||||
set => _sortOrder = value;
|
||||
}
|
||||
|
||||
string IWithDescriptionBuilder.Description
|
||||
{
|
||||
get => _description;
|
||||
set => _description = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,22 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Moq;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Configuration.Models;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
using Umbraco.Tests.Common.Builders.Interfaces;
|
||||
|
||||
namespace Umbraco.Tests.Common.Builders
|
||||
{
|
||||
public class UserBuilder
|
||||
: BuilderBase<User>,
|
||||
IWithIdBuilder
|
||||
|
||||
public class UserBuilder : UserBuilder<object>
|
||||
{
|
||||
public UserBuilder() : base(null)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class UserBuilder<TParent>
|
||||
: ChildBuilderBase<TParent, User>,
|
||||
IWithIdBuilder,
|
||||
IWithNameBuilder,
|
||||
IWithApprovedBuilder
|
||||
{
|
||||
private int? _id;
|
||||
private string _language;
|
||||
@@ -20,63 +26,57 @@ namespace Umbraco.Tests.Common.Builders
|
||||
private bool? _isLockedOut;
|
||||
private string _email;
|
||||
private string _username;
|
||||
private string _defaultLang;
|
||||
private string _suffix = string.Empty;
|
||||
private string _defaultLang;
|
||||
|
||||
public UserBuilder WithDefaultUILanguage(string defaultLang)
|
||||
|
||||
public UserBuilder(TParent parentBuilder) : base(parentBuilder)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public UserBuilder<TParent> WithDefaultUILanguage(string defaultLang)
|
||||
{
|
||||
_defaultLang = defaultLang;
|
||||
return this;
|
||||
}
|
||||
|
||||
public UserBuilder WithLanguage(string language)
|
||||
public UserBuilder<TParent> WithLanguage(string language)
|
||||
{
|
||||
_language = language;
|
||||
return this;
|
||||
}
|
||||
|
||||
public UserBuilder WithApproved(bool approved)
|
||||
{
|
||||
_approved = approved;
|
||||
return this;
|
||||
}
|
||||
|
||||
public UserBuilder WithRawPassword(string rawPassword)
|
||||
public UserBuilder<TParent> WithRawPassword(string rawPassword)
|
||||
{
|
||||
_rawPassword = rawPassword;
|
||||
return this;
|
||||
}
|
||||
|
||||
public UserBuilder WithEmail(string email)
|
||||
public UserBuilder<TParent> WithEmail(string email)
|
||||
{
|
||||
_email = email;
|
||||
return this;
|
||||
}
|
||||
|
||||
public UserBuilder WithUsername(string username)
|
||||
public UserBuilder<TParent> WithUsername(string username)
|
||||
{
|
||||
_username = username;
|
||||
return this;
|
||||
}
|
||||
|
||||
public UserBuilder WithLockedOut(bool isLockedOut)
|
||||
public UserBuilder<TParent> WithLockedOut(bool isLockedOut)
|
||||
{
|
||||
_isLockedOut = isLockedOut;
|
||||
return this;
|
||||
}
|
||||
|
||||
public UserBuilder WithName(string name)
|
||||
{
|
||||
_name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Will suffix the name, email and username for testing
|
||||
/// </summary>
|
||||
/// <param name="suffix"></param>
|
||||
/// <returns></returns>
|
||||
public UserBuilder WithSuffix(string suffix)
|
||||
public UserBuilder<TParent> WithSuffix(string suffix)
|
||||
{
|
||||
_suffix = suffix;
|
||||
return this;
|
||||
@@ -84,16 +84,25 @@ namespace Umbraco.Tests.Common.Builders
|
||||
|
||||
public override User Build()
|
||||
{
|
||||
var globalSettings = Mock.Of<IGlobalSettings>(x => x.DefaultUILanguage == (_defaultLang ?? "en-US"));
|
||||
return new User(globalSettings,
|
||||
_name ?? "TestUser" + _suffix,
|
||||
_email ?? "test" + _suffix + "@test.com",
|
||||
_username ?? "TestUser" + _suffix,
|
||||
_rawPassword ?? "abcdefghijklmnopqrstuvwxyz")
|
||||
var globalSettings = new GlobalSettingsBuilder().WithDefaultUiLanguage(_defaultLang).Build();
|
||||
var name = _name ?? "TestUser" + _suffix;
|
||||
var email = _email ?? "test" + _suffix + "@test.com";
|
||||
var username = _username ?? "TestUser" + _suffix;
|
||||
var rawPassword = _rawPassword ?? "abcdefghijklmnopqrstuvwxyz";
|
||||
var language = _language ?? globalSettings.DefaultUILanguage;
|
||||
var isLockedOut = _isLockedOut ?? false;
|
||||
var approved = _approved ?? true;
|
||||
|
||||
return new User(
|
||||
globalSettings,
|
||||
name,
|
||||
email,
|
||||
username,
|
||||
rawPassword)
|
||||
{
|
||||
Language = _language ?? _defaultLang ?? "en-US",
|
||||
IsLockedOut = _isLockedOut ?? false,
|
||||
IsApproved = _approved ?? true
|
||||
Language = language,
|
||||
IsLockedOut = isLockedOut,
|
||||
IsApproved = approved
|
||||
};
|
||||
}
|
||||
|
||||
@@ -102,5 +111,17 @@ namespace Umbraco.Tests.Common.Builders
|
||||
get => _id;
|
||||
set => _id = value;
|
||||
}
|
||||
|
||||
string IWithNameBuilder.Name
|
||||
{
|
||||
get => _name;
|
||||
set => _name = value;
|
||||
}
|
||||
|
||||
bool? IWithApprovedBuilder.Approved
|
||||
{
|
||||
get => _approved;
|
||||
set => _approved = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,9 +6,20 @@ using Umbraco.Tests.Common.Builders.Interfaces;
|
||||
|
||||
namespace Umbraco.Tests.Common.Builders
|
||||
{
|
||||
public class UserGroupBuilder
|
||||
: BuilderBase<IUserGroup>,
|
||||
IWithIdBuilder
|
||||
|
||||
public class UserGroupBuilder : UserGroupBuilder<object>
|
||||
{
|
||||
public UserGroupBuilder() : base(null)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class UserGroupBuilder<TParent>
|
||||
: ChildBuilderBase<TParent, IUserGroup>,
|
||||
IWithIdBuilder,
|
||||
IWithIconBuilder,
|
||||
IWithAliasBuilder,
|
||||
IWithNameBuilder
|
||||
{
|
||||
private int? _startContentId;
|
||||
private int? _startMediaId;
|
||||
@@ -20,12 +31,16 @@ namespace Umbraco.Tests.Common.Builders
|
||||
private string _suffix;
|
||||
private int? _id;
|
||||
|
||||
public UserGroupBuilder(TParent parentBuilder) : base(parentBuilder)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Will suffix the name and alias for testing
|
||||
/// </summary>
|
||||
/// <param name="suffix"></param>
|
||||
/// <returns></returns>
|
||||
public UserGroupBuilder WithSuffix(string suffix)
|
||||
public UserGroupBuilder<TParent> WithSuffix(string suffix)
|
||||
{
|
||||
_suffix = suffix;
|
||||
return this;
|
||||
@@ -61,5 +76,24 @@ namespace Umbraco.Tests.Common.Builders
|
||||
get => _id;
|
||||
set => _id = value;
|
||||
}
|
||||
|
||||
|
||||
string IWithIconBuilder.Icon
|
||||
{
|
||||
get => _icon;
|
||||
set => _icon = value;
|
||||
}
|
||||
|
||||
string IWithAliasBuilder.Alias
|
||||
{
|
||||
get => _alias;
|
||||
set => _alias = value;
|
||||
}
|
||||
|
||||
string IWithNameBuilder.Name
|
||||
{
|
||||
get => _name;
|
||||
set => _name = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ namespace Umbraco.Tests.Integration.Extensions
|
||||
// dynamically change the config status
|
||||
var umbVersion = app.ApplicationServices.GetRequiredService<IUmbracoVersion>();
|
||||
var config = app.ApplicationServices.GetRequiredService<IConfiguration>();
|
||||
config[GlobalSettings.Prefix + "ConfigurationStatus"] = umbVersion.SemanticVersion.ToString();
|
||||
config[Constants.Configuration.ConfigGlobalPrefix + "ConfigurationStatus"] = umbVersion.SemanticVersion.ToString();
|
||||
|
||||
// re-run the runtime level check
|
||||
var profilingLogger = app.ApplicationServices.GetRequiredService<IProfilingLogger>();
|
||||
|
||||
@@ -18,6 +18,7 @@ using Umbraco.Core.Runtime;
|
||||
using Umbraco.Tests.Common;
|
||||
using Umbraco.Web.BackOffice;
|
||||
using Umbraco.Web.BackOffice.AspNetCore;
|
||||
using Umbraco.Web.Common.AspNetCore;
|
||||
using IHostingEnvironment = Umbraco.Core.Hosting.IHostingEnvironment;
|
||||
|
||||
namespace Umbraco.Tests.Integration.Implementations
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Web.BackOffice.AspNetCore;
|
||||
using Umbraco.Web.Common.AspNetCore;
|
||||
|
||||
namespace Umbraco.Tests.Integration.Implementations
|
||||
{
|
||||
|
||||
|
||||
public class TestHostingEnvironment : AspNetCoreHostingEnvironment, Umbraco.Core.Hosting.IHostingEnvironment
|
||||
{
|
||||
public TestHostingEnvironment(IHostingSettings hostingSettings, IWebHostEnvironment webHostEnvironment, IHttpContextAccessor httpContextAccessor)
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Umbraco.Core;
|
||||
@@ -16,6 +13,7 @@ using Umbraco.Tests.Integration.Extensions;
|
||||
using Umbraco.Tests.Integration.Implementations;
|
||||
using Umbraco.Tests.Integration.Testing;
|
||||
using Umbraco.Web.BackOffice.AspNetCore;
|
||||
using Umbraco.Web.Common.Extensions;
|
||||
|
||||
namespace Umbraco.Tests.Integration
|
||||
{
|
||||
@@ -46,11 +44,11 @@ namespace Umbraco.Tests.Integration
|
||||
// LightInject / Umbraco
|
||||
var container = UmbracoServiceProviderFactory.CreateServiceContainer();
|
||||
var serviceProviderFactory = new UmbracoServiceProviderFactory(container);
|
||||
var umbracoContainer = serviceProviderFactory.GetContainer();
|
||||
var umbracoContainer = serviceProviderFactory.GetContainer();
|
||||
|
||||
// Special case since we are not using the Generic Host, we need to manually add an AspNetCore service to the container
|
||||
umbracoContainer.Register(x => Mock.Of<IHostApplicationLifetime>());
|
||||
|
||||
|
||||
var testHelper = new TestHelper();
|
||||
|
||||
// Create the core runtime
|
||||
@@ -64,7 +62,7 @@ namespace Umbraco.Tests.Integration
|
||||
|
||||
Assert.IsTrue(coreRuntime.MainDom.IsMainDom);
|
||||
Assert.IsNull(coreRuntime.State.BootFailedException);
|
||||
Assert.AreEqual(RuntimeLevel.Install, coreRuntime.State.Level);
|
||||
Assert.AreEqual(RuntimeLevel.Install, coreRuntime.State.Level);
|
||||
Assert.IsTrue(MyComposer.IsComposed);
|
||||
Assert.IsFalse(MyComponent.IsInit);
|
||||
Assert.IsFalse(MyComponent.IsTerminated);
|
||||
@@ -82,7 +80,7 @@ namespace Umbraco.Tests.Integration
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calling AddUmbracoCore to configure the container
|
||||
/// Calling AddUmbracoCore to configure the container
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task AddUmbracoCore()
|
||||
@@ -99,7 +97,7 @@ namespace Umbraco.Tests.Integration
|
||||
|
||||
// Add it!
|
||||
services.AddUmbracoConfiguration(hostContext.Configuration);
|
||||
services.AddUmbracoCore(webHostEnvironment, umbracoContainer, GetType().Assembly);
|
||||
services.AddUmbracoCore(webHostEnvironment, umbracoContainer, GetType().Assembly, out _);
|
||||
});
|
||||
|
||||
var host = await hostBuilder.StartAsync();
|
||||
@@ -138,7 +136,7 @@ namespace Umbraco.Tests.Integration
|
||||
|
||||
// Add it!
|
||||
services.AddUmbracoConfiguration(hostContext.Configuration);
|
||||
services.AddUmbracoCore(webHostEnvironment, umbracoContainer, GetType().Assembly);
|
||||
services.AddUmbracoCore(webHostEnvironment, umbracoContainer, GetType().Assembly, out _);
|
||||
});
|
||||
|
||||
var host = await hostBuilder.StartAsync();
|
||||
@@ -209,5 +207,5 @@ namespace Umbraco.Tests.Integration
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
@@ -20,8 +19,8 @@ using Umbraco.Core.Strings;
|
||||
using Umbraco.Tests.Common.Builders;
|
||||
using Umbraco.Tests.Integration.Extensions;
|
||||
using Umbraco.Tests.Integration.Implementations;
|
||||
using Umbraco.Tests.Testing;
|
||||
using Umbraco.Web.BackOffice.AspNetCore;
|
||||
using Umbraco.Web.Common.Extensions;
|
||||
|
||||
namespace Umbraco.Tests.Integration.Testing
|
||||
{
|
||||
@@ -119,7 +118,7 @@ namespace Umbraco.Tests.Integration.Testing
|
||||
|
||||
// Add it!
|
||||
services.AddUmbracoConfiguration(hostContext.Configuration);
|
||||
services.AddUmbracoCore(webHostEnvironment, umbracoContainer, GetType().Assembly);
|
||||
services.AddUmbracoCore(webHostEnvironment, umbracoContainer, GetType().Assembly, out _);
|
||||
});
|
||||
|
||||
var host = await hostBuilder.StartAsync();
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<IsPackable>false</IsPackable>
|
||||
<LangVersion>8</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -4,18 +4,17 @@ using Umbraco.Core.Models;
|
||||
using Umbraco.Tests.Common.Builders;
|
||||
using Umbraco.Tests.Common.Builders.Extensions;
|
||||
|
||||
|
||||
namespace Umbraco.Tests.UnitTests.Umbraco.Infrastructure.Models
|
||||
{
|
||||
[TestFixture]
|
||||
public class DataTypeTests
|
||||
{
|
||||
|
||||
private readonly DataTypeBuilder _builder = new DataTypeBuilder();
|
||||
|
||||
[Test]
|
||||
public void Can_Deep_Clone()
|
||||
{
|
||||
var dtd = _builder
|
||||
var dtd = _builder
|
||||
.WithId(3123)
|
||||
.Build();
|
||||
|
||||
|
||||
+22
-26
@@ -3,28 +3,21 @@ using System.Diagnostics;
|
||||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Serialization;
|
||||
using Umbraco.Tests.Common.Builders;
|
||||
using Umbraco.Tests.Common.Builders.Extensions;
|
||||
|
||||
namespace Umbraco.Tests.Models
|
||||
namespace Umbraco.Tests.UnitTests.Umbraco.Infrastructure.Models
|
||||
{
|
||||
[TestFixture]
|
||||
public class MemberGroupTests
|
||||
{
|
||||
private readonly MemberGroupBuilder _builder = new MemberGroupBuilder();
|
||||
|
||||
[Test]
|
||||
public void Can_Deep_Clone()
|
||||
{
|
||||
// Arrange
|
||||
var group = new MemberGroup()
|
||||
{
|
||||
CreateDate = DateTime.Now,
|
||||
CreatorId = 4,
|
||||
Id = 6,
|
||||
Key = Guid.NewGuid(),
|
||||
UpdateDate = DateTime.Now,
|
||||
Name = "asdf"
|
||||
};
|
||||
group.AdditionalData.Add("test1", 123);
|
||||
group.AdditionalData.Add("test2", "hello");
|
||||
var group = BuildMemberGroup();
|
||||
|
||||
// Act
|
||||
var clone = (MemberGroup)group.DeepClone();
|
||||
@@ -44,29 +37,32 @@ namespace Umbraco.Tests.Models
|
||||
//This double verifies by reflection
|
||||
var allProps = clone.GetType().GetProperties();
|
||||
foreach (var propertyInfo in allProps)
|
||||
{
|
||||
Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(group, null));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Serialize_Without_Error()
|
||||
{
|
||||
var group = new MemberGroup()
|
||||
{
|
||||
CreateDate = DateTime.Now,
|
||||
CreatorId = 4,
|
||||
Id = 6,
|
||||
Key = Guid.NewGuid(),
|
||||
UpdateDate = DateTime.Now,
|
||||
Name = "asdf"
|
||||
};
|
||||
group.AdditionalData.Add("test1", 123);
|
||||
group.AdditionalData.Add("test2", "hello");
|
||||
var group = BuildMemberGroup();
|
||||
|
||||
var json = JsonConvert.SerializeObject(group);
|
||||
Debug.Print(json);
|
||||
}
|
||||
|
||||
private MemberGroup BuildMemberGroup()
|
||||
{
|
||||
return _builder
|
||||
.WithId(6)
|
||||
.WithKey(Guid.NewGuid())
|
||||
.WithName("Test Group")
|
||||
.WithCreatorId(4)
|
||||
.WithCreateDate(DateTime.Now)
|
||||
.WithUpdateDate(DateTime.Now)
|
||||
.AddAdditionalData()
|
||||
.WithKeyValue("test1", 123)
|
||||
.WithKeyValue("test2", "hello")
|
||||
.Done()
|
||||
.Build();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Tests.Common.Builders;
|
||||
using Umbraco.Tests.Common.Builders.Extensions;
|
||||
|
||||
namespace Umbraco.Tests.UnitTests.Umbraco.Infrastructure.Models
|
||||
{
|
||||
[TestFixture]
|
||||
public class MemberTests
|
||||
{
|
||||
private readonly MemberBuilder _builder = new MemberBuilder();
|
||||
|
||||
[Test]
|
||||
public void Can_Deep_Clone()
|
||||
{
|
||||
// Arrange
|
||||
var member = BuildMember();
|
||||
|
||||
// Act
|
||||
var clone = (Member)member.DeepClone();
|
||||
|
||||
// Assert
|
||||
Assert.AreNotSame(clone, member);
|
||||
Assert.AreEqual(clone, member);
|
||||
Assert.AreEqual(clone.Id, member.Id);
|
||||
Assert.AreEqual(clone.VersionId, member.VersionId);
|
||||
Assert.AreEqual(clone.AdditionalData, member.AdditionalData);
|
||||
Assert.AreEqual(clone.ContentType, member.ContentType);
|
||||
Assert.AreEqual(clone.ContentTypeId, member.ContentTypeId);
|
||||
Assert.AreEqual(clone.CreateDate, member.CreateDate);
|
||||
Assert.AreEqual(clone.CreatorId, member.CreatorId);
|
||||
Assert.AreEqual(clone.Comments, member.Comments);
|
||||
Assert.AreEqual(clone.Key, member.Key);
|
||||
Assert.AreEqual(clone.FailedPasswordAttempts, member.FailedPasswordAttempts);
|
||||
Assert.AreEqual(clone.Level, member.Level);
|
||||
Assert.AreEqual(clone.Path, member.Path);
|
||||
Assert.AreEqual(clone.Groups, member.Groups);
|
||||
Assert.AreEqual(clone.Groups.Count(), member.Groups.Count());
|
||||
Assert.AreEqual(clone.IsApproved, member.IsApproved);
|
||||
Assert.AreEqual(clone.IsLockedOut, member.IsLockedOut);
|
||||
Assert.AreEqual(clone.SortOrder, member.SortOrder);
|
||||
Assert.AreEqual(clone.LastLockoutDate, member.LastLockoutDate);
|
||||
Assert.AreNotSame(clone.LastLoginDate, member.LastLoginDate);
|
||||
Assert.AreEqual(clone.LastPasswordChangeDate, member.LastPasswordChangeDate);
|
||||
Assert.AreEqual(clone.Trashed, member.Trashed);
|
||||
Assert.AreEqual(clone.UpdateDate, member.UpdateDate);
|
||||
Assert.AreEqual(clone.VersionId, member.VersionId);
|
||||
Assert.AreEqual(clone.RawPasswordValue, member.RawPasswordValue);
|
||||
Assert.AreNotSame(clone.Properties, member.Properties);
|
||||
Assert.AreEqual(clone.Properties.Count(), member.Properties.Count());
|
||||
for (var index = 0; index < member.Properties.Count; index++)
|
||||
{
|
||||
Assert.AreNotSame(clone.Properties[index], member.Properties[index]);
|
||||
Assert.AreEqual(clone.Properties[index], member.Properties[index]);
|
||||
}
|
||||
|
||||
// this can be the same, it is immutable
|
||||
Assert.AreSame(clone.ContentType, member.ContentType);
|
||||
|
||||
//This double verifies by reflection
|
||||
var allProps = clone.GetType().GetProperties();
|
||||
foreach (var propertyInfo in allProps)
|
||||
Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(member, null));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Serialize_Without_Error()
|
||||
{
|
||||
var member = BuildMember();
|
||||
|
||||
var json = JsonConvert.SerializeObject(member);
|
||||
Debug.Print(json);
|
||||
}
|
||||
|
||||
private Member BuildMember()
|
||||
{
|
||||
return _builder
|
||||
.AddMemberType()
|
||||
.WithId(99)
|
||||
.WithAlias("memberType")
|
||||
.WithName("Member Type")
|
||||
.WithMembershipPropertyGroup()
|
||||
.AddPropertyGroup()
|
||||
.WithName("Content")
|
||||
.WithSortOrder(1)
|
||||
.AddPropertyType()
|
||||
.WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.TextBox)
|
||||
.WithValueStorageType(ValueStorageType.Nvarchar)
|
||||
.WithAlias("title")
|
||||
.WithName("Title")
|
||||
.WithSortOrder(1)
|
||||
.WithDataTypeId(-88)
|
||||
.Done()
|
||||
.AddPropertyType()
|
||||
.WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.TextBox)
|
||||
.WithValueStorageType(ValueStorageType.Ntext)
|
||||
.WithAlias("bodyText")
|
||||
.WithName("Body text")
|
||||
.WithSortOrder(2)
|
||||
.WithDataTypeId(-87)
|
||||
.Done()
|
||||
.AddPropertyType()
|
||||
.WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.TextBox)
|
||||
.WithValueStorageType(ValueStorageType.Nvarchar)
|
||||
.WithAlias("author")
|
||||
.WithName("Author")
|
||||
.WithDescription("Name of the author")
|
||||
.WithSortOrder(3)
|
||||
.WithDataTypeId(-88)
|
||||
.Done()
|
||||
.Done()
|
||||
.Done()
|
||||
.WithId(10)
|
||||
.WithKey(Guid.NewGuid())
|
||||
.WithName("Fred")
|
||||
.WithUserName("fred")
|
||||
.WithRawPasswordValue("raw pass")
|
||||
.WithEmail("email@email.com")
|
||||
.WithCreatorId(22)
|
||||
.WithCreateDate(DateTime.Now)
|
||||
.WithUpdateDate(DateTime.Now)
|
||||
.WithFailedPasswordAttempts(22)
|
||||
.WithLevel(3)
|
||||
.WithPath("-1, 4, 10")
|
||||
.WithIsApproved(true)
|
||||
.WithIsLockedOut(true)
|
||||
.WithSortOrder(5)
|
||||
.WithTrashed(false)
|
||||
.AddMemberGroups()
|
||||
.WithValue("Group 1")
|
||||
.WithValue("Group 2")
|
||||
.Done()
|
||||
.AddAdditionalData()
|
||||
.WithKeyValue("test1", 123)
|
||||
.WithKeyValue("test2", "hello")
|
||||
.Done()
|
||||
.WithPropertyIdsIncrementingFrom(200)
|
||||
.AddPropertyData()
|
||||
.WithKeyValue("title", "Name member")
|
||||
.WithKeyValue("bodyText", "This is a subpage")
|
||||
.WithKeyValue("author", "John Doe")
|
||||
.Done()
|
||||
.Build();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Tests.Common.Builders;
|
||||
using Umbraco.Tests.Common.Builders.Extensions;
|
||||
|
||||
namespace Umbraco.Tests.UnitTests.Umbraco.Tests.Common.Builders
|
||||
{
|
||||
[TestFixture]
|
||||
public class DataTypeBuilderTests
|
||||
{
|
||||
[Test]
|
||||
public void Is_Built_Correctly()
|
||||
{
|
||||
// Arrange
|
||||
const int testId = 3123;
|
||||
|
||||
var builder = new DataTypeBuilder();
|
||||
|
||||
// Act
|
||||
var dtd = builder
|
||||
.WithId(testId)
|
||||
.Build();
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(testId, dtd.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Tests.Common.Builders;
|
||||
using Umbraco.Tests.Common.Builders.Extensions;
|
||||
|
||||
namespace Umbraco.Tests.UnitTests.Umbraco.Tests.Common.Builders
|
||||
{
|
||||
[TestFixture]
|
||||
public class MemberBuilderTests
|
||||
{
|
||||
private class PropertyTypeDetail
|
||||
{
|
||||
public string Alias { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Description { get; set; } = string.Empty;
|
||||
|
||||
public int SortOrder { get; set; }
|
||||
|
||||
public int DataTypeId { get; set; }
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Is_Built_Correctly()
|
||||
{
|
||||
// Arrange
|
||||
const int testMemberTypeId = 99;
|
||||
const string testMemberTypeAlias = "memberType";
|
||||
const string testMemberTypeName = "Member Type";
|
||||
const string testMemberTypePropertyGroupName = "Content";
|
||||
const int testId = 10;
|
||||
const string testName = "Fred";
|
||||
const string testUsername = "fred";
|
||||
const string testRawPasswordValue = "raw pass";
|
||||
const string testEmail = "email@email.com";
|
||||
const int testCreatorId = 22;
|
||||
const int testLevel = 3;
|
||||
const string testPath = "-1, 4, 10";
|
||||
const bool testIsApproved = true;
|
||||
const bool testIsLockedOut = true;
|
||||
const int testSortOrder = 5;
|
||||
const bool testTrashed = false;
|
||||
var testKey = Guid.NewGuid();
|
||||
var testCreateDate = DateTime.Now.AddHours(-1);
|
||||
var testUpdateDate = DateTime.Now;
|
||||
var testLastLockoutDate = DateTime.Now.AddHours(-2);
|
||||
var testLastLoginDate = DateTime.Now.AddHours(-3);
|
||||
var testLastPasswordChangeDate = DateTime.Now.AddHours(-4);
|
||||
var testPropertyType1 = new PropertyTypeDetail { Alias = "title", Name = "Title", SortOrder = 1, DataTypeId = -88 };
|
||||
var testPropertyType2 = new PropertyTypeDetail { Alias = "bodyText", Name = "Body Text", SortOrder = 2, DataTypeId = -87 };
|
||||
var testPropertyType3 = new PropertyTypeDetail { Alias = "author", Name = "Author", Description = "Writer of the article", SortOrder = 1, DataTypeId = -88 };
|
||||
var testGroups = new string[] { "group1", "group2" };
|
||||
var testPropertyData1 = new KeyValuePair<string, object>("title", "Name member");
|
||||
var testPropertyData2 = new KeyValuePair<string, object>("bodyText", "This is a subpage");
|
||||
var testPropertyData3 = new KeyValuePair<string, object>("author", "John Doe");
|
||||
var testAdditionalData1 = new KeyValuePair<string, object>("test1", 123);
|
||||
var testAdditionalData2 = new KeyValuePair<string, object>("test2", "hello");
|
||||
|
||||
var builder = new MemberBuilder();
|
||||
|
||||
// Act
|
||||
var member = builder
|
||||
.AddMemberType()
|
||||
.WithId(testMemberTypeId)
|
||||
.WithAlias(testMemberTypeAlias)
|
||||
.WithName(testMemberTypeName)
|
||||
.WithMembershipPropertyGroup()
|
||||
.AddPropertyGroup()
|
||||
.WithName(testMemberTypePropertyGroupName)
|
||||
.WithSortOrder(1)
|
||||
.AddPropertyType()
|
||||
.WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.TextBox)
|
||||
.WithValueStorageType(ValueStorageType.Nvarchar)
|
||||
.WithAlias(testPropertyType1.Alias)
|
||||
.WithName(testPropertyType1.Name)
|
||||
.WithSortOrder(testPropertyType1.SortOrder)
|
||||
.WithDataTypeId(testPropertyType1.DataTypeId)
|
||||
.Done()
|
||||
.AddPropertyType()
|
||||
.WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.TextBox)
|
||||
.WithValueStorageType(ValueStorageType.Ntext)
|
||||
.WithAlias(testPropertyType2.Alias)
|
||||
.WithName(testPropertyType2.Name)
|
||||
.WithSortOrder(testPropertyType2.SortOrder)
|
||||
.WithDataTypeId(testPropertyType2.DataTypeId)
|
||||
.Done()
|
||||
.AddPropertyType()
|
||||
.WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.TextBox)
|
||||
.WithValueStorageType(ValueStorageType.Nvarchar)
|
||||
.WithAlias(testPropertyType3.Alias)
|
||||
.WithName(testPropertyType3.Name)
|
||||
.WithDescription(testPropertyType3.Description)
|
||||
.WithSortOrder(testPropertyType3.SortOrder)
|
||||
.WithDataTypeId(testPropertyType3.DataTypeId)
|
||||
.Done()
|
||||
.Done()
|
||||
.Done()
|
||||
.WithId(testId)
|
||||
.WithKey(testKey)
|
||||
.WithName(testName)
|
||||
.WithUserName(testUsername)
|
||||
.WithRawPasswordValue(testRawPasswordValue)
|
||||
.WithEmail(testEmail)
|
||||
.WithCreatorId(testCreatorId)
|
||||
.WithCreateDate(testCreateDate)
|
||||
.WithUpdateDate(testUpdateDate)
|
||||
.WithFailedPasswordAttempts(22)
|
||||
.WithLevel(testLevel)
|
||||
.WithPath(testPath)
|
||||
.WithIsApproved(testIsApproved)
|
||||
.WithIsLockedOut(testIsLockedOut)
|
||||
.WithLastLockoutDate(testLastLockoutDate)
|
||||
.WithLastLoginDate(testLastLoginDate)
|
||||
.WithLastPasswordChangeDate(testLastPasswordChangeDate)
|
||||
.WithSortOrder(testSortOrder)
|
||||
.WithTrashed(testTrashed)
|
||||
.AddMemberGroups()
|
||||
.WithValue(testGroups[0])
|
||||
.WithValue(testGroups[1])
|
||||
.Done()
|
||||
.AddAdditionalData()
|
||||
.WithKeyValue(testAdditionalData1.Key, testAdditionalData1.Value)
|
||||
.WithKeyValue(testAdditionalData2.Key, testAdditionalData2.Value)
|
||||
.Done()
|
||||
.WithPropertyIdsIncrementingFrom(200)
|
||||
.AddPropertyData()
|
||||
.WithKeyValue(testPropertyData1.Key, testPropertyData1.Value)
|
||||
.WithKeyValue(testPropertyData2.Key, testPropertyData2.Value)
|
||||
.WithKeyValue(testPropertyData3.Key, testPropertyData3.Value)
|
||||
.Done()
|
||||
.Build();
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(testMemberTypeId, member.ContentTypeId);
|
||||
Assert.AreEqual(testMemberTypeAlias, member.ContentType.Alias);
|
||||
Assert.AreEqual(testMemberTypeName, member.ContentType.Name);
|
||||
Assert.AreEqual(testId, member.Id);
|
||||
Assert.AreEqual(testKey, member.Key);
|
||||
Assert.AreEqual(testName, member.Name);
|
||||
Assert.AreEqual(testCreateDate, member.CreateDate);
|
||||
Assert.AreEqual(testUpdateDate, member.UpdateDate);
|
||||
Assert.AreEqual(testCreatorId, member.CreatorId);
|
||||
Assert.AreEqual(testGroups, member.Groups.ToArray());
|
||||
Assert.AreEqual(10, member.Properties.Count); // 7 from membership properties group, 3 custom
|
||||
Assert.AreEqual(testPropertyData1.Value, member.GetValue<string>(testPropertyData1.Key));
|
||||
Assert.AreEqual(testPropertyData2.Value, member.GetValue<string>(testPropertyData2.Key));
|
||||
Assert.AreEqual(testPropertyData3.Value, member.GetValue<string>(testPropertyData3.Key));
|
||||
Assert.AreEqual(2, member.AdditionalData.Count);
|
||||
Assert.AreEqual(testAdditionalData1.Value, member.AdditionalData[testAdditionalData1.Key]);
|
||||
Assert.AreEqual(testAdditionalData2.Value, member.AdditionalData[testAdditionalData2.Key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Tests.Common.Builders;
|
||||
using Umbraco.Tests.Common.Builders.Extensions;
|
||||
|
||||
namespace Umbraco.Tests.UnitTests.Umbraco.Tests.Common.Builders
|
||||
{
|
||||
[TestFixture]
|
||||
public class MemberGroupBuilderTests
|
||||
{
|
||||
[Test]
|
||||
public void Is_Built_Correctly()
|
||||
{
|
||||
// Arrange
|
||||
const int testId = 6;
|
||||
const string testName = "Test Group";
|
||||
const int testCreatorId = 4;
|
||||
var testKey = Guid.NewGuid();
|
||||
var testCreateDate = DateTime.Now.AddHours(-1);
|
||||
var testUpdateDate = DateTime.Now;
|
||||
var testAdditionalData1 = new KeyValuePair<string, object>("test1", 123);
|
||||
var testAdditionalData2 = new KeyValuePair<string, object>("test2", "hello");
|
||||
|
||||
var builder = new MemberGroupBuilder();
|
||||
|
||||
// Act
|
||||
var group = builder
|
||||
.WithId(testId)
|
||||
.WithKey(testKey)
|
||||
.WithName(testName)
|
||||
.WithCreatorId(testCreatorId)
|
||||
.WithCreateDate(testCreateDate)
|
||||
.WithUpdateDate(testUpdateDate)
|
||||
.AddAdditionalData()
|
||||
.WithKeyValue(testAdditionalData1.Key, testAdditionalData1.Value)
|
||||
.WithKeyValue(testAdditionalData2.Key, testAdditionalData2.Value)
|
||||
.Done()
|
||||
.Build();
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(testId, group.Id);
|
||||
Assert.AreEqual(testKey, group.Key);
|
||||
Assert.AreEqual(testName, group.Name);
|
||||
Assert.AreEqual(testCreateDate, group.CreateDate);
|
||||
Assert.AreEqual(testUpdateDate, group.UpdateDate);
|
||||
Assert.AreEqual(testCreatorId, group.CreatorId);
|
||||
Assert.AreEqual(3, group.AdditionalData.Count); // previousName is added as part of the MemberGroup construction, plus the 2 we've added.
|
||||
Assert.AreEqual(testAdditionalData1.Value, group.AdditionalData[testAdditionalData1.Key]);
|
||||
Assert.AreEqual(testAdditionalData2.Value, group.AdditionalData[testAdditionalData2.Key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -96,7 +96,7 @@ namespace Umbraco.Tests.Cache
|
||||
return "";
|
||||
});
|
||||
|
||||
Assert.AreEqual(counter, 1);
|
||||
Assert.AreEqual(1, counter);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -27,17 +27,17 @@ namespace Umbraco.Tests.Configurations.UmbracoSettings
|
||||
[Test]
|
||||
public virtual void Can_Set_Multiple()
|
||||
{
|
||||
Assert.AreEqual(ContentSettings.Error404Collection.Count(), 3);
|
||||
Assert.AreEqual(ContentSettings.Error404Collection.ElementAt(0).Culture, "default");
|
||||
Assert.AreEqual(ContentSettings.Error404Collection.ElementAt(0).ContentId, 1047);
|
||||
Assert.AreEqual(3, ContentSettings.Error404Collection.Count());
|
||||
Assert.AreEqual("default", ContentSettings.Error404Collection.ElementAt(0).Culture);
|
||||
Assert.AreEqual(1047, ContentSettings.Error404Collection.ElementAt(0).ContentId);
|
||||
Assert.IsTrue(ContentSettings.Error404Collection.ElementAt(0).HasContentId);
|
||||
Assert.IsFalse(ContentSettings.Error404Collection.ElementAt(0).HasContentKey);
|
||||
Assert.AreEqual(ContentSettings.Error404Collection.ElementAt(1).Culture, "en-US");
|
||||
Assert.AreEqual(ContentSettings.Error404Collection.ElementAt(1).ContentXPath, "$site/error [@name = 'error']");
|
||||
Assert.AreEqual("en-US", ContentSettings.Error404Collection.ElementAt(1).Culture);
|
||||
Assert.AreEqual("$site/error [@name = 'error']", ContentSettings.Error404Collection.ElementAt(1).ContentXPath);
|
||||
Assert.IsFalse(ContentSettings.Error404Collection.ElementAt(1).HasContentId);
|
||||
Assert.IsFalse(ContentSettings.Error404Collection.ElementAt(1).HasContentKey);
|
||||
Assert.AreEqual(ContentSettings.Error404Collection.ElementAt(2).Culture, "en-UK");
|
||||
Assert.AreEqual(ContentSettings.Error404Collection.ElementAt(2).ContentKey, new Guid("8560867F-B88F-4C74-A9A4-679D8E5B3BFC"));
|
||||
Assert.AreEqual("en-UK", ContentSettings.Error404Collection.ElementAt(2).Culture);
|
||||
Assert.AreEqual(new Guid("8560867F-B88F-4C74-A9A4-679D8E5B3BFC"), ContentSettings.Error404Collection.ElementAt(2).ContentKey);
|
||||
Assert.IsTrue(ContentSettings.Error404Collection.ElementAt(2).HasContentKey);
|
||||
Assert.IsFalse(ContentSettings.Error404Collection.ElementAt(2).HasContentId);
|
||||
}
|
||||
@@ -51,17 +51,17 @@ namespace Umbraco.Tests.Configurations.UmbracoSettings
|
||||
[Test]
|
||||
public virtual void ImageAutoFillProperties()
|
||||
{
|
||||
Assert.AreEqual(ContentSettings.ImageAutoFillProperties.Count(), 2);
|
||||
Assert.AreEqual(ContentSettings.ImageAutoFillProperties.ElementAt(0).Alias, "umbracoFile");
|
||||
Assert.AreEqual(ContentSettings.ImageAutoFillProperties.ElementAt(0).WidthFieldAlias, "umbracoWidth");
|
||||
Assert.AreEqual(ContentSettings.ImageAutoFillProperties.ElementAt(0).HeightFieldAlias, "umbracoHeight");
|
||||
Assert.AreEqual(ContentSettings.ImageAutoFillProperties.ElementAt(0).LengthFieldAlias, "umbracoBytes");
|
||||
Assert.AreEqual(ContentSettings.ImageAutoFillProperties.ElementAt(0).ExtensionFieldAlias, "umbracoExtension");
|
||||
Assert.AreEqual(ContentSettings.ImageAutoFillProperties.ElementAt(1).Alias, "umbracoFile2");
|
||||
Assert.AreEqual(ContentSettings.ImageAutoFillProperties.ElementAt(1).WidthFieldAlias, "umbracoWidth2");
|
||||
Assert.AreEqual(ContentSettings.ImageAutoFillProperties.ElementAt(1).HeightFieldAlias, "umbracoHeight2");
|
||||
Assert.AreEqual(ContentSettings.ImageAutoFillProperties.ElementAt(1).LengthFieldAlias, "umbracoBytes2");
|
||||
Assert.AreEqual(ContentSettings.ImageAutoFillProperties.ElementAt(1).ExtensionFieldAlias, "umbracoExtension2");
|
||||
Assert.AreEqual(2, ContentSettings.ImageAutoFillProperties.Count());
|
||||
Assert.AreEqual("umbracoFile", ContentSettings.ImageAutoFillProperties.ElementAt(0).Alias);
|
||||
Assert.AreEqual("umbracoWidth", ContentSettings.ImageAutoFillProperties.ElementAt(0).WidthFieldAlias);
|
||||
Assert.AreEqual("umbracoHeight", ContentSettings.ImageAutoFillProperties.ElementAt(0).HeightFieldAlias);
|
||||
Assert.AreEqual("umbracoBytes", ContentSettings.ImageAutoFillProperties.ElementAt(0).LengthFieldAlias);
|
||||
Assert.AreEqual("umbracoExtension", ContentSettings.ImageAutoFillProperties.ElementAt(0).ExtensionFieldAlias);
|
||||
Assert.AreEqual("umbracoFile2", ContentSettings.ImageAutoFillProperties.ElementAt(1).Alias);
|
||||
Assert.AreEqual("umbracoWidth2", ContentSettings.ImageAutoFillProperties.ElementAt(1).WidthFieldAlias);
|
||||
Assert.AreEqual("umbracoHeight2", ContentSettings.ImageAutoFillProperties.ElementAt(1).HeightFieldAlias);
|
||||
Assert.AreEqual("umbracoBytes2", ContentSettings.ImageAutoFillProperties.ElementAt(1).LengthFieldAlias);
|
||||
Assert.AreEqual("umbracoExtension2", ContentSettings.ImageAutoFillProperties.ElementAt(1).ExtensionFieldAlias);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -116,7 +116,7 @@ namespace Umbraco.Tests.Configurations.UmbracoSettings
|
||||
Debug.WriteLine("AllowedContainsExtension: {0}", allowedContainsExtension);
|
||||
Debug.WriteLine("DisallowedContainsExtension: {0}", disallowedContainsExtension);
|
||||
|
||||
Assert.AreEqual(ContentSettings.IsFileAllowedForUpload(extension), expected);
|
||||
Assert.AreEqual(expected, ContentSettings.IsFileAllowedForUpload(extension));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Umbraco.Tests.CoreThings
|
||||
|
||||
var xmlNode = cdata.GetXmlNode(xdoc);
|
||||
|
||||
Assert.AreEqual(xmlNode.InnerText, "hello world");
|
||||
Assert.AreEqual("hello world", xmlNode.InnerText);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -27,7 +27,7 @@ namespace Umbraco.Tests.CoreThings
|
||||
|
||||
var xmlNode = cdata.GetXmlNode(xdoc);
|
||||
|
||||
Assert.AreEqual(xmlNode.InnerText, "hello world");
|
||||
Assert.AreEqual("hello world", xmlNode.InnerText);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -41,7 +41,7 @@ namespace Umbraco.Tests.CoreThings
|
||||
|
||||
var xmlNode = cdata.GetXmlNode(xdoc);
|
||||
|
||||
Assert.AreEqual(xmlNode.InnerText, "hello world");
|
||||
Assert.AreEqual("hello world", xmlNode.InnerText);
|
||||
Assert.AreEqual(xml, xdoc.OuterXml);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,10 +16,10 @@ using Umbraco.Core.PropertyEditors.ValueConverters;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Tests.Components;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Web.Models;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.PropertyEditors;
|
||||
using System.Text;
|
||||
using Umbraco.Infrastructure.Media;
|
||||
|
||||
namespace Umbraco.Tests.Models
|
||||
{
|
||||
|
||||
@@ -1,134 +0,0 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Tests.TestHelpers.Entities;
|
||||
|
||||
namespace Umbraco.Tests.Models
|
||||
{
|
||||
[TestFixture]
|
||||
public class MemberTests
|
||||
{
|
||||
[Test]
|
||||
public void Can_Deep_Clone()
|
||||
{
|
||||
// Arrange
|
||||
var memberType = MockedContentTypes.CreateSimpleMemberType("memberType", "Member Type");
|
||||
memberType.Id = 99;
|
||||
var member = MockedMember.CreateSimpleMember(memberType, "Name", "email@email.com", "pass", "user", Guid.NewGuid());
|
||||
var i = 200;
|
||||
foreach (var property in member.Properties)
|
||||
{
|
||||
property.Id = ++i;
|
||||
}
|
||||
member.Id = 10;
|
||||
member.CreateDate = DateTime.Now;
|
||||
member.CreatorId = 22;
|
||||
member.Comments = "comments";
|
||||
member.Key = Guid.NewGuid();
|
||||
member.FailedPasswordAttempts = 22;
|
||||
member.Level = 3;
|
||||
member.Path = "-1,4,10";
|
||||
member.Groups = new[] {"group1", "group2"};
|
||||
member.IsApproved = true;
|
||||
member.IsLockedOut = true;
|
||||
member.LastLockoutDate = DateTime.Now;
|
||||
member.LastLoginDate = DateTime.Now;
|
||||
member.LastPasswordChangeDate = DateTime.Now;
|
||||
member.RawPasswordValue = "raw pass";
|
||||
member.SortOrder = 5;
|
||||
member.Trashed = false;
|
||||
member.UpdateDate = DateTime.Now;
|
||||
member.AdditionalData.Add("test1", 123);
|
||||
member.AdditionalData.Add("test2", "hello");
|
||||
|
||||
// Act
|
||||
var clone = (Member)member.DeepClone();
|
||||
|
||||
// Assert
|
||||
Assert.AreNotSame(clone, member);
|
||||
Assert.AreEqual(clone, member);
|
||||
Assert.AreEqual(clone.Id, member.Id);
|
||||
Assert.AreEqual(clone.VersionId, member.VersionId);
|
||||
Assert.AreEqual(clone.AdditionalData, member.AdditionalData);
|
||||
Assert.AreEqual(clone.ContentType, member.ContentType);
|
||||
Assert.AreEqual(clone.ContentTypeId, member.ContentTypeId);
|
||||
Assert.AreEqual(clone.CreateDate, member.CreateDate);
|
||||
Assert.AreEqual(clone.CreatorId, member.CreatorId);
|
||||
Assert.AreEqual(clone.Comments, member.Comments);
|
||||
Assert.AreEqual(clone.Key, member.Key);
|
||||
Assert.AreEqual(clone.FailedPasswordAttempts, member.FailedPasswordAttempts);
|
||||
Assert.AreEqual(clone.Level, member.Level);
|
||||
Assert.AreEqual(clone.Path, member.Path);
|
||||
Assert.AreEqual(clone.Groups, member.Groups);
|
||||
Assert.AreEqual(clone.Groups.Count(), member.Groups.Count());
|
||||
Assert.AreEqual(clone.IsApproved, member.IsApproved);
|
||||
Assert.AreEqual(clone.IsLockedOut, member.IsLockedOut);
|
||||
Assert.AreEqual(clone.SortOrder, member.SortOrder);
|
||||
Assert.AreEqual(clone.LastLockoutDate, member.LastLockoutDate);
|
||||
Assert.AreNotSame(clone.LastLoginDate, member.LastLoginDate);
|
||||
Assert.AreEqual(clone.LastPasswordChangeDate, member.LastPasswordChangeDate);
|
||||
Assert.AreEqual(clone.Trashed, member.Trashed);
|
||||
Assert.AreEqual(clone.UpdateDate, member.UpdateDate);
|
||||
Assert.AreEqual(clone.VersionId, member.VersionId);
|
||||
Assert.AreEqual(clone.RawPasswordValue, member.RawPasswordValue);
|
||||
Assert.AreNotSame(clone.Properties, member.Properties);
|
||||
Assert.AreEqual(clone.Properties.Count(), member.Properties.Count());
|
||||
for (var index = 0; index < member.Properties.Count; index++)
|
||||
{
|
||||
Assert.AreNotSame(clone.Properties[index], member.Properties[index]);
|
||||
Assert.AreEqual(clone.Properties[index], member.Properties[index]);
|
||||
}
|
||||
|
||||
// this can be the same, it is immutable
|
||||
Assert.AreSame(clone.ContentType, member.ContentType);
|
||||
|
||||
//This double verifies by reflection
|
||||
var allProps = clone.GetType().GetProperties();
|
||||
foreach (var propertyInfo in allProps)
|
||||
{
|
||||
Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(member, null));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Serialize_Without_Error()
|
||||
{
|
||||
var memberType = MockedContentTypes.CreateSimpleMemberType("memberType", "Member Type");
|
||||
memberType.Id = 99;
|
||||
var member = MockedMember.CreateSimpleMember(memberType, "Name", "email@email.com", "pass", "user", Guid.NewGuid());
|
||||
var i = 200;
|
||||
foreach (var property in member.Properties)
|
||||
{
|
||||
property.Id = ++i;
|
||||
}
|
||||
member.Id = 10;
|
||||
member.CreateDate = DateTime.Now;
|
||||
member.CreatorId = 22;
|
||||
member.Comments = "comments";
|
||||
member.Key = Guid.NewGuid();
|
||||
member.FailedPasswordAttempts = 22;
|
||||
member.Level = 3;
|
||||
member.Path = "-1,4,10";
|
||||
member.Groups = new[] { "group1", "group2" };
|
||||
member.IsApproved = true;
|
||||
member.IsLockedOut = true;
|
||||
member.LastLockoutDate = DateTime.Now;
|
||||
member.LastLoginDate = DateTime.Now;
|
||||
member.LastPasswordChangeDate = DateTime.Now;
|
||||
member.RawPasswordValue = "raw pass";
|
||||
member.SortOrder = 5;
|
||||
member.Trashed = false;
|
||||
member.UpdateDate = DateTime.Now;
|
||||
member.AdditionalData.Add("test1", 123);
|
||||
member.AdditionalData.Add("test2", "hello");
|
||||
|
||||
var json = JsonConvert.SerializeObject(member);
|
||||
Debug.Print(json);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1693,7 +1693,7 @@ namespace Umbraco.Tests.Persistence
|
||||
{
|
||||
Assert.IsTrue(testReader.Read());
|
||||
|
||||
Assert.AreEqual(testReader.Depth, 0);
|
||||
Assert.AreEqual(0, testReader.Depth);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2067,7 +2067,7 @@ namespace Umbraco.Tests.Persistence
|
||||
{
|
||||
Assert.IsTrue(testReader.Read());
|
||||
|
||||
Assert.AreEqual(testReader.RecordsAffected, -1);
|
||||
Assert.AreEqual(-1, testReader.RecordsAffected);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence.Repositories;
|
||||
using Umbraco.Core.Persistence.Repositories.Implement;
|
||||
using Umbraco.Core.Scoping;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Tests.Testing;
|
||||
|
||||
namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
[TestFixture]
|
||||
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
|
||||
public class KeyValueRepositoryTests : TestWithDatabaseBase
|
||||
{
|
||||
[Test]
|
||||
public void CanSetAndGet()
|
||||
{
|
||||
var provider = TestObjects.GetScopeProvider(Logger);
|
||||
|
||||
// Insert new key/value
|
||||
using (var scope = provider.CreateScope())
|
||||
{
|
||||
var keyValue = new KeyValue
|
||||
{
|
||||
Identifier = "foo",
|
||||
Value = "bar",
|
||||
UpdateDate = DateTime.Now,
|
||||
};
|
||||
var repo = CreateRepository(provider);
|
||||
repo.Save(keyValue);
|
||||
scope.Complete();
|
||||
}
|
||||
|
||||
// Retrieve key/value
|
||||
using (var scope = provider.CreateScope())
|
||||
{
|
||||
var repo = CreateRepository(provider);
|
||||
var keyValue = repo.Get("foo");
|
||||
scope.Complete();
|
||||
|
||||
Assert.AreEqual("bar", keyValue.Value);
|
||||
}
|
||||
|
||||
// Update value
|
||||
using (var scope = provider.CreateScope())
|
||||
{
|
||||
var repo = CreateRepository(provider);
|
||||
var keyValue = repo.Get("foo");
|
||||
keyValue.Value = "buzz";
|
||||
keyValue.UpdateDate = DateTime.Now;
|
||||
repo.Save(keyValue);
|
||||
scope.Complete();
|
||||
}
|
||||
|
||||
// Retrieve key/value again
|
||||
using (var scope = provider.CreateScope())
|
||||
{
|
||||
var repo = CreateRepository(provider);
|
||||
var keyValue = repo.Get("foo");
|
||||
scope.Complete();
|
||||
|
||||
Assert.AreEqual("buzz", keyValue.Value);
|
||||
}
|
||||
}
|
||||
|
||||
private IKeyValueRepository CreateRepository(IScopeProvider provider)
|
||||
{
|
||||
return new KeyValueRepository((IScopeAccessor) provider, Logger);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -303,15 +303,13 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
stylesheet = repository.Get("missing.css");
|
||||
Assert.IsNull(stylesheet);
|
||||
|
||||
// fixed in 7.3 - 7.2.8 used to...
|
||||
Assert.Throws<UnauthorizedAccessException>(() =>
|
||||
{
|
||||
stylesheet = repository.Get("\\test-path-4.css"); // outside the filesystem, does not exist
|
||||
});
|
||||
Assert.Throws<UnauthorizedAccessException>(() =>
|
||||
{
|
||||
stylesheet = repository.Get("../packages.config"); // outside the filesystem, exists
|
||||
});
|
||||
// #7713 changes behaviour to return null when outside the filesystem
|
||||
// to accomodate changing the CSS path and not flooding the backoffice with errors
|
||||
stylesheet = repository.Get("\\test-path-4.css"); // outside the filesystem, does not exist
|
||||
Assert.IsNull(stylesheet);
|
||||
|
||||
stylesheet = repository.Get("../packages.config"); // outside the filesystem, exists
|
||||
Assert.IsNull(stylesheet);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ using Umbraco.Web.PropertyEditors;
|
||||
using System.Text;
|
||||
using Current = Umbraco.Web.Composing.Current;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Media;
|
||||
|
||||
namespace Umbraco.Tests.PropertyEditors
|
||||
{
|
||||
|
||||
@@ -1325,6 +1325,18 @@ namespace Umbraco.Tests.PublishedContent
|
||||
AssertLinkedNode(child3.contentNode, 1, 3, -1, -1, -1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MultipleCacheIteration()
|
||||
{
|
||||
//see https://github.com/umbraco/Umbraco-CMS/issues/7798
|
||||
this.Init(this.GetInvariantKits());
|
||||
var snapshot = this._snapshotService.CreatePublishedSnapshot(previewToken: null);
|
||||
this._snapshotAccessor.PublishedSnapshot = snapshot;
|
||||
|
||||
var items = snapshot.Content.GetByXPath("/root/itype");
|
||||
Assert.AreEqual(items.Count(), items.Count());
|
||||
}
|
||||
|
||||
private void AssertLinkedNode(ContentNode node, int parent, int prevSibling, int nextSibling, int firstChild, int lastChild)
|
||||
{
|
||||
Assert.AreEqual(parent, node.ParentContentId);
|
||||
|
||||
@@ -16,6 +16,7 @@ using Umbraco.Web;
|
||||
using Umbraco.Web.Templates;
|
||||
using Umbraco.Web.Models;
|
||||
using Umbraco.Web.Routing;
|
||||
using Umbraco.Core.Media;
|
||||
|
||||
namespace Umbraco.Tests.PublishedContent
|
||||
{
|
||||
|
||||
@@ -25,6 +25,7 @@ using Umbraco.Web.Templates;
|
||||
using Umbraco.Web.Models;
|
||||
using Umbraco.Web.Routing;
|
||||
using Current = Umbraco.Web.Composing.Current;
|
||||
using Umbraco.Core.Media;
|
||||
|
||||
namespace Umbraco.Tests.PublishedContent
|
||||
{
|
||||
|
||||
@@ -36,6 +36,7 @@ using File = System.IO.File;
|
||||
using Current = Umbraco.Web.Composing.Current;
|
||||
using Umbraco.Tests.Common;
|
||||
using Umbraco.Tests.Common.Composing;
|
||||
using Umbraco.Core.Media;
|
||||
|
||||
namespace Umbraco.Tests.Runtimes
|
||||
{
|
||||
|
||||
@@ -1811,7 +1811,7 @@ namespace Umbraco.Tests.Services
|
||||
ServiceContext.ContentService.Save(content2, Constants.Security.SuperUserId);
|
||||
Assert.IsTrue(ServiceContext.ContentService.SaveAndPublish(content2, userId: 0).Success);
|
||||
|
||||
var editorGroup = ServiceContext.UserService.GetUserGroupByAlias("editor");
|
||||
var editorGroup = ServiceContext.UserService.GetUserGroupByAlias(Constants.Security.EditorGroupAlias);
|
||||
editorGroup.StartContentId = content1.Id;
|
||||
ServiceContext.UserService.Save(editorGroup);
|
||||
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
using System.Threading;
|
||||
using NUnit.Framework;
|
||||
using NUnit.Framework.Internal;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Tests.Testing;
|
||||
|
||||
namespace Umbraco.Tests.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests covering methods in the KeyValueService class.
|
||||
/// This is more of an integration test as it involves multiple layers
|
||||
/// as well as configuration.
|
||||
/// </summary>
|
||||
[TestFixture]
|
||||
[Apartment(ApartmentState.STA)]
|
||||
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
|
||||
public class KeyValueServiceTests : TestWithSomeContentBase
|
||||
{
|
||||
[Test]
|
||||
public void GetValue_ForMissingKey_ReturnsNull()
|
||||
{
|
||||
// Arrange
|
||||
var keyValueService = ServiceContext.KeyValueService;
|
||||
|
||||
// Act
|
||||
var value = keyValueService.GetValue("foo");
|
||||
|
||||
// Assert
|
||||
Assert.IsNull(value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetValue_ForExistingKey_ReturnsValue()
|
||||
{
|
||||
// Arrange
|
||||
var keyValueService = ServiceContext.KeyValueService;
|
||||
keyValueService.SetValue("foo", "bar");
|
||||
|
||||
// Act
|
||||
var value = keyValueService.GetValue("foo");
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual("bar", value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SetValue_ForExistingKey_SavesValue()
|
||||
{
|
||||
// Arrange
|
||||
var keyValueService = ServiceContext.KeyValueService;
|
||||
keyValueService.SetValue("foo", "bar");
|
||||
|
||||
// Act
|
||||
keyValueService.SetValue("foo", "buzz");
|
||||
var value = keyValueService.GetValue("foo");
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual("buzz", value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TrySetValue_ForExistingKeyWithProvidedValue_ReturnsTrueAndSetsValue()
|
||||
{
|
||||
// Arrange
|
||||
var keyValueService = ServiceContext.KeyValueService;
|
||||
keyValueService.SetValue("foo", "bar");
|
||||
|
||||
// Act
|
||||
var result = keyValueService.TrySetValue("foo", "bar", "buzz");
|
||||
var value = keyValueService.GetValue("foo");
|
||||
|
||||
// Assert
|
||||
Assert.IsTrue(result);
|
||||
Assert.AreEqual("buzz", value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TrySetValue_ForExistingKeyWithoutProvidedValue_ReturnsFalseAndDoesNotSetValue()
|
||||
{
|
||||
// Arrange
|
||||
var keyValueService = ServiceContext.KeyValueService;
|
||||
keyValueService.SetValue("foo", "bar");
|
||||
|
||||
// Act
|
||||
var result = keyValueService.TrySetValue("foo", "bang", "buzz");
|
||||
var value = keyValueService.GetValue("foo");
|
||||
|
||||
// Assert
|
||||
Assert.IsFalse(result);
|
||||
Assert.AreEqual("bar", value);
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user