From a331e6db3030cb930950eac2853ab0fce3283878 Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Wed, 7 Oct 2020 11:23:31 +0200 Subject: [PATCH] Removed Mocked entity static helpers from new test projects, so they are only used for legacy tests. Created equivalent methods as static builder methods, that use the builders to construct the model objects. --- .../Builders/BuilderBase.cs | 12 + .../Builders/ContentBuilder.cs | 138 +++-- .../Builders/ContentTypeBaseBuilder.cs | 24 +- .../Builders/ContentTypeBuilder.cs | 118 +++- .../Builders/Extensions/BuilderExtensions.cs | 8 + .../Interfaces/IWithSupportsPublishing.cs | 9 + .../Builders/MediaBuilder.cs | 72 ++- .../Builders/MediaTypeBuilder.cs | 128 +++++ .../Builders/MemberBuilder.cs | 74 ++- .../Builders/MemberTypeBuilder.cs | 35 +- .../Builders/PropertyGroupBuilder.cs | 13 +- .../Builders/PropertyTypeBuilder.cs | 16 +- .../Builders/TemplateBuilder.cs | 14 +- .../Builders/UserBuilder.cs | 24 + .../Builders/UserGroupBuilder.cs | 13 +- .../Extensions/ContentBaseExtensions.cs | 5 - .../Umbraco.Tests.Common.csproj | 1 + .../Mapping/ContentTypeModelMappingTests.cs | 43 +- .../Repositories/EntityRepositoryTest.cs | 13 +- .../RedirectUrlRepositoryTests.cs | 16 +- .../Repositories/TemplateRepositoryTest.cs | 22 +- .../Repositories/UserGroupRepositoryTest.cs | 27 +- .../Repositories/UserRepositoryTest.cs | 22 +- .../Services/ContentServiceEventTests.cs | 65 ++- .../Services/MediaServiceTests.cs | 43 +- .../Services/PublicAccessServiceTests.cs | 65 ++- .../Services/TagServiceTests.cs | 42 +- .../Services/UserServiceTests.cs | 111 ++-- .../Testing/UmbracoIntegrationTest.cs | 4 +- .../Filters/ContentModelValidatorTests.cs | 507 +++++++++--------- .../TestHelpers/Entities/MockedContent.cs | 0 .../Entities}/MockedContentTypes.cs | 0 .../TestHelpers/Entities/MockedMedia.cs | 0 .../TestHelpers/Entities/MockedMember.cs | 0 .../TestHelpers/Entities/MockedUserGroup.cs | 0 src/Umbraco.Tests/Umbraco.Tests.csproj | 5 + 36 files changed, 1109 insertions(+), 580 deletions(-) create mode 100644 src/Umbraco.Tests.Common/Builders/Interfaces/IWithSupportsPublishing.cs rename src/{Umbraco.Tests.Common => Umbraco.Tests}/TestHelpers/Entities/MockedContent.cs (100%) rename src/{Umbraco.Tests.Common/TestHelpers => Umbraco.Tests/TestHelpers/Entities}/MockedContentTypes.cs (100%) rename src/{Umbraco.Tests.Common => Umbraco.Tests}/TestHelpers/Entities/MockedMedia.cs (100%) rename src/{Umbraco.Tests.Common => Umbraco.Tests}/TestHelpers/Entities/MockedMember.cs (100%) rename src/{Umbraco.Tests.Common => Umbraco.Tests}/TestHelpers/Entities/MockedUserGroup.cs (100%) diff --git a/src/Umbraco.Tests.Common/Builders/BuilderBase.cs b/src/Umbraco.Tests.Common/Builders/BuilderBase.cs index d8fc048d1b..bb8255bbc0 100644 --- a/src/Umbraco.Tests.Common/Builders/BuilderBase.cs +++ b/src/Umbraco.Tests.Common/Builders/BuilderBase.cs @@ -1,7 +1,19 @@ +using System; + namespace Umbraco.Tests.Common.Builders { public abstract class BuilderBase { public abstract T Build(); + + protected static string RandomAlias(string alias, bool randomizeAliases) + { + if (randomizeAliases) + { + return string.Concat(alias, Guid.NewGuid().ToString("N")); + } + + return alias; + } } } diff --git a/src/Umbraco.Tests.Common/Builders/ContentBuilder.cs b/src/Umbraco.Tests.Common/Builders/ContentBuilder.cs index c9aaa4e908..a01a8b1748 100644 --- a/src/Umbraco.Tests.Common/Builders/ContentBuilder.cs +++ b/src/Umbraco.Tests.Common/Builders/ContentBuilder.cs @@ -3,6 +3,8 @@ using System.Collections.Generic; using System.Globalization; using Umbraco.Core.Models; using Umbraco.Tests.Common.Builders.Interfaces; +using Umbraco.Tests.Common.Builders.Extensions; +using Umbraco.Tests.Testing; namespace Umbraco.Tests.Common.Builders { @@ -39,6 +41,9 @@ namespace Umbraco.Tests.Common.Builders private CultureInfo _cultureInfo; private IContentType _contentType; private IDictionary _cultureNames = new Dictionary(); + private object _propertyValues; + private string _propertyValuesCulture; + private string _propertyValuesSegment; public ContentTypeBuilder AddContentType() { @@ -48,24 +53,67 @@ namespace Umbraco.Tests.Common.Builders return builder; } + public ContentBuilder WithContentType(IContentType contentType) + { + _contentTypeBuilder = null; + _contentType = contentType; + + return this; + } + + public ContentBuilder WithCultureName(string culture, string name = "") + { + if (string.IsNullOrWhiteSpace(name)) + { + if (_cultureNames.TryGetValue(culture, out _)) + { + _cultureNames.Remove(culture); + } + } + else + { + _cultureNames[culture] = name; + } + + return this; + } + + public ContentBuilder WithPropertyValues(object propertyValues, string culture = null, string segment = null) + { + _propertyValues = propertyValues; + _propertyValuesCulture = culture; + _propertyValuesSegment = segment; + return this; + } + + public GenericDictionaryBuilder AddPropertyData() + { + var builder = new GenericDictionaryBuilder(this); + _propertyDataBuilder = builder; + return builder; + } + public override Content Build() { - var id = _id ?? 1; + var id = _id ?? 0; var key = _key ?? Guid.NewGuid(); var parentId = _parentId ?? -1; var createDate = _createDate ?? DateTime.Now; var updateDate = _updateDate ?? DateTime.Now; var name = _name ?? Guid.NewGuid().ToString(); - var creatorId = _creatorId ?? 1; + var creatorId = _creatorId ?? 0; var level = _level ?? 1; var path = _path ?? $"-1,{id}"; var sortOrder = _sortOrder ?? 0; var trashed = _trashed ?? false; var culture = _cultureInfo?.Name ?? null; + var propertyValues = _propertyValues ?? null; + var propertyValuesCulture = _propertyValuesCulture ?? null; + var propertyValuesSegment = _propertyValuesSegment ?? null; if (_contentTypeBuilder is null && _contentType is null) { - throw new InvalidOperationException("A member cannot be constructed without providing a member type. Use AddContentType() or WithContentType()."); + throw new InvalidOperationException("A content item cannot be constructed without providing a member type. Use AddContentType() or WithContentType()."); } var contentType = _contentType ?? _contentTypeBuilder.Build(); @@ -88,13 +136,19 @@ namespace Umbraco.Tests.Common.Builders content.SetCultureName(cultureName.Value, cultureName.Key); } - - if (_propertyDataBuilder != null) + if (_propertyDataBuilder != null || propertyValues != null) { - var propertyData = _propertyDataBuilder.Build(); - foreach (var kvp in propertyData) + if (_propertyDataBuilder != null) { - content.SetValue(kvp.Key, kvp.Value); + var propertyData = _propertyDataBuilder.Build(); + foreach (var kvp in propertyData) + { + content.SetValue(kvp.Key, kvp.Value); + } + } + else + { + content.PropertyValues(propertyValues, propertyValuesCulture, propertyValuesSegment); } content.ResetDirtyProperties(false); @@ -103,36 +157,58 @@ namespace Umbraco.Tests.Common.Builders return content; } - public ContentBuilder WithContentType(IContentType contentType) + public static Content CreateBasicContent(IContentType contentType) { - _contentTypeBuilder = null; - _contentType = contentType; - - return this; + return new ContentBuilder() + .WithContentType(contentType) + .WithName("Home") + .Build(); } - public ContentBuilder WithCultureName(string culture, string name) + public static Content CreateSimpleContent(IContentType contentType) { - if (string.IsNullOrWhiteSpace(name)) - { - if (_cultureNames.TryGetValue(culture, out _)) - { - _cultureNames.Remove(culture); - } - } - else - { - _cultureNames[culture] = name; - } - - return this; + return new ContentBuilder() + .WithContentType(contentType) + .WithName("Home") + .WithPropertyValues(new + { + title = "Welcome to our Home page", + bodyText = "This is the welcome message on the first page", + author = "John Doe" + }) + .Build(); } - public GenericDictionaryBuilder AddPropertyData() + public static Content CreateSimpleContent(IContentType contentType, string name, int parentId = -1, string culture = null, string segment = null) { - var builder = new GenericDictionaryBuilder(this); - _propertyDataBuilder = builder; - return builder; + return new ContentBuilder() + .WithContentType(contentType) + .WithName(name) + .WithParentId(parentId) + .WithPropertyValues(new + { + title = "Welcome to our Home page", + bodyText = "This is the welcome message on the first page", + author = "John Doe" + }, culture, segment) + .Build(); + } + + public static Content CreateTextpageContent(IContentType contentType, string name, int parentId) + { + return new ContentBuilder() + .WithId(0) + .WithContentType(contentType) + .WithName(name) + .WithParentId(parentId) + .WithPropertyValues(new + { + title = name + " textpage", + bodyText = string.Format("This is a textpage based on the {0} ContentType", contentType.Alias), + keywords = "text,page,meta", + description = "This is the meta description for a textpage" + }) + .Build(); } int? IWithIdBuilder.Id diff --git a/src/Umbraco.Tests.Common/Builders/ContentTypeBaseBuilder.cs b/src/Umbraco.Tests.Common/Builders/ContentTypeBaseBuilder.cs index d9838cbd50..dd664b3553 100644 --- a/src/Umbraco.Tests.Common/Builders/ContentTypeBaseBuilder.cs +++ b/src/Umbraco.Tests.Common/Builders/ContentTypeBaseBuilder.cs @@ -43,7 +43,6 @@ namespace Umbraco.Tests.Common.Builders private string _thumbnail; private bool? _trashed; private bool? _isContainer; - protected ContentVariation? ContentVariation { get; set; } protected IShortStringHelper ShortStringHelper => new DefaultShortStringHelper(new DefaultShortStringHelperConfig()); @@ -51,7 +50,7 @@ namespace Umbraco.Tests.Common.Builders { } - protected int GetId() => _id ?? 1; + protected int GetId() => _id ?? 0; protected Guid GetKey() => _key ?? Guid.NewGuid(); @@ -82,8 +81,6 @@ namespace Umbraco.Tests.Common.Builders protected bool GetTrashed() => _trashed ?? false; protected bool GetIsContainer() => _isContainer ?? false; - protected ContentVariation GetContentVariation() => ContentVariation ?? Core.Models.ContentVariation.Nothing; - protected void BuildPropertyGroups(ContentTypeCompositionBase contentType, IEnumerable propertyGroups) { @@ -93,8 +90,6 @@ namespace Umbraco.Tests.Common.Builders } } - - protected void BuildPropertyTypeIds(ContentTypeCompositionBase contentType, int? propertyTypeIdsIncrementingFrom) { if (propertyTypeIdsIncrementingFrom.HasValue) @@ -107,6 +102,23 @@ namespace Umbraco.Tests.Common.Builders } } + public static void EnsureAllIds(ContentTypeCompositionBase contentType, int seedId) + { + // Ensure everything has IDs (it will have if builder is used to create the object, but still useful to reset + // and ensure there are no clashes). + contentType.Id = seedId; + var itemid = seedId + 1; + foreach (var propertyGroup in contentType.PropertyGroups) + { + propertyGroup.Id = itemid++; + } + + foreach (var propertyType in contentType.PropertyTypes) + { + propertyType.Id = itemid++; + } + } + int? IWithIdBuilder.Id { get => _id; diff --git a/src/Umbraco.Tests.Common/Builders/ContentTypeBuilder.cs b/src/Umbraco.Tests.Common/Builders/ContentTypeBuilder.cs index 7d51d26437..3d741c695c 100644 --- a/src/Umbraco.Tests.Common/Builders/ContentTypeBuilder.cs +++ b/src/Umbraco.Tests.Common/Builders/ContentTypeBuilder.cs @@ -1,13 +1,16 @@ using System.Collections.Generic; using System.Linq; +using Umbraco.Core; using Umbraco.Core.Models; +using Umbraco.Tests.Common.Builders.Extensions; using Umbraco.Tests.Common.Builders.Interfaces; namespace Umbraco.Tests.Common.Builders { public class ContentTypeBuilder : ContentTypeBaseBuilder, - IWithPropertyTypeIdsIncrementingFrom, IBuildPropertyTypes + IWithPropertyTypeIdsIncrementingFrom, + IBuildPropertyTypes { private List> _propertyGroupBuilders = new List>(); private List> _noGroupPropertyTypeBuilders = new List>(); @@ -16,6 +19,7 @@ namespace Umbraco.Tests.Common.Builders private int? _propertyTypeIdsIncrementingFrom; private int? _defaultTemplateId; + protected ContentVariation? _contentVariation; public ContentTypeBuilder() : base(null) { @@ -31,6 +35,12 @@ namespace Umbraco.Tests.Common.Builders return this; } + public ContentTypeBuilder WithContentVariation(ContentVariation contentVariation) + { + _contentVariation = contentVariation; + return this; + } + public PropertyGroupBuilder AddPropertyGroup() { var builder = new PropertyGroupBuilder(this); @@ -78,32 +88,125 @@ namespace Umbraco.Tests.Common.Builders CreatorId = GetCreatorId(), Trashed = GetTrashed(), IsContainer = GetIsContainer(), - Variations = GetContentVariation(), }; + var contentVariation = _contentVariation ?? ContentVariation.Nothing; + contentType.Variations = contentVariation; + contentType.NoGroupPropertyTypes = _noGroupPropertyTypeBuilders.Select(x => x.Build()); BuildPropertyGroups(contentType, _propertyGroupBuilders.Select(x => x.Build())); BuildPropertyTypeIds(contentType, _propertyTypeIdsIncrementingFrom); - contentType.AllowedTemplates = _templateBuilders.Select(x => x.Build()); contentType.AllowedContentTypes = _allowedContentTypeBuilders.Select(x => x.Build()); + contentType.AllowedTemplates = _templateBuilders.Select(x => x.Build()); if (_defaultTemplateId.HasValue) { contentType.SetDefaultTemplate(contentType.AllowedTemplates .SingleOrDefault(x => x.Id == _defaultTemplateId.Value)); } - contentType.ResetDirtyProperties(false); return contentType; } - public ContentTypeBuilder WithContentVariation(ContentVariation contentVariation) + public static ContentType CreateBasicContentType(string alias = "basePage", string name = "Base Page", IContentType parent = null) { - ContentVariation = contentVariation; - return this; + var builder = new ContentTypeBuilder(); + return (ContentType)builder + .WithAlias(alias) + .WithName(name) + .WithParentId(parent?.Id ?? -1) + .Build(); + } + + public static ContentType CreateSimpleContentType(string alias = null, string name = null, IContentType parent = null, bool randomizeAliases = false, string propertyGroupName = "Content", int defaultTemplateId = 1) + { + return (ContentType)new ContentTypeBuilder() + .WithAlias(alias ?? "simple") + .WithName(name ?? "Simple Page") + .WithParentId(parent?.Id ?? -1) + .AddPropertyGroup() + .WithName(propertyGroupName) + .WithSortOrder(1) + .WithSupportsPublishing(true) + .AddPropertyType() + .WithAlias(RandomAlias("title", randomizeAliases)) + .WithName("Title") + .WithSortOrder(1) + .Done() + .AddPropertyType() + .WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.TinyMce) + .WithValueStorageType(ValueStorageType.Ntext) + .WithAlias(RandomAlias("bodyText", randomizeAliases)) + .WithName("Body text") + .WithSortOrder(2) + .WithDataTypeId(-87) + .Done() + .AddPropertyType() + .WithAlias(RandomAlias("author", randomizeAliases)) + .WithName("Author") + .WithSortOrder(3) + .Done() + .Done() + .AddAllowedTemplate() + .WithId(defaultTemplateId) + .WithAlias("textPage") + .WithName("Textpage") + .Done() + .WithDefaultTemplateId(defaultTemplateId) + .Build(); + } + + public static ContentType CreateTextPageContentType(string alias = "textPage", int defaultTemplateId = 1) + { + var builder = new ContentTypeBuilder(); + return (ContentType)builder + .WithAlias(alias) + .WithName("Text Page") + .AddPropertyGroup() + .WithId(1) + .WithName("Content") + .WithSortOrder(1) + .WithSupportsPublishing(true) + .AddPropertyType() + .WithAlias("title") + .WithName("Title") + .WithSortOrder(1) + .Done() + .AddPropertyType() + .WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.TinyMce) + .WithValueStorageType(ValueStorageType.Ntext) + .WithAlias("bodyText") + .WithName("Body text") + .WithSortOrder(2) + .WithDataTypeId(-87) + .Done() + .Done() + .AddPropertyGroup() + .WithId(2) + .WithName("Meta") + .WithSortOrder(2) + .WithSupportsPublishing(true) + .AddPropertyType() + .WithAlias("keywords") + .WithName("Keywords") + .WithSortOrder(1) + .Done() + .AddPropertyType() + .WithAlias("description") + .WithName("Description") + .WithSortOrder(2) + .Done() + .Done() + .AddAllowedTemplate() + .WithId(defaultTemplateId) + .WithAlias("textpage") + .WithName("Textpage") + .Done() + .WithDefaultTemplateId(defaultTemplateId) + .Build(); } int? IWithPropertyTypeIdsIncrementingFrom.PropertyTypeIdsIncrementingFrom @@ -111,6 +214,5 @@ namespace Umbraco.Tests.Common.Builders get => _propertyTypeIdsIncrementingFrom; set => _propertyTypeIdsIncrementingFrom = value; } - } } diff --git a/src/Umbraco.Tests.Common/Builders/Extensions/BuilderExtensions.cs b/src/Umbraco.Tests.Common/Builders/Extensions/BuilderExtensions.cs index b5294d85fd..1cc766f231 100644 --- a/src/Umbraco.Tests.Common/Builders/Extensions/BuilderExtensions.cs +++ b/src/Umbraco.Tests.Common/Builders/Extensions/BuilderExtensions.cs @@ -1,5 +1,6 @@ using System; using System.Globalization; +using Umbraco.Core.Models; using Umbraco.Tests.Common.Builders.Interfaces; namespace Umbraco.Tests.Common.Builders.Extensions @@ -200,5 +201,12 @@ namespace Umbraco.Tests.Common.Builders.Extensions builder.CultureInfo = CultureInfo.GetCultureInfo(name); return builder; } + + public static T WithSupportsPublishing(this T builder, bool supportsPublishing) + where T : IWithSupportsPublishing + { + builder.SupportsPublishing = supportsPublishing; + return builder; + } } } diff --git a/src/Umbraco.Tests.Common/Builders/Interfaces/IWithSupportsPublishing.cs b/src/Umbraco.Tests.Common/Builders/Interfaces/IWithSupportsPublishing.cs new file mode 100644 index 0000000000..03bf74aa06 --- /dev/null +++ b/src/Umbraco.Tests.Common/Builders/Interfaces/IWithSupportsPublishing.cs @@ -0,0 +1,9 @@ +using System; + +namespace Umbraco.Tests.Common.Builders.Interfaces +{ + public interface IWithSupportsPublishing + { + bool? SupportsPublishing { get; set; } + } +} diff --git a/src/Umbraco.Tests.Common/Builders/MediaBuilder.cs b/src/Umbraco.Tests.Common/Builders/MediaBuilder.cs index e65f52f488..ab5b171bd3 100644 --- a/src/Umbraco.Tests.Common/Builders/MediaBuilder.cs +++ b/src/Umbraco.Tests.Common/Builders/MediaBuilder.cs @@ -1,6 +1,8 @@ using System; using Umbraco.Core.Models; using Umbraco.Tests.Common.Builders.Interfaces; +using Umbraco.Tests.Common.Builders.Extensions; +using Umbraco.Core; namespace Umbraco.Tests.Common.Builders { @@ -33,36 +35,53 @@ namespace Umbraco.Tests.Common.Builders private string _path; private int? _sortOrder; private bool? _trashed; + private IMediaType _mediaType; public MediaTypeBuilder AddMediaType() { + _mediaType = null; var builder = new MediaTypeBuilder(this); _mediaTypeBuilder = builder; return builder; } + public MediaBuilder WithMediaType(IMediaType mediaType) + { + _mediaTypeBuilder = null; + _mediaType = mediaType; + + return this; + } + + public GenericDictionaryBuilder AddPropertyData() + { + var builder = new GenericDictionaryBuilder(this); + _propertyDataBuilder = builder; + return builder; + } + public override Media Build() { - var id = _id ?? 1; + var id = _id ?? 0; var key = _key ?? Guid.NewGuid(); var parentId = _parentId ?? -1; var createDate = _createDate ?? DateTime.Now; var updateDate = _updateDate ?? DateTime.Now; var name = _name ?? Guid.NewGuid().ToString(); - var creatorId = _creatorId ?? 1; + var creatorId = _creatorId ?? 0; var level = _level ?? 1; var path = _path ?? $"-1,{id}"; var sortOrder = _sortOrder ?? 0; var trashed = _trashed ?? false; - if (_mediaTypeBuilder == null) + if (_mediaTypeBuilder is null && _mediaType is null) { - throw new InvalidOperationException("A member cannot be constructed without providing a member type. Use AddMediaType()."); + throw new InvalidOperationException("A media item cannot be constructed without providing a member type. Use AddMediaType() or WithMediaType()."); } - var memberType = _mediaTypeBuilder.Build(); + var mediaType = _mediaType ?? _mediaTypeBuilder.Build(); - var member = new Media(name, parentId, memberType) + var media = new Media(name, parentId, mediaType) { Id = id, Key = key, @@ -80,13 +99,48 @@ namespace Umbraco.Tests.Common.Builders var propertyData = _propertyDataBuilder.Build(); foreach (var kvp in propertyData) { - member.SetValue(kvp.Key, kvp.Value); + media.SetValue(kvp.Key, kvp.Value); } - member.ResetDirtyProperties(false); + media.ResetDirtyProperties(false); } - return member; + return media; + } + + public static Media CreateMediaImage(IMediaType mediaType, int parentId) + { + return CreateMediaImage(mediaType, parentId, "/media/test-image.png"); + } + + public static Media CreateMediaImageWithCrop(IMediaType mediaType, int parentId) + { + return CreateMediaImage(mediaType, parentId, "{src: '/media/test-image.png', crops: []}"); + } + + private static Media CreateMediaImage(IMediaType mediaType, int parentId, string fileValue) + { + return new MediaBuilder() + .WithMediaType(mediaType) + .WithName("Test Image") + .WithParentId(parentId) + .AddPropertyData() + .WithKeyValue(Constants.Conventions.Media.File, fileValue) + .WithKeyValue(Constants.Conventions.Media.Width, "200") + .WithKeyValue(Constants.Conventions.Media.Height, "200") + .WithKeyValue(Constants.Conventions.Media.Bytes, "100") + .WithKeyValue(Constants.Conventions.Media.Extension, "png") + .Done() + .Build(); + } + + public static Media CreateMediaFolder(IMediaType mediaType, int parentId) + { + return new MediaBuilder() + .WithMediaType(mediaType) + .WithName("Test Folder") + .WithParentId(parentId) + .Build(); } int? IWithIdBuilder.Id diff --git a/src/Umbraco.Tests.Common/Builders/MediaTypeBuilder.cs b/src/Umbraco.Tests.Common/Builders/MediaTypeBuilder.cs index 7ec3a3be4a..1342fc4db4 100644 --- a/src/Umbraco.Tests.Common/Builders/MediaTypeBuilder.cs +++ b/src/Umbraco.Tests.Common/Builders/MediaTypeBuilder.cs @@ -108,6 +108,134 @@ namespace Umbraco.Tests.Common.Builders return mediaType; } + public static MediaType CreateSimpleMediaType(string alias, string name, IMediaType parent = null, bool randomizeAliases = false, string propertyGroupName = "Content") + { + var builder = new MediaTypeBuilder(); + var mediaType = builder + .WithAlias(alias) + .WithName(name) + .WithParentId(parent?.Id ?? -1) + .AddPropertyGroup() + .WithName(propertyGroupName) + .WithSortOrder(1) + .AddPropertyType() + .WithAlias(RandomAlias("title", randomizeAliases)) + .WithName("Title") + .WithSortOrder(1) + .Done() + .AddPropertyType() + .WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.TinyMce) + .WithValueStorageType(ValueStorageType.Ntext) + .WithAlias(RandomAlias("bodyText", randomizeAliases)) + .WithName("Body text") + .WithSortOrder(2) + .WithDataTypeId(-87) + .Done() + .AddPropertyType() + .WithAlias(RandomAlias("author", randomizeAliases)) + .WithName("Author") + .WithSortOrder(3) + .Done() + .Done() + .Build(); + + // Ensure that nothing is marked as dirty + mediaType.ResetDirtyProperties(false); + + return (MediaType)mediaType; + } + + public static MediaType CreateImageMediaType(string alias = Constants.Conventions.MediaTypes.Image) + { + return CreateImageMediaType(alias ?? "Image", Constants.PropertyEditors.Aliases.UploadField, -90); + } + + public static MediaType CreateImageMediaTypeWithCrop(string alias = Constants.Conventions.MediaTypes.Image) + { + return CreateImageMediaType(alias ?? "Image", Constants.PropertyEditors.Aliases.ImageCropper, 1043); + } + + private static MediaType CreateImageMediaType(string alias, string imageFieldPropertyEditorAlias, int imageFieldDataTypeId) + { + var builder = new MediaTypeBuilder(); + var mediaType = builder + .WithAlias(alias) + .WithName("Image") + .AddPropertyGroup() + .WithName("Media") + .WithSortOrder(1) + .AddPropertyType() + .WithPropertyEditorAlias(imageFieldPropertyEditorAlias) + .WithAlias(Constants.Conventions.Media.File) + .WithName("File") + .WithSortOrder(1) + .WithDataTypeId(imageFieldDataTypeId) + .Done() + .AddPropertyType() + .WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.Label) + .WithAlias(Constants.Conventions.Media.Width) + .WithName("Width") + .WithSortOrder(2) + .WithDataTypeId(Constants.System.DefaultLabelDataTypeId) + .Done() + .AddPropertyType() + .WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.Label) + .WithAlias(Constants.Conventions.Media.Height) + .WithName("Height") + .WithSortOrder(3) + .WithDataTypeId(Constants.System.DefaultLabelDataTypeId) + .Done() + .AddPropertyType() + .WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.Label) + .WithAlias(Constants.Conventions.Media.Bytes) + .WithName("Bytes") + .WithSortOrder(4) + .WithDataTypeId(Constants.System.DefaultLabelDataTypeId) + .Done() + .AddPropertyType() + .WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.Label) + .WithAlias(Constants.Conventions.Media.Extension) + .WithName("File Extension") + .WithSortOrder(5) + .WithDataTypeId(Constants.System.DefaultLabelDataTypeId) + .Done() + .Done() + .Build(); + + // Ensure that nothing is marked as dirty + mediaType.ResetDirtyProperties(false); + + return (MediaType)mediaType; + } + + public static MediaType CreateVideoMediaType() + { + var builder = new MediaTypeBuilder(); + var mediaType = builder + .WithAlias("video") + .WithName("Video") + .AddPropertyGroup() + .WithName("Media") + .WithSortOrder(1) + .AddPropertyType() + .WithAlias("title") + .WithName("Title") + .WithSortOrder(1) + .Done() + .AddPropertyType() + .WithAlias("videoFile") + .WithName("Video file") + .WithSortOrder(1) + .Done() + .Done() + .Build(); + + // Ensure that nothing is marked as dirty + mediaType.ResetDirtyProperties(false); + + return (MediaType)mediaType; + } + int? IWithPropertyTypeIdsIncrementingFrom.PropertyTypeIdsIncrementingFrom { get => _propertyTypeIdsIncrementingFrom; diff --git a/src/Umbraco.Tests.Common/Builders/MemberBuilder.cs b/src/Umbraco.Tests.Common/Builders/MemberBuilder.cs index ff954b741e..2f93802a6a 100644 --- a/src/Umbraco.Tests.Common/Builders/MemberBuilder.cs +++ b/src/Umbraco.Tests.Common/Builders/MemberBuilder.cs @@ -1,6 +1,8 @@ using System; using Umbraco.Core.Models; using Umbraco.Tests.Common.Builders.Interfaces; +using Umbraco.Tests.Common.Builders.Extensions; +using System.Collections.Generic; namespace Umbraco.Tests.Common.Builders { @@ -45,6 +47,7 @@ namespace Umbraco.Tests.Common.Builders private int? _sortOrder; private bool? _trashed; private int? _propertyIdsIncrementingFrom; + private IMemberType _memberType; public MemberBuilder WithPropertyIdsIncrementingFrom(int propertyIdsIncrementingFrom) { @@ -54,11 +57,20 @@ namespace Umbraco.Tests.Common.Builders public MemberTypeBuilder AddMemberType() { + _memberType = null; var builder = new MemberTypeBuilder(this); _memberTypeBuilder = builder; return builder; } + public MemberBuilder WithMemberType(IMemberType memberType) + { + _memberTypeBuilder = null; + _memberType = memberType; + + return this; + } + public GenericCollectionBuilder AddMemberGroups() { var builder = new GenericCollectionBuilder(this); @@ -82,12 +94,12 @@ namespace Umbraco.Tests.Common.Builders public override Member Build() { - var id = _id ?? 1; + var id = _id ?? 0; 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 creatorId = _creatorId ?? 0; var level = _level ?? 1; var path = _path ?? $"-1,{id}"; var sortOrder = _sortOrder ?? 0; @@ -101,13 +113,13 @@ namespace Umbraco.Tests.Common.Builders var lastLockoutDate = _lastLockoutDate ?? DateTime.Now; var lastLoginDate = _lastLoginDate ?? DateTime.Now; var lastPasswordChangeDate = _lastPasswordChangeDate ?? DateTime.Now; - - if (_memberTypeBuilder == null) + + if (_memberTypeBuilder is null && _memberType is null) { - throw new InvalidOperationException("A member cannot be constructed without providing a member type. Use AddMemberType()."); + throw new InvalidOperationException("A membercannot be constructed without providing a member type. Use AddMemberType() or WithMemberType()."); } - var memberType = _memberTypeBuilder.Build(); + var memberType = _memberType ?? _memberTypeBuilder.Build(); var member = new Member(name, email, username, rawPasswordValue, memberType) { @@ -166,6 +178,56 @@ namespace Umbraco.Tests.Common.Builders return member; } + public static Member CreateSimpleMember(IMemberType memberType, string name, string email, string password, string username, Guid? key = null) + { + var builder = new MemberBuilder() + .WithMemberType(memberType) + .WithName(name) + .WithEmail(email) + .WithLogin(username, password); + + if (key.HasValue) + { + builder = builder.WithKey(key.Value); + } + + builder = builder + .AddPropertyData() + .WithKeyValue("title", name + " member") + .WithKeyValue("bodyText", "Member profile") + .WithKeyValue("author", "John Doe") + .Done(); + + return builder.Build(); + } + + public static IEnumerable CreateMultipleSimpleMembers(IMemberType memberType, int amount, Action onCreating = null) + { + var list = new List(); + + for (var i = 0; i < amount; i++) + { + var name = "Member No-" + i; + var member = new MemberBuilder() + .WithMemberType(memberType) + .WithName(name) + .WithEmail("test" + i + "@test.com") + .WithLogin("test" + i, "test" + i) + .AddPropertyData() + .WithKeyValue("title", name + " member" + i) + .WithKeyValue("bodyText", "Member profile" + i) + .WithKeyValue("author", "John Doe" + i) + .Done() + .Build(); + + onCreating?.Invoke(i, member); + + list.Add(member); + } + + return list; + } + int? IWithIdBuilder.Id { get => _id; diff --git a/src/Umbraco.Tests.Common/Builders/MemberTypeBuilder.cs b/src/Umbraco.Tests.Common/Builders/MemberTypeBuilder.cs index 0bc5b2e602..e895bd3401 100644 --- a/src/Umbraco.Tests.Common/Builders/MemberTypeBuilder.cs +++ b/src/Umbraco.Tests.Common/Builders/MemberTypeBuilder.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.Linq; using Umbraco.Core; @@ -134,6 +133,40 @@ namespace Umbraco.Tests.Common.Builders return memberType; } + public static MemberType CreateSimpleMemberType(string alias = null, string name = null) + { + var builder = new MemberTypeBuilder(); + var memberType = builder + .WithAlias("simple") + .WithName("Simple Member") + .AddPropertyGroup() + .WithName("Content") + .WithSortOrder(1) + .AddPropertyType() + .WithAlias("title") + .WithName("Title") + .WithSortOrder(1) + .Done() + .AddPropertyType() + .WithAlias("bodyText") + .WithName("Body text") + .WithSortOrder(2) + .WithDataTypeId(-87) + .Done() + .AddPropertyType() + .WithAlias("author") + .WithName("Author") + .WithSortOrder(3) + .Done() + .Done() + .Build(); + + // Ensure that nothing is marked as dirty + memberType.ResetDirtyProperties(false); + + return (MemberType)memberType; + } + int? IWithPropertyTypeIdsIncrementingFrom.PropertyTypeIdsIncrementingFrom { get => _propertyTypeIdsIncrementingFrom; diff --git a/src/Umbraco.Tests.Common/Builders/PropertyGroupBuilder.cs b/src/Umbraco.Tests.Common/Builders/PropertyGroupBuilder.cs index 5df61dd072..f153283764 100644 --- a/src/Umbraco.Tests.Common/Builders/PropertyGroupBuilder.cs +++ b/src/Umbraco.Tests.Common/Builders/PropertyGroupBuilder.cs @@ -25,7 +25,8 @@ namespace Umbraco.Tests.Common.Builders IWithCreateDateBuilder, IWithUpdateDateBuilder, IWithNameBuilder, - IWithSortOrderBuilder where TParent: IBuildPropertyGroups + IWithSortOrderBuilder, + IWithSupportsPublishing where TParent: IBuildPropertyGroups { private readonly List>> _propertyTypeBuilders = new List>>(); @@ -35,6 +36,7 @@ namespace Umbraco.Tests.Common.Builders private DateTime? _updateDate; private string _name; private int? _sortOrder; + private bool? _supportsPublishing; public PropertyGroupBuilder(TParent parentBuilder) : base(parentBuilder) { @@ -55,8 +57,9 @@ namespace Umbraco.Tests.Common.Builders var updateDate = _updateDate ?? DateTime.Now; var name = _name ?? Guid.NewGuid().ToString(); var sortOrder = _sortOrder ?? 0; + var supportsPublishing = _supportsPublishing ?? false; - var properties = new PropertyTypeCollection(false); + var properties = new PropertyTypeCollection(supportsPublishing); foreach (var propertyType in _propertyTypeBuilders.Select(x => x.Build())) { properties.Add(propertyType); @@ -108,5 +111,11 @@ namespace Umbraco.Tests.Common.Builders get => _sortOrder; set => _sortOrder = value; } + + bool? IWithSupportsPublishing.SupportsPublishing + { + get => _supportsPublishing; + set => _supportsPublishing = value; + } } } diff --git a/src/Umbraco.Tests.Common/Builders/PropertyTypeBuilder.cs b/src/Umbraco.Tests.Common/Builders/PropertyTypeBuilder.cs index ed02cfa02f..10e0f5c496 100644 --- a/src/Umbraco.Tests.Common/Builders/PropertyTypeBuilder.cs +++ b/src/Umbraco.Tests.Common/Builders/PropertyTypeBuilder.cs @@ -27,7 +27,8 @@ namespace Umbraco.Tests.Common.Builders IWithCreateDateBuilder, IWithUpdateDateBuilder, IWithSortOrderBuilder, - IWithDescriptionBuilder where TParent : IBuildPropertyTypes + IWithDescriptionBuilder, + IWithSupportsPublishing where TParent : IBuildPropertyTypes { private int? _id; private Guid? _key; @@ -45,6 +46,7 @@ namespace Umbraco.Tests.Common.Builders private string _mandatoryMessage; private string _validationRegExp; private string _validationRegExpMessage; + private bool? _supportsPublishing; public PropertyTypeBuilder(TParent parentBuilder) : base(parentBuilder) { @@ -106,10 +108,11 @@ namespace Umbraco.Tests.Common.Builders var mandatoryMessage = _mandatoryMessage ?? string.Empty; var validationRegExp = _validationRegExp ?? string.Empty; var validationRegExpMessage = _validationRegExpMessage ?? string.Empty; + var supportsPublishing = _supportsPublishing ?? false; var shortStringHelper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig()); - return new PropertyType(shortStringHelper, propertyEditorAlias, valueStorageType) + var propertyType = new PropertyType(shortStringHelper, propertyEditorAlias, valueStorageType) { Id = id, Key = key, @@ -125,7 +128,10 @@ namespace Umbraco.Tests.Common.Builders MandatoryMessage = mandatoryMessage, ValidationRegExp = validationRegExp, ValidationRegExpMessage = validationRegExpMessage, + SupportsPublishing = supportsPublishing, }; + + return propertyType; } int? IWithIdBuilder.Id @@ -175,5 +181,11 @@ namespace Umbraco.Tests.Common.Builders get => _description; set => _description = value; } + + bool? IWithSupportsPublishing.SupportsPublishing + { + get => _supportsPublishing; + set => _supportsPublishing = value; + } } } diff --git a/src/Umbraco.Tests.Common/Builders/TemplateBuilder.cs b/src/Umbraco.Tests.Common/Builders/TemplateBuilder.cs index 7a2007967e..3a3575b862 100644 --- a/src/Umbraco.Tests.Common/Builders/TemplateBuilder.cs +++ b/src/Umbraco.Tests.Common/Builders/TemplateBuilder.cs @@ -62,11 +62,11 @@ namespace Umbraco.Tests.Common.Builders var content = _content; var isMasterTemplate = _isMasterTemplate ?? false; var masterTemplateAlias = _masterTemplateAlias ?? string.Empty; - var masterTemplateId = _masterTemplateId ?? null; + var masterTemplateId = _masterTemplateId ?? new Lazy(() => -1); var shortStringHelper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig()); - return new Template(shortStringHelper, name, alias) + var template = new Template(shortStringHelper, name, alias) { Id = id, Key = key, @@ -78,6 +78,16 @@ namespace Umbraco.Tests.Common.Builders MasterTemplateAlias = masterTemplateAlias, MasterTemplateId = masterTemplateId, }; + + return template; + } + + public static Template CreateTextPageTemplate() + { + return (Template)new TemplateBuilder() + .WithAlias("textPage") + .WithName("Text page") + .Build(); } int? IWithIdBuilder.Id diff --git a/src/Umbraco.Tests.Common/Builders/UserBuilder.cs b/src/Umbraco.Tests.Common/Builders/UserBuilder.cs index 9658b0453f..e88252cc69 100644 --- a/src/Umbraco.Tests.Common/Builders/UserBuilder.cs +++ b/src/Umbraco.Tests.Common/Builders/UserBuilder.cs @@ -4,6 +4,7 @@ using System.Linq; using Umbraco.Core.Configuration.Models; using Umbraco.Core.Models.Membership; using Umbraco.Tests.Common.Builders.Interfaces; +using Umbraco.Tests.Common.Builders.Extensions; namespace Umbraco.Tests.Common.Builders { @@ -185,6 +186,29 @@ namespace Umbraco.Tests.Common.Builders return result; } + public static IEnumerable CreateMulipleUsers(int amount, Action onCreating = null) + { + var list = new List(); + + for (var i = 0; i < amount; i++) + { + var name = "User No-" + i; + var user = new UserBuilder() + .WithName(name) + .WithEmail("test" + i + "@test.com") + .WithLogin("test" + i, "test" + i) + .Build(); + + onCreating?.Invoke(i, user); + + user.ResetDirtyProperties(false); + + list.Add(user); + } + + return list; + } + int? IWithIdBuilder.Id { get => _id; diff --git a/src/Umbraco.Tests.Common/Builders/UserGroupBuilder.cs b/src/Umbraco.Tests.Common/Builders/UserGroupBuilder.cs index a5a96786ce..229285baae 100644 --- a/src/Umbraco.Tests.Common/Builders/UserGroupBuilder.cs +++ b/src/Umbraco.Tests.Common/Builders/UserGroupBuilder.cs @@ -4,6 +4,7 @@ using Moq; using Umbraco.Core.Models.Membership; using Umbraco.Core.Strings; using Umbraco.Tests.Common.Builders.Interfaces; +using Umbraco.Tests.Common.Builders.Extensions; namespace Umbraco.Tests.Common.Builders { @@ -121,7 +122,17 @@ namespace Umbraco.Tests.Common.Builders return userGroup; } - int? IWithIdBuilder.Id + public static UserGroup CreateUserGroup(string suffix = "", string[] permissions = null, string[] allowedSections = null) + { + return (UserGroup)new UserGroupBuilder() + .WithAlias("testUserGroup" + suffix) + .WithName("TestUserGroup" + suffix) + .WithPermissions(permissions ?? new[] { "A", "B", "C" }) + .WithAllowedSections(allowedSections ?? new[] { "content", "media" }) + .Build(); + } + + int? IWithIdBuilder.Id { get => _id; set => _id = value; diff --git a/src/Umbraco.Tests.Common/Extensions/ContentBaseExtensions.cs b/src/Umbraco.Tests.Common/Extensions/ContentBaseExtensions.cs index d33818a31b..c442efe334 100644 --- a/src/Umbraco.Tests.Common/Extensions/ContentBaseExtensions.cs +++ b/src/Umbraco.Tests.Common/Extensions/ContentBaseExtensions.cs @@ -1,15 +1,10 @@ using System; -using System.Linq; -using Umbraco.Core; -using Umbraco.Core.Composing; using Umbraco.Core.Models; -using Umbraco.Core.Services; namespace Umbraco.Tests.Testing { public static class ContentBaseExtensions { - /// /// Set property values by alias with an anonymous object. /// diff --git a/src/Umbraco.Tests.Common/Umbraco.Tests.Common.csproj b/src/Umbraco.Tests.Common/Umbraco.Tests.Common.csproj index 493dbd7ef0..6c05d57cfd 100644 --- a/src/Umbraco.Tests.Common/Umbraco.Tests.Common.csproj +++ b/src/Umbraco.Tests.Common/Umbraco.Tests.Common.csproj @@ -21,6 +21,7 @@ + diff --git a/src/Umbraco.Tests.Integration/Mapping/ContentTypeModelMappingTests.cs b/src/Umbraco.Tests.Integration/Mapping/ContentTypeModelMappingTests.cs index 0b7a702b44..96e49e79e9 100644 --- a/src/Umbraco.Tests.Integration/Mapping/ContentTypeModelMappingTests.cs +++ b/src/Umbraco.Tests.Integration/Mapping/ContentTypeModelMappingTests.cs @@ -8,8 +8,8 @@ using Umbraco.Core.Models; using Umbraco.Core.PropertyEditors; using Umbraco.Core.Services; using Umbraco.Core.Strings; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.Integration.Testing; -using Umbraco.Tests.TestHelpers.Entities; using Umbraco.Tests.Testing; using Umbraco.Web.Models.ContentEditing; @@ -23,9 +23,8 @@ namespace Umbraco.Tests.Models.Mapping private UmbracoMapper _sut; private IFileService _fileService; - [SetUp] - public void Setup() + public void SetupTest() { _sut = Services.GetRequiredService(); _dataTypeService = Services.GetRequiredService(); @@ -273,12 +272,12 @@ namespace Umbraco.Tests.Models.Mapping public void IMemberType_To_MemberTypeDisplay() { //Arrange - var memberType = MockedContentTypes.CreateSimpleMemberType(); + var memberType = MemberTypeBuilder.CreateSimpleMemberType(); var alias = memberType.PropertyTypes.Last().Alias; memberType.SetIsSensitiveProperty(alias, true); memberType.SetMemberCanEditProperty(alias, true); memberType.SetMemberCanViewProperty(alias, true); - MockedContentTypes.EnsureAllIds(memberType, 8888); + MemberTypeBuilder.EnsureAllIds(memberType, 8888); //Act @@ -332,8 +331,8 @@ namespace Umbraco.Tests.Models.Mapping { //Arrange - var mediaType = MockedContentTypes.CreateImageMediaType(); - MockedContentTypes.EnsureAllIds(mediaType, 8888); + var mediaType = MediaTypeBuilder.CreateImageMediaType(); + MediaTypeBuilder.EnsureAllIds(mediaType, 8888); //Act @@ -387,8 +386,8 @@ namespace Umbraco.Tests.Models.Mapping // // // setup the mocks to return the data we want to test against... - var contentType = MockedContentTypes.CreateTextPageContentType(); - MockedContentTypes.EnsureAllIds(contentType, 8888); + var contentType = ContentTypeBuilder.CreateTextPageContentType(); + ContentTypeBuilder.EnsureAllIds(contentType, 8888); //Act @@ -665,7 +664,7 @@ namespace Umbraco.Tests.Models.Mapping public void IMediaTypeComposition_To_MediaTypeDisplay() { //Arrange - var ctMain = MockedContentTypes.CreateSimpleMediaType("parent", "Parent"); + var ctMain = MediaTypeBuilder.CreateSimpleMediaType("parent", "Parent"); //not assigned to tab ctMain.AddPropertyType(new PropertyType(ShortStringHelper, Constants.PropertyEditors.Aliases.TextBox, ValueStorageType.Ntext) { @@ -676,8 +675,8 @@ namespace Umbraco.Tests.Models.Mapping SortOrder = 1, DataTypeId = -88 }); - MockedContentTypes.EnsureAllIds(ctMain, 8888); - var ctChild1 = MockedContentTypes.CreateSimpleMediaType("child1", "Child 1", ctMain, true); + MediaTypeBuilder.EnsureAllIds(ctMain, 8888); + var ctChild1 = MediaTypeBuilder.CreateSimpleMediaType("child1", "Child 1", ctMain, true); ctChild1.AddPropertyType(new PropertyType(ShortStringHelper, Constants.PropertyEditors.Aliases.TextBox, ValueStorageType.Ntext) { Alias = "someProperty", @@ -687,8 +686,8 @@ namespace Umbraco.Tests.Models.Mapping SortOrder = 1, DataTypeId = -88 }, "Another tab"); - MockedContentTypes.EnsureAllIds(ctChild1, 7777); - var contentType = MockedContentTypes.CreateSimpleMediaType("child2", "Child 2", ctChild1, true, "CustomGroup"); + MediaTypeBuilder.EnsureAllIds(ctChild1, 7777); + var contentType = MediaTypeBuilder.CreateSimpleMediaType("child2", "Child 2", ctChild1, true, "CustomGroup"); //not assigned to tab contentType.AddPropertyType(new PropertyType(ShortStringHelper, Constants.PropertyEditors.Aliases.TextBox, ValueStorageType.Ntext) { @@ -699,7 +698,7 @@ namespace Umbraco.Tests.Models.Mapping SortOrder = 1, DataTypeId = -88 }); - MockedContentTypes.EnsureAllIds(contentType, 6666); + MediaTypeBuilder.EnsureAllIds(contentType, 6666); //Act @@ -743,23 +742,21 @@ namespace Umbraco.Tests.Models.Mapping { Assert.AreEqual(contentType.AllowedContentTypes.ElementAt(i).Id.Value, result.AllowedContentTypes.ElementAt(i)); } - } - [Test] public void IContentTypeComposition_To_ContentTypeDisplay() { //Arrange - var ctMain = MockedContentTypes.CreateSimpleContentType(); + var ctMain = ContentTypeBuilder.CreateSimpleContentType(); //not assigned to tab ctMain.AddPropertyType(new PropertyType(ShortStringHelper, Constants.PropertyEditors.Aliases.TextBox, ValueStorageType.Ntext) { Alias = "umbracoUrlName", Name = "Slug", Description = "", Mandatory = false, SortOrder = 1, DataTypeId = -88 }); - MockedContentTypes.EnsureAllIds(ctMain, 8888); - var ctChild1 = MockedContentTypes.CreateSimpleContentType("child1", "Child 1", ctMain, true); + ContentTypeBuilder.EnsureAllIds(ctMain, 8888); + var ctChild1 = ContentTypeBuilder.CreateSimpleContentType("child1", "Child 1", ctMain, true); ctChild1.AddPropertyType(new PropertyType(ShortStringHelper, Constants.PropertyEditors.Aliases.TextBox, ValueStorageType.Ntext) { Alias = "someProperty", @@ -769,14 +766,14 @@ namespace Umbraco.Tests.Models.Mapping SortOrder = 1, DataTypeId = -88 }, "Another tab"); - MockedContentTypes.EnsureAllIds(ctChild1, 7777); - var contentType = MockedContentTypes.CreateSimpleContentType("child2", "Child 2", ctChild1, true, "CustomGroup"); + ContentTypeBuilder.EnsureAllIds(ctChild1, 7777); + var contentType = ContentTypeBuilder.CreateSimpleContentType("child2", "Child 2", ctChild1, true, "CustomGroup"); //not assigned to tab contentType.AddPropertyType(new PropertyType(ShortStringHelper, Constants.PropertyEditors.Aliases.TextBox, ValueStorageType.Ntext) { Alias = "umbracoUrlAlias", Name = "AltUrl", Description = "", Mandatory = false, SortOrder = 1, DataTypeId = -88 }); - MockedContentTypes.EnsureAllIds(contentType, 6666); + ContentTypeBuilder.EnsureAllIds(contentType, 6666); //Act diff --git a/src/Umbraco.Tests.Integration/Persistence/Repositories/EntityRepositoryTest.cs b/src/Umbraco.Tests.Integration/Persistence/Repositories/EntityRepositoryTest.cs index 678e33d34b..06b675606c 100644 --- a/src/Umbraco.Tests.Integration/Persistence/Repositories/EntityRepositoryTest.cs +++ b/src/Umbraco.Tests.Integration/Persistence/Repositories/EntityRepositoryTest.cs @@ -7,6 +7,7 @@ using Umbraco.Core.Models.Entities; using Umbraco.Core.Persistence.Repositories.Implement; using Umbraco.Core.Scoping; using Umbraco.Core.Services; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.Integration.Testing; using Umbraco.Tests.TestHelpers.Entities; using Umbraco.Tests.Testing; @@ -31,11 +32,11 @@ namespace Umbraco.Tests.Integration.Persistence.Repositories var contentService = GetRequiredService(); var contentTypeService = GetRequiredService(); var createdContent = new List(); - var contentType = MockedContentTypes.CreateBasicContentType("blah"); + var contentType = ContentTypeBuilder.CreateBasicContentType("blah"); contentTypeService.Save(contentType); for (var i = 0; i < 10; i++) { - var c1 = MockedContent.CreateBasicContent(contentType); + var c1 = ContentBuilder.CreateBasicContent(contentType); contentService.Save(c1); createdContent.Add(c1); } @@ -45,11 +46,11 @@ namespace Umbraco.Tests.Integration.Persistence.Repositories var mediaService = GetRequiredService(); var mediaTypeService = GetRequiredService(); var createdMedia = new List(); - var imageType = MockedContentTypes.CreateImageMediaType("myImage"); + var imageType = MediaTypeBuilder.CreateImageMediaType("myImage"); mediaTypeService.Save(imageType); for (var i = 0; i < 10; i++) { - var c1 = MockedMedia.CreateMediaImage(imageType, -1); + var c1 = MediaBuilder.CreateMediaImage(imageType, -1); mediaService.Save(c1); createdMedia.Add(c1); } @@ -58,9 +59,9 @@ namespace Umbraco.Tests.Integration.Persistence.Repositories var memberService = GetRequiredService(); var memberTypeService = GetRequiredService(); - var memberType = MockedContentTypes.CreateSimpleMemberType("simple"); + var memberType = MemberTypeBuilder.CreateSimpleMemberType("simple"); memberTypeService.Save(memberType); - var createdMembers = MockedMember.CreateSimpleMember(memberType, 10).ToList(); + var createdMembers = MemberBuilder.CreateMultipleSimpleMembers(memberType, 10).ToList(); memberService.Save(createdMembers); diff --git a/src/Umbraco.Tests.Integration/Persistence/Repositories/RedirectUrlRepositoryTests.cs b/src/Umbraco.Tests.Integration/Persistence/Repositories/RedirectUrlRepositoryTests.cs index ea3bbfb166..ea1a7ed8db 100644 --- a/src/Umbraco.Tests.Integration/Persistence/Repositories/RedirectUrlRepositoryTests.cs +++ b/src/Umbraco.Tests.Integration/Persistence/Repositories/RedirectUrlRepositoryTests.cs @@ -7,8 +7,8 @@ using Umbraco.Core.Persistence.Repositories; using Umbraco.Core.Persistence.Repositories.Implement; using Umbraco.Core.Scoping; using Umbraco.Core.Services; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.Integration.Testing; -using Umbraco.Tests.TestHelpers.Entities; using Umbraco.Tests.Testing; namespace Umbraco.Tests.Integration.Persistence.Repositories @@ -196,31 +196,33 @@ namespace Umbraco.Tests.Integration.Persistence.Repositories public void CreateTestData() { var fileService = GetRequiredService(); + var template = TemplateBuilder.CreateTextPageTemplate(); + fileService.SaveTemplate(template); // else, FK violation on contentType! + var contentService = GetRequiredService(); var contentTypeService = GetRequiredService(); //Create and Save ContentType "umbTextpage" -> (NodeDto.NodeIdSeed) - var contentType = MockedContentTypes.CreateSimpleContentType("umbTextpage", "Textpage"); + var contentType = ContentTypeBuilder.CreateSimpleContentType("umbTextpage", "Textpage", defaultTemplateId: template.Id); contentType.Key = Guid.NewGuid(); - fileService.SaveTemplate(contentType.DefaultTemplate); // else, FK violation on contentType! contentTypeService.Save(contentType); //Create and Save Content "Homepage" based on "umbTextpage" -> (NodeDto.NodeIdSeed + 1) - _textpage = MockedContent.CreateSimpleContent(contentType); + _textpage = ContentBuilder.CreateSimpleContent(contentType); _textpage.Key = Guid.NewGuid(); contentService.Save(_textpage); //Create and Save Content "Text Page 1" based on "umbTextpage" -> (NodeDto.NodeIdSeed + 2) - _subpage = MockedContent.CreateSimpleContent(contentType, "Text Page 1", _textpage.Id); + _subpage = ContentBuilder.CreateSimpleContent(contentType, "Text Page 1", _textpage.Id); _subpage.Key = Guid.NewGuid(); contentService.Save(_subpage); //Create and Save Content "Text Page 1" based on "umbTextpage" -> (NodeDto.NodeIdSeed + 3) - _otherpage = MockedContent.CreateSimpleContent(contentType, "Text Page 2", _textpage.Id); + _otherpage = ContentBuilder.CreateSimpleContent(contentType, "Text Page 2", _textpage.Id); _otherpage.Key = Guid.NewGuid(); contentService.Save(_otherpage); //Create and Save Content "Text Page Deleted" based on "umbTextpage" -> (NodeDto.NodeIdSeed + 4) - _trashed = MockedContent.CreateSimpleContent(contentType, "Text Page Deleted", -20); + _trashed = ContentBuilder.CreateSimpleContent(contentType, "Text Page Deleted", -20); _trashed.Key = Guid.NewGuid(); ((Content) _trashed).Trashed = true; contentService.Save(_trashed); diff --git a/src/Umbraco.Tests.Integration/Persistence/Repositories/TemplateRepositoryTest.cs b/src/Umbraco.Tests.Integration/Persistence/Repositories/TemplateRepositoryTest.cs index 5f7c160ed4..48db7e3ece 100644 --- a/src/Umbraco.Tests.Integration/Persistence/Repositories/TemplateRepositoryTest.cs +++ b/src/Umbraco.Tests.Integration/Persistence/Repositories/TemplateRepositoryTest.cs @@ -16,6 +16,7 @@ using Umbraco.Core.Persistence.Repositories.Implement; using Umbraco.Core.PropertyEditors; using Umbraco.Core.Scoping; using Umbraco.Core.Services; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.Integration.Implementations; using Umbraco.Tests.Integration.Testing; using Umbraco.Tests.TestHelpers.Entities; @@ -273,27 +274,24 @@ namespace Umbraco.Tests.Integration.Persistence.Repositories var dataValueReferences = new DataValueReferenceFactoryCollection(Enumerable.Empty()); var contentRepo = new DocumentRepository(scopeAccessor, AppCaches.Disabled, LoggerFactory.CreateLogger(), LoggerFactory, contentTypeRepository, templateRepository, tagRepository, languageRepository, relationRepository, relationTypeRepository, propertyEditors, dataValueReferences, dataTypeService); - var contentType = MockedContentTypes.CreateSimpleContentType("umbTextpage2", "Textpage"); - fileService.SaveTemplate(contentType.DefaultTemplate); // else, FK violation on contentType! - contentTypeRepository.Save(contentType); - var textpage = MockedContent.CreateSimpleContent(contentType); - contentRepo.Save(textpage); + var template = TemplateBuilder.CreateTextPageTemplate(); + fileService.SaveTemplate(template); // else, FK violation on contentType! - var template = new Template(ShortStringHelper, "test", "test") - { - Content = @"<%@ Master Language=""C#"" %>" - }; - templateRepository.Save(template); + var contentType = ContentTypeBuilder.CreateSimpleContentType("umbTextpage2", "Textpage", defaultTemplateId: template.Id); + contentTypeRepository.Save(contentType); + + var textpage = ContentBuilder.CreateSimpleContent(contentType); + contentRepo.Save(textpage); textpage.TemplateId = template.Id; contentRepo.Save(textpage); // Act - var templates = templateRepository.Get("test"); + var templates = templateRepository.Get("textPage"); templateRepository.Delete(templates); // Assert - Assert.IsNull(templateRepository.Get("test")); + Assert.IsNull(templateRepository.Get("textPage")); } } diff --git a/src/Umbraco.Tests.Integration/Persistence/Repositories/UserGroupRepositoryTest.cs b/src/Umbraco.Tests.Integration/Persistence/Repositories/UserGroupRepositoryTest.cs index d1e0711d58..387207c653 100644 --- a/src/Umbraco.Tests.Integration/Persistence/Repositories/UserGroupRepositoryTest.cs +++ b/src/Umbraco.Tests.Integration/Persistence/Repositories/UserGroupRepositoryTest.cs @@ -5,6 +5,7 @@ using Umbraco.Core.Models.Membership; using Umbraco.Core.Persistence.Repositories; using Umbraco.Core.Persistence.Repositories.Implement; using Umbraco.Core.Scoping; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.Integration.Testing; using Umbraco.Tests.TestHelpers.Entities; using Umbraco.Tests.Testing; @@ -29,7 +30,7 @@ namespace Umbraco.Tests.Integration.Persistence.Repositories { var repository = CreateRepository(provider); - var userGroup = MockedUserGroup.CreateUserGroup(); + var userGroup = UserGroupBuilder.CreateUserGroup(); // Act repository.Save(userGroup); @@ -49,8 +50,8 @@ namespace Umbraco.Tests.Integration.Persistence.Repositories { var repository = CreateRepository(provider); - var userGroup1 = MockedUserGroup.CreateUserGroup("1"); - var userGroup2 = MockedUserGroup.CreateUserGroup("2"); + var userGroup1 = UserGroupBuilder.CreateUserGroup("1"); + var userGroup2 = UserGroupBuilder.CreateUserGroup("2"); // Act repository.Save(userGroup1); @@ -73,7 +74,7 @@ namespace Umbraco.Tests.Integration.Persistence.Repositories { var repository = CreateRepository(provider); - var userGroup = MockedUserGroup.CreateUserGroup(); + var userGroup = UserGroupBuilder.CreateUserGroup(); repository.Save(userGroup); scope.Complete(); @@ -95,7 +96,7 @@ namespace Umbraco.Tests.Integration.Persistence.Repositories { var repository = CreateRepository(provider); - var userGroup = MockedUserGroup.CreateUserGroup(); + var userGroup = UserGroupBuilder.CreateUserGroup(); repository.Save(userGroup); // Act @@ -121,7 +122,7 @@ namespace Umbraco.Tests.Integration.Persistence.Repositories { var repository = CreateRepository(provider); - var userGroup = MockedUserGroup.CreateUserGroup(); + var userGroup = UserGroupBuilder.CreateUserGroup(); // Act repository.Save(userGroup); @@ -148,7 +149,7 @@ namespace Umbraco.Tests.Integration.Persistence.Repositories { var repository = CreateRepository(provider); - var userGroup = MockedUserGroup.CreateUserGroup(); + var userGroup = UserGroupBuilder.CreateUserGroup(); repository.Save(userGroup); scope.Complete(); @@ -389,9 +390,9 @@ namespace Umbraco.Tests.Integration.Persistence.Repositories { var repository = CreateRepository(provider); - var user1 = MockedUserGroup.CreateUserGroup("1", allowedSections: new[] { "test1" }); - var user2 = MockedUserGroup.CreateUserGroup("2", allowedSections: new[] { "test2" }); - var user3 = MockedUserGroup.CreateUserGroup("3", allowedSections: new[] { "test1" }); + var user1 = UserGroupBuilder.CreateUserGroup("1", allowedSections: new[] { "test1" }); + var user2 = UserGroupBuilder.CreateUserGroup("2", allowedSections: new[] { "test2" }); + var user3 = UserGroupBuilder.CreateUserGroup("3", allowedSections: new[] { "test1" }); repository.Save(user1); repository.Save(user2); repository.Save(user3); @@ -411,9 +412,9 @@ namespace Umbraco.Tests.Integration.Persistence.Repositories private IUserGroup[] CreateAndCommitMultipleUserGroups(IUserGroupRepository repository) { - var userGroup1 = MockedUserGroup.CreateUserGroup("1"); - var userGroup2 = MockedUserGroup.CreateUserGroup("2"); - var userGroup3 = MockedUserGroup.CreateUserGroup("3"); + var userGroup1 = UserGroupBuilder.CreateUserGroup("1"); + var userGroup2 = UserGroupBuilder.CreateUserGroup("2"); + var userGroup3 = UserGroupBuilder.CreateUserGroup("3"); repository.Save(userGroup1); repository.Save(userGroup2); repository.Save(userGroup3); diff --git a/src/Umbraco.Tests.Integration/Persistence/Repositories/UserRepositoryTest.cs b/src/Umbraco.Tests.Integration/Persistence/Repositories/UserRepositoryTest.cs index 1485425026..0df619544d 100644 --- a/src/Umbraco.Tests.Integration/Persistence/Repositories/UserRepositoryTest.cs +++ b/src/Umbraco.Tests.Integration/Persistence/Repositories/UserRepositoryTest.cs @@ -46,7 +46,7 @@ namespace Umbraco.Tests.Persistence.Repositories { var repository = CreateRepository(provider); - var user = UserBuilder.Build(); + var user = UserBuilderInstance.Build(); // Act repository.Save(user); @@ -66,8 +66,8 @@ namespace Umbraco.Tests.Persistence.Repositories { var repository = CreateRepository(provider); - var user1 = UserBuilder.WithSuffix("1").Build(); - var use2 = UserBuilder.WithSuffix("2").Build(); + var user1 = UserBuilderInstance.WithSuffix("1").Build(); + var use2 = UserBuilderInstance.WithSuffix("2").Build(); // Act repository.Save(user1); @@ -90,7 +90,7 @@ namespace Umbraco.Tests.Persistence.Repositories { var repository = CreateRepository(provider); - var user = UserBuilder.WithoutIdentity().Build(); + var user = UserBuilderInstance.WithoutIdentity().Build(); repository.Save(user); @@ -112,7 +112,7 @@ namespace Umbraco.Tests.Persistence.Repositories { var repository = CreateRepository(provider); - var user = UserBuilder.Build(); + var user = UserBuilderInstance.Build(); // Act repository.Save(user); @@ -368,22 +368,22 @@ namespace Umbraco.Tests.Persistence.Repositories private User CreateAndCommitUserWithGroup(IUserRepository repository, IUserGroupRepository userGroupRepository) { - var user = UserBuilder.WithoutIdentity().Build(); + var user = UserBuilderInstance.WithoutIdentity().Build(); repository.Save(user); - var group = UserGroupBuilder.Build(); + var group = UserGroupBuilderInstance.Build(); userGroupRepository.AddOrUpdateGroupWithUsers(@group, new[] { user.Id }); - user.AddGroup(UserGroupBuilder.BuildReadOnly(group)); + user.AddGroup(UserGroupBuilderInstance.BuildReadOnly(group)); return user; } private IUser[] CreateAndCommitMultipleUsers(IUserRepository repository) { - var user1 = UserBuilder.WithoutIdentity().WithSuffix("1").Build(); - var user2 = UserBuilder.WithoutIdentity().WithSuffix("2").Build(); - var user3 = UserBuilder.WithoutIdentity().WithSuffix("3").Build(); + var user1 = UserBuilderInstance.WithoutIdentity().WithSuffix("1").Build(); + var user2 = UserBuilderInstance.WithoutIdentity().WithSuffix("2").Build(); + var user3 = UserBuilderInstance.WithoutIdentity().WithSuffix("3").Build(); repository.Save(user1); repository.Save(user2); repository.Save(user3); diff --git a/src/Umbraco.Tests.Integration/Services/ContentServiceEventTests.cs b/src/Umbraco.Tests.Integration/Services/ContentServiceEventTests.cs index 5afc045231..51228b21df 100644 --- a/src/Umbraco.Tests.Integration/Services/ContentServiceEventTests.cs +++ b/src/Umbraco.Tests.Integration/Services/ContentServiceEventTests.cs @@ -7,8 +7,8 @@ using Umbraco.Core.Models; using Umbraco.Core.Persistence.Repositories.Implement; using Umbraco.Core.Services; using Umbraco.Core.Services.Implement; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.Integration.Testing; -using Umbraco.Tests.TestHelpers.Entities; using Umbraco.Tests.Testing; namespace Umbraco.Tests.Integration.Services @@ -26,12 +26,23 @@ namespace Umbraco.Tests.Integration.Services private IFileService FileService => GetRequiredService(); private GlobalSettings _globalSettings; + private IContentType _contentType; [SetUp] public void SetupTest() { ContentRepositoryBase.ThrowOnWarning = true; _globalSettings = new GlobalSettings(); + CreateTestData(); + } + + private void CreateTestData() + { + var template = TemplateBuilder.CreateTextPageTemplate(); + FileService.SaveTemplate(template); // else, FK violation on contentType! + + _contentType = ContentTypeBuilder.CreateTextPageContentType(defaultTemplateId: template.Id); + ContentTypeService.Save(_contentType); } public override void TearDown() @@ -45,14 +56,12 @@ namespace Umbraco.Tests.Integration.Services { LocalizationService.Save(new Language(_globalSettings, "fr-FR")); - var contentType = MockedContentTypes.CreateTextPageContentType(); - FileService.SaveTemplate(contentType.DefaultTemplate); - contentType.Variations = ContentVariation.Culture; - foreach (var propertyType in contentType.PropertyTypes) + _contentType.Variations = ContentVariation.Culture; + foreach (var propertyType in _contentType.PropertyTypes) propertyType.Variations = ContentVariation.Culture; - ContentTypeService.Save(contentType); + ContentTypeService.Save(_contentType); - IContent document = new Content("content", -1, contentType); + IContent document = new Content("content", -1, _contentType); document.SetCultureName("hello", "en-US"); document.SetCultureName("bonjour", "fr-FR"); ContentService.Save(document); @@ -99,11 +108,7 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Saving_Set_Value() { - var contentType = MockedContentTypes.CreateTextPageContentType(); - FileService.SaveTemplate(contentType.DefaultTemplate); - ContentTypeService.Save(contentType); - - IContent document = new Content("content", -1, contentType); + IContent document = new Content("content", -1, _contentType); void OnSaving(IContentService sender, ContentSavingEventArgs e) { @@ -145,14 +150,12 @@ namespace Umbraco.Tests.Integration.Services { LocalizationService.Save(new Language(_globalSettings, "fr-FR")); - var contentType = MockedContentTypes.CreateTextPageContentType(); - FileService.SaveTemplate(contentType.DefaultTemplate); - contentType.Variations = ContentVariation.Culture; - foreach (var propertyType in contentType.PropertyTypes) + _contentType.Variations = ContentVariation.Culture; + foreach (var propertyType in _contentType.PropertyTypes) propertyType.Variations = ContentVariation.Culture; - ContentTypeService.Save(contentType); + ContentTypeService.Save(_contentType); - IContent document = new Content("content", -1, contentType); + IContent document = new Content("content", -1, _contentType); document.SetCultureName("hello", "en-US"); document.SetCultureName("bonjour", "fr-FR"); ContentService.Save(document); @@ -205,11 +208,7 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Publishing_Set_Value() { - var contentType = MockedContentTypes.CreateTextPageContentType(); - FileService.SaveTemplate(contentType.DefaultTemplate); - ContentTypeService.Save(contentType); - - IContent document = new Content("content", -1, contentType); + IContent document = new Content("content", -1, _contentType); void OnSaving(IContentService sender, ContentSavingEventArgs e) { @@ -252,13 +251,11 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Publishing_Set_Mandatory_Value() { - var contentType = MockedContentTypes.CreateTextPageContentType(); - var titleProperty = contentType.PropertyTypes.First(x => x.Alias == "title"); + var titleProperty = _contentType.PropertyTypes.First(x => x.Alias == "title"); titleProperty.Mandatory = true; // make this required! - FileService.SaveTemplate(contentType.DefaultTemplate); - ContentTypeService.Save(contentType); + ContentTypeService.Save(_contentType); - IContent document = new Content("content", -1, contentType); + IContent document = new Content("content", -1, _contentType); var result = ContentService.SaveAndPublish(document); Assert.IsFalse(result.Success); @@ -266,7 +263,7 @@ namespace Umbraco.Tests.Integration.Services // when a service operation fails, the object is dirty and should not be re-used, // re-create it - document = new Content("content", -1, contentType); + document = new Content("content", -1, _contentType); void OnSaving(IContentService sender, ContentSavingEventArgs e) { @@ -297,16 +294,14 @@ namespace Umbraco.Tests.Integration.Services { LocalizationService.Save(new Language(_globalSettings, "fr-FR")); - var contentType = MockedContentTypes.CreateTextPageContentType(); - FileService.SaveTemplate(contentType.DefaultTemplate); - contentType.Variations = ContentVariation.Culture; - foreach (var propertyType in contentType.PropertyTypes) + _contentType.Variations = ContentVariation.Culture; + foreach (var propertyType in _contentType.PropertyTypes) propertyType.Variations = ContentVariation.Culture; - ContentTypeService.Save(contentType); + ContentTypeService.Save(_contentType); var contentService = (ContentService)ContentService; - IContent document = new Content("content", -1, contentType); + IContent document = new Content("content", -1, _contentType); document.SetCultureName("hello", "en-US"); document.SetCultureName("bonjour", "fr-FR"); contentService.SaveAndPublish(document); diff --git a/src/Umbraco.Tests.Integration/Services/MediaServiceTests.cs b/src/Umbraco.Tests.Integration/Services/MediaServiceTests.cs index a43f21d061..a6b67c8b59 100644 --- a/src/Umbraco.Tests.Integration/Services/MediaServiceTests.cs +++ b/src/Umbraco.Tests.Integration/Services/MediaServiceTests.cs @@ -8,6 +8,7 @@ using Umbraco.Core.Events; using Umbraco.Core.Models; using Umbraco.Core.Services; using Umbraco.Core.Services.Implement; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.Integration.Testing; using Umbraco.Tests.TestHelpers.Entities; using Umbraco.Tests.Testing; @@ -51,16 +52,16 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Get_Paged_Children_With_Media_Type_Filter() { - var mediaType1 = MockedContentTypes.CreateImageMediaType("Image2"); + var mediaType1 = MediaTypeBuilder.CreateImageMediaType("Image2"); MediaTypeService.Save(mediaType1); - var mediaType2 = MockedContentTypes.CreateImageMediaType("Image3"); + var mediaType2 = MediaTypeBuilder.CreateImageMediaType("Image3"); MediaTypeService.Save(mediaType2); for (var i = 0; i < 10; i++) { - var m1 = MockedMedia.CreateMediaImage(mediaType1, -1); + var m1 = MediaBuilder.CreateMediaImage(mediaType1, -1); MediaService.Save(m1); - var m2 = MockedMedia.CreateMediaImage(mediaType2, -1); + var m2 = MediaBuilder.CreateMediaImage(mediaType2, -1); MediaService.Save(m2); } @@ -136,7 +137,7 @@ namespace Umbraco.Tests.Integration.Services public void Cannot_Save_Media_With_Empty_Name() { // Arrange - var mediaType = MockedContentTypes.CreateVideoMediaType(); + var mediaType = MediaTypeBuilder.CreateVideoMediaType(); MediaTypeService.Save(mediaType); var media = MediaService.CreateMedia(string.Empty, -1, "video"); @@ -162,10 +163,10 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Can_Get_Media_By_Path() { - var mediaType = MockedContentTypes.CreateImageMediaType("Image2"); + var mediaType = MediaTypeBuilder.CreateImageMediaType("Image2"); MediaTypeService.Save(mediaType); - var media = MockedMedia.CreateMediaImage(mediaType, -1); + var media = MediaBuilder.CreateMediaImage(mediaType, -1); MediaService.Save(media); var mediaPath = "/media/test-image.png"; @@ -178,10 +179,10 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Can_Get_Media_With_Crop_By_Path() { - var mediaType = MockedContentTypes.CreateImageMediaTypeWithCrop("Image2"); + var mediaType = MediaTypeBuilder.CreateImageMediaTypeWithCrop("Image2"); MediaTypeService.Save(mediaType); - var media = MockedMedia.CreateMediaImageWithCrop(mediaType, -1); + var media = MediaBuilder.CreateMediaImageWithCrop(mediaType, -1); MediaService.Save(media); var mediaPath = "/media/test-image.png"; @@ -194,11 +195,11 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Can_Get_Paged_Children() { - var mediaType = MockedContentTypes.CreateImageMediaType("Image2"); + var mediaType = MediaTypeBuilder.CreateImageMediaType("Image2"); MediaTypeService.Save(mediaType); for (var i = 0; i < 10; i++) { - var c1 = MockedMedia.CreateMediaImage(mediaType, -1); + var c1 = MediaBuilder.CreateMediaImage(mediaType, -1); MediaService.Save(c1); } @@ -216,22 +217,22 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Can_Get_Paged_Children_Dont_Get_Descendants() { - var mediaType = MockedContentTypes.CreateImageMediaType("Image2"); + var mediaType = MediaTypeBuilder.CreateImageMediaType("Image2"); MediaTypeService.Save(mediaType); // only add 9 as we also add a folder with children for (var i = 0; i < 9; i++) { - var m1 = MockedMedia.CreateMediaImage(mediaType, -1); + var m1 = MediaBuilder.CreateMediaImage(mediaType, -1); MediaService.Save(m1); } - var mediaTypeForFolder = MockedContentTypes.CreateImageMediaType("Folder2"); + var mediaTypeForFolder = MediaTypeBuilder.CreateImageMediaType("Folder2"); MediaTypeService.Save(mediaTypeForFolder); - var mediaFolder = MockedMedia.CreateMediaFolder(mediaTypeForFolder, -1); + var mediaFolder = MediaBuilder.CreateMediaFolder(mediaTypeForFolder, -1); MediaService.Save(mediaFolder); for (var i = 0; i < 10; i++) { - var m1 = MockedMedia.CreateMediaImage(mediaType, mediaFolder.Id); + var m1 = MediaBuilder.CreateMediaImage(mediaType, mediaFolder.Id); MediaService.Save(m1); } @@ -259,25 +260,25 @@ namespace Umbraco.Tests.Integration.Services { //Create and Save folder-Media -> 1050 var folderMediaType = MediaTypeService.Get(1031); - var folder = MockedMedia.CreateMediaFolder(folderMediaType, -1); + var folder = MediaBuilder.CreateMediaFolder(folderMediaType, -1); MediaService.Save(folder); //Create and Save folder-Media -> 1051 - var folder2 = MockedMedia.CreateMediaFolder(folderMediaType, -1); + var folder2 = MediaBuilder.CreateMediaFolder(folderMediaType, -1); MediaService.Save(folder2); //Create and Save image-Media -> 1052 var imageMediaType = MediaTypeService.Get(1032); - var image = (Media)MockedMedia.CreateMediaImage(imageMediaType, 1050); + var image = MediaBuilder.CreateMediaImage(imageMediaType, 1050); MediaService.Save(image); //Create and Save folder-Media that is trashed -> 1053 - var folderTrashed = (Media)MockedMedia.CreateMediaFolder(folderMediaType, -21); + var folderTrashed = MediaBuilder.CreateMediaFolder(folderMediaType, -21); folderTrashed.Trashed = true; MediaService.Save(folderTrashed); //Create and Save image-Media child of folderTrashed -> 1054 - var imageTrashed = (Media)MockedMedia.CreateMediaImage(imageMediaType, folderTrashed.Id); + var imageTrashed = MediaBuilder.CreateMediaImage(imageMediaType, folderTrashed.Id); imageTrashed.Trashed = true; MediaService.Save(imageTrashed); diff --git a/src/Umbraco.Tests.Integration/Services/PublicAccessServiceTests.cs b/src/Umbraco.Tests.Integration/Services/PublicAccessServiceTests.cs index 5294e8015b..b02bdb9b70 100644 --- a/src/Umbraco.Tests.Integration/Services/PublicAccessServiceTests.cs +++ b/src/Umbraco.Tests.Integration/Services/PublicAccessServiceTests.cs @@ -4,8 +4,8 @@ using System.Threading; using NUnit.Framework; using Umbraco.Core.Models; using Umbraco.Core.Services; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.Integration.Testing; -using Umbraco.Tests.TestHelpers.Entities; using Umbraco.Tests.Testing; namespace Umbraco.Tests.Integration.Services @@ -20,18 +20,28 @@ namespace Umbraco.Tests.Integration.Services private IFileService FileService => GetRequiredService(); private IPublicAccessService PublicAccessService => GetRequiredService(); + private Content _content; + + [SetUp] + public void CreateTestData() + { + var template = TemplateBuilder.CreateTextPageTemplate(); + FileService.SaveTemplate(template); // else, FK violation on contentType! + + var ct = ContentTypeBuilder.CreateSimpleContentType("blah", "Blah", defaultTemplateId: template.Id); + ContentTypeService.Save(ct); + + _content = ContentBuilder.CreateSimpleContent(ct, "Test", -1); + ContentService.Save(_content); + } + [Test] public void Can_Add_New_Entry() { // Arrange - var ct = MockedContentTypes.CreateSimpleContentType("blah", "Blah"); - FileService.SaveTemplate(ct.DefaultTemplate); - ContentTypeService.Save(ct); - var c = MockedContent.CreateSimpleContent(ct, "Test", -1); - ContentService.Save(c); // Act - var entry = new PublicAccessEntry(c, c, c, new[] + var entry = new PublicAccessEntry(_content, _content, _content, new[] { new PublicAccessRule() { @@ -46,21 +56,16 @@ namespace Umbraco.Tests.Integration.Services Assert.AreEqual(OperationResultType.Success, result.Result.Result); Assert.IsTrue(entry.HasIdentity); Assert.AreNotEqual(entry.Key, Guid.Empty); - Assert.AreEqual(c.Id, entry.LoginNodeId); - Assert.AreEqual(c.Id, entry.NoAccessNodeId); - Assert.AreEqual(c.Id, entry.ProtectedNodeId); + Assert.AreEqual(_content.Id, entry.LoginNodeId); + Assert.AreEqual(_content.Id, entry.NoAccessNodeId); + Assert.AreEqual(_content.Id, entry.ProtectedNodeId); } [Test] public void Can_Add_Rule() { // Arrange - var ct = MockedContentTypes.CreateSimpleContentType("blah", "Blah"); - FileService.SaveTemplate(ct.DefaultTemplate); - ContentTypeService.Save(ct); - var c = MockedContent.CreateSimpleContent(ct, "Test", -1); - ContentService.Save(c); - var entry = new PublicAccessEntry(c, c, c, new[] + var entry = new PublicAccessEntry(_content, _content, _content, new[] { new PublicAccessRule() { @@ -71,9 +76,9 @@ namespace Umbraco.Tests.Integration.Services PublicAccessService.Save(entry); // Act - var updated = PublicAccessService.AddRule(c, "TestType2", "AnotherVal"); + var updated = PublicAccessService.AddRule(_content, "TestType2", "AnotherVal"); //re-get - entry = PublicAccessService.GetEntryForContent(c); + entry = PublicAccessService.GetEntryForContent(_content); // Assert Assert.IsTrue(updated.Success); @@ -85,12 +90,7 @@ namespace Umbraco.Tests.Integration.Services public void Can_Add_Multiple_Value_For_Same_Rule_Type() { // Arrange - var ct = MockedContentTypes.CreateSimpleContentType("blah", "Blah"); - FileService.SaveTemplate(ct.DefaultTemplate); - ContentTypeService.Save(ct); - var c = MockedContent.CreateSimpleContent(ct, "Test", -1); - ContentService.Save(c); - var entry = new PublicAccessEntry(c, c, c, new[] + var entry = new PublicAccessEntry(_content, _content, _content, new[] { new PublicAccessRule() { @@ -101,11 +101,11 @@ namespace Umbraco.Tests.Integration.Services PublicAccessService.Save(entry); // Act - var updated1 = PublicAccessService.AddRule(c, "TestType", "AnotherVal1"); - var updated2 = PublicAccessService.AddRule(c, "TestType", "AnotherVal2"); + var updated1 = PublicAccessService.AddRule(_content, "TestType", "AnotherVal1"); + var updated2 = PublicAccessService.AddRule(_content, "TestType", "AnotherVal2"); //re-get - entry = PublicAccessService.GetEntryForContent(c); + entry = PublicAccessService.GetEntryForContent(_content); // Assert Assert.IsTrue(updated1.Success); @@ -119,12 +119,7 @@ namespace Umbraco.Tests.Integration.Services public void Can_Remove_Rule() { // Arrange - var ct = MockedContentTypes.CreateSimpleContentType("blah", "Blah"); - FileService.SaveTemplate(ct.DefaultTemplate); - ContentTypeService.Save(ct); - var c = MockedContent.CreateSimpleContent(ct, "Test", -1); - ContentService.Save(c); - var entry = new PublicAccessEntry(c, c, c, new[] + var entry = new PublicAccessEntry(_content, _content, _content, new[] { new PublicAccessRule() { @@ -140,9 +135,9 @@ namespace Umbraco.Tests.Integration.Services PublicAccessService.Save(entry); // Act - var removed = PublicAccessService.RemoveRule(c, "TestType", "TestValue1"); + var removed = PublicAccessService.RemoveRule(_content, "TestType", "TestValue1"); //re-get - entry = PublicAccessService.GetEntryForContent(c); + entry = PublicAccessService.GetEntryForContent(_content); // Assert Assert.IsTrue(removed.Success); diff --git a/src/Umbraco.Tests.Integration/Services/TagServiceTests.cs b/src/Umbraco.Tests.Integration/Services/TagServiceTests.cs index 585c1319a4..f84dbfb74a 100644 --- a/src/Umbraco.Tests.Integration/Services/TagServiceTests.cs +++ b/src/Umbraco.Tests.Integration/Services/TagServiceTests.cs @@ -6,6 +6,7 @@ using Umbraco.Core; using Umbraco.Core.Models; using Umbraco.Core.PropertyEditors; using Umbraco.Core.Services; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.Integration.Testing; using Umbraco.Tests.TestHelpers.Entities; using Umbraco.Tests.Testing; @@ -24,22 +25,31 @@ namespace Umbraco.Tests.Integration.Services { private IContentService ContentService => GetRequiredService(); private IContentTypeService ContentTypeService => GetRequiredService(); + private IFileService FileService => GetRequiredService(); private ITagService TagService => GetRequiredService(); private IDataTypeService DataTypeService => GetRequiredService(); private PropertyEditorCollection PropertyEditorCollection => GetRequiredService(); + private IContentType _contentType; + + [SetUp] + public void CreateTestData() + { + var template = TemplateBuilder.CreateTextPageTemplate(); + FileService.SaveTemplate(template); // else, FK violation on contentType! + + _contentType = ContentTypeBuilder.CreateSimpleContentType("umbMandatory", "Mandatory Doc Type", defaultTemplateId: template.Id); + _contentType.PropertyGroups.First().PropertyTypes.Add( + new PropertyType(ShortStringHelper, "test", ValueStorageType.Ntext, "tags") + { + DataTypeId = Constants.DataTypes.Tags, + }); + ContentTypeService.Save(_contentType); + } [Test] public void TagApiConsistencyTest() { - var contentType = MockedContentTypes.CreateSimpleContentType("umbMandatory", "Mandatory Doc Type", true); - contentType.PropertyGroups.First().PropertyTypes.Add( - new PropertyType(ShortStringHelper, "test", ValueStorageType.Ntext, "tags") - { - DataTypeId = 1041 - }); - ContentTypeService.Save(contentType); - - IContent content1 = MockedContent.CreateSimpleContent(contentType, "Tagged content 1", -1); + IContent content1 = ContentBuilder.CreateSimpleContent(_contentType, "Tagged content 1", -1); content1.AssignTags(PropertyEditorCollection, DataTypeService, "tags", new[] { "cow", "pig", "goat" }); ContentService.SaveAndPublish(content1); @@ -76,23 +86,15 @@ namespace Umbraco.Tests.Integration.Services [Test] public void TagList_Contains_NodeCount() { - var contentType = MockedContentTypes.CreateSimpleContentType("umbMandatory", "Mandatory Doc Type", true); - contentType.PropertyGroups.First().PropertyTypes.Add( - new PropertyType(ShortStringHelper, Constants.PropertyEditors.Aliases.Tags, ValueStorageType.Ntext, "tags") - { - DataTypeId = Constants.DataTypes.Tags - }); - ContentTypeService.Save(contentType); - - var content1 = MockedContent.CreateSimpleContent(contentType, "Tagged content 1", -1); + var content1 = ContentBuilder.CreateSimpleContent(_contentType, "Tagged content 1", -1); content1.AssignTags(PropertyEditorCollection, DataTypeService, "tags", new[] { "cow", "pig", "goat" }); ContentService.SaveAndPublish(content1); - var content2 = MockedContent.CreateSimpleContent(contentType, "Tagged content 2", -1); + var content2 = ContentBuilder.CreateSimpleContent(_contentType, "Tagged content 2", -1); content2.AssignTags(PropertyEditorCollection, DataTypeService, "tags", new[] { "cow", "pig" }); ContentService.SaveAndPublish(content2); - var content3 = MockedContent.CreateSimpleContent(contentType, "Tagged content 3", -1); + var content3 = ContentBuilder.CreateSimpleContent(_contentType, "Tagged content 3", -1); content3.AssignTags(PropertyEditorCollection, DataTypeService, "tags", new[] { "cow" }); ContentService.SaveAndPublish(content3); diff --git a/src/Umbraco.Tests.Integration/Services/UserServiceTests.cs b/src/Umbraco.Tests.Integration/Services/UserServiceTests.cs index fbe51da837..a75485ad76 100644 --- a/src/Umbraco.Tests.Integration/Services/UserServiceTests.cs +++ b/src/Umbraco.Tests.Integration/Services/UserServiceTests.cs @@ -38,13 +38,13 @@ namespace Umbraco.Tests.Integration.Services { // Arrange var user = CreateTestUser(out _); - var contentType = MockedContentTypes.CreateSimpleContentType(); + var contentType = ContentTypeBuilder.CreateSimpleContentType(); ContentTypeService.Save(contentType); var content = new[] { - MockedContent.CreateSimpleContent(contentType), - MockedContent.CreateSimpleContent(contentType), - MockedContent.CreateSimpleContent(contentType) + ContentBuilder.CreateSimpleContent(contentType), + ContentBuilder.CreateSimpleContent(contentType), + ContentBuilder.CreateSimpleContent(contentType) }; ContentService.Save(content); @@ -64,13 +64,13 @@ namespace Umbraco.Tests.Integration.Services // Arrange var user = CreateTestUser(out var userGroup); - var contentType = MockedContentTypes.CreateSimpleContentType(); + var contentType = ContentTypeBuilder.CreateSimpleContentType(); ContentTypeService.Save(contentType); var content = new[] { - MockedContent.CreateSimpleContent(contentType), - MockedContent.CreateSimpleContent(contentType), - MockedContent.CreateSimpleContent(contentType) + ContentBuilder.CreateSimpleContent(contentType), + ContentBuilder.CreateSimpleContent(contentType), + ContentBuilder.CreateSimpleContent(contentType) }; ContentService.Save(content); ContentService.SetPermission(content[0], ActionBrowse.ActionLetter, new int[] { userGroup.Id }); @@ -96,13 +96,13 @@ namespace Umbraco.Tests.Integration.Services // Arrange var userGroup = CreateTestUserGroup(); - var contentType = MockedContentTypes.CreateSimpleContentType(); + var contentType = ContentTypeBuilder.CreateSimpleContentType(); ContentTypeService.Save(contentType); var content = new[] { - MockedContent.CreateSimpleContent(contentType), - MockedContent.CreateSimpleContent(contentType), - MockedContent.CreateSimpleContent(contentType) + ContentBuilder.CreateSimpleContent(contentType), + ContentBuilder.CreateSimpleContent(contentType), + ContentBuilder.CreateSimpleContent(contentType) }; ContentService.Save(content); ContentService.SetPermission(content.ElementAt(0), ActionBrowse.ActionLetter, new int[] { userGroup.Id }); @@ -128,13 +128,13 @@ namespace Umbraco.Tests.Integration.Services // Arrange var userGroup = CreateTestUserGroup(); - var contentType = MockedContentTypes.CreateSimpleContentType(); + var contentType = ContentTypeBuilder.CreateSimpleContentType(); ContentTypeService.Save(contentType); var content = new[] { - MockedContent.CreateSimpleContent(contentType), - MockedContent.CreateSimpleContent(contentType), - MockedContent.CreateSimpleContent(contentType) + ContentBuilder.CreateSimpleContent(contentType), + ContentBuilder.CreateSimpleContent(contentType), + ContentBuilder.CreateSimpleContent(contentType) }; ContentService.Save(content); ContentService.SetPermission(content[0], ActionBrowse.ActionLetter, new int[] { userGroup.Id }); @@ -170,13 +170,13 @@ namespace Umbraco.Tests.Integration.Services user.AddGroup(userGroup3); UserService.Save(user); - var contentType = MockedContentTypes.CreateSimpleContentType(); + var contentType = ContentTypeBuilder.CreateSimpleContentType(); ContentTypeService.Save(contentType); var content = new[] { - MockedContent.CreateSimpleContent(contentType), - MockedContent.CreateSimpleContent(contentType), - MockedContent.CreateSimpleContent(contentType) + ContentBuilder.CreateSimpleContent(contentType), + ContentBuilder.CreateSimpleContent(contentType), + ContentBuilder.CreateSimpleContent(contentType) }; ContentService.Save(content); //assign permissions - we aren't assigning anything explicit for group3 and nothing explicit for content[2] /w group2 @@ -239,13 +239,13 @@ namespace Umbraco.Tests.Integration.Services // Arrange var userGroup = CreateTestUserGroup(); - var contentType = MockedContentTypes.CreateSimpleContentType(); + var contentType = ContentTypeBuilder.CreateSimpleContentType(); ContentTypeService.Save(contentType); var content = new[] { - MockedContent.CreateSimpleContent(contentType), - MockedContent.CreateSimpleContent(contentType), - MockedContent.CreateSimpleContent(contentType) + ContentBuilder.CreateSimpleContent(contentType), + ContentBuilder.CreateSimpleContent(contentType), + ContentBuilder.CreateSimpleContent(contentType) }; ContentService.Save(content); ContentService.SetPermission(content[0], ActionBrowse.ActionLetter, new int[] { userGroup.Id }); @@ -400,13 +400,13 @@ namespace Umbraco.Tests.Integration.Services // Arrange var userGroup = CreateTestUserGroup(); - var contentType = MockedContentTypes.CreateSimpleContentType(); + var contentType = ContentTypeBuilder.CreateSimpleContentType(); ContentTypeService.Save(contentType); - var parent = MockedContent.CreateSimpleContent(contentType); + var parent = ContentBuilder.CreateSimpleContent(contentType); ContentService.Save(parent); - var child1 = MockedContent.CreateSimpleContent(contentType, "child1", parent); + var child1 = ContentBuilder.CreateSimpleContent(contentType, "child1", parent.Id); ContentService.Save(child1); - var child2 = MockedContent.CreateSimpleContent(contentType, "child2", child1); + var child2 = ContentBuilder.CreateSimpleContent(contentType, "child2", child1.Id); ContentService.Save(child2); ContentService.SetPermission(parent, ActionBrowse.ActionLetter, new int[] { userGroup.Id }); @@ -496,7 +496,7 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Find_By_Email_Starts_With() { - var users = CreateMulipleUsers(10); + var users = UserBuilder. CreateMulipleUsers(10); UserService.Save(users); //don't find this var customUser = CreateUser(); @@ -511,7 +511,7 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Find_By_Email_Ends_With() { - var users = CreateMulipleUsers(10); + var users = UserBuilder. CreateMulipleUsers(10); UserService.Save(users); //include this var customUser = CreateUser(); @@ -526,7 +526,7 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Find_By_Email_Contains() { - var users = CreateMulipleUsers(10); + var users = UserBuilder. CreateMulipleUsers(10); UserService.Save(users); //include this var customUser = CreateUser(); @@ -541,7 +541,7 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Find_By_Email_Exact() { - var users = CreateMulipleUsers(10); + var users = UserBuilder. CreateMulipleUsers(10); UserService.Save(users); //include this var customUser = CreateUser(); @@ -556,7 +556,7 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Get_All_Paged_Users() { - var users = CreateMulipleUsers(10); + var users = UserBuilder. CreateMulipleUsers(10); UserService.Save(users); var found = UserService.GetAll(0, 2, out var totalRecs); @@ -571,7 +571,7 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Get_All_Paged_Users_With_Filter() { - var users = CreateMulipleUsers(10).ToArray(); + var users = UserBuilder. CreateMulipleUsers(10).ToArray(); UserService.Save(users); var found = UserService.GetAll(0, 2, out var totalRecs, "username", Direction.Ascending, filter: "test"); @@ -585,10 +585,10 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Get_All_Paged_Users_For_Group() { - var userGroup = MockedUserGroup.CreateUserGroup(); + var userGroup = UserGroupBuilder.CreateUserGroup(); UserService.Save(userGroup); - var users = CreateMulipleUsers(10).ToArray(); + var users = UserBuilder. CreateMulipleUsers(10).ToArray(); for (var i = 0; i < 10;) { users[i].AddGroup(userGroup.ToReadOnlyGroup()); @@ -608,10 +608,10 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Get_All_Paged_Users_For_Group_With_Filter() { - var userGroup = MockedUserGroup.CreateUserGroup(); + var userGroup = UserGroupBuilder.CreateUserGroup(); UserService.Save(userGroup); - var users = CreateMulipleUsers(10).ToArray(); + var users = UserBuilder. CreateMulipleUsers(10).ToArray(); for (var i = 0; i < 10;) { users[i].AddGroup(userGroup.ToReadOnlyGroup()); @@ -636,7 +636,7 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Count_All_Users() { - var users = CreateMulipleUsers(10); + var users = UserBuilder. CreateMulipleUsers(10); UserService.Save(users); var customUser = CreateUser(); UserService.Save(customUser); @@ -651,7 +651,7 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Count_All_Online_Users() { - var users = CreateMulipleUsers(10, (i, member) => member.LastLoginDate = DateTime.Now.AddMinutes(i * -2)); + var users = UserBuilder. CreateMulipleUsers(10, (i, member) => member.LastLoginDate = DateTime.Now.AddMinutes(i * -2)); UserService.Save(users); var customUser = CreateUser(); @@ -661,7 +661,7 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Count_All_Locked_Users() { - var users = CreateMulipleUsers(10, (i, member) => member.IsLockedOut = i % 2 == 0); + var users = UserBuilder.CreateMulipleUsers(10, (i, member) => member.IsLockedOut = i % 2 == 0); UserService.Save(users); var customUser = CreateUser(); @@ -676,7 +676,7 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Count_All_Approved_Users() { - var users = CreateMulipleUsers(10, (i, member) => member.IsApproved = i % 2 == 0); + var users = UserBuilder.CreateMulipleUsers(10, (i, member) => member.IsApproved = i % 2 == 0); UserService.Save(users); var customUser = CreateUser(); @@ -970,43 +970,20 @@ namespace Umbraco.Tests.Integration.Services private Content[] BuildContentItems(int numberToCreate) { - var contentType = MockedContentTypes.CreateSimpleContentType(); + var contentType = ContentTypeBuilder.CreateSimpleContentType(); ContentTypeService.Save(contentType); var startContentItems = new List(); for (var i = 0; i < numberToCreate; i++) - startContentItems.Add(MockedContent.CreateSimpleContent(contentType)); + startContentItems.Add(ContentBuilder.CreateSimpleContent(contentType)); ContentService.Save(startContentItems); return startContentItems.ToArray(); } - private static IEnumerable CreateMulipleUsers(int amount, Action onCreating = null) - { - var list = new List(); - - for (var i = 0; i < amount; i++) - { - var name = "User No-" + i; - var user = new UserBuilder() - .WithName(name) - .WithEmail("test" + i + "@test.com") - .WithLogin("test" + i, "test" + i) - .Build(); - - onCreating?.Invoke(i, user); - - user.ResetDirtyProperties(false); - - list.Add(user); - } - - return list; - } - private static User CreateUser(string suffix = "") { return new UserBuilder() diff --git a/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs b/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs index 36df0bbc64..968705f848 100644 --- a/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs +++ b/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs @@ -483,8 +483,8 @@ namespace Umbraco.Tests.Integration.Testing #region Builders - protected UserBuilder UserBuilder = new UserBuilder(); - protected UserGroupBuilder UserGroupBuilder = new UserGroupBuilder(); + protected UserBuilder UserBuilderInstance = new UserBuilder(); + protected UserGroupBuilder UserGroupBuilderInstance = new UserGroupBuilder(); #endregion diff --git a/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice/Filters/ContentModelValidatorTests.cs b/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice/Filters/ContentModelValidatorTests.cs index 1daae93675..92458804db 100644 --- a/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice/Filters/ContentModelValidatorTests.cs +++ b/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice/Filters/ContentModelValidatorTests.cs @@ -1,162 +1,159 @@ - using NUnit.Framework; - using System; - using System.Collections.Generic; - using System.Linq; - using Umbraco.Core.Services; - using Umbraco.Web.Models.ContentEditing; - using Umbraco.Tests.Testing; - using Umbraco.Core.PropertyEditors; - using Umbraco.Core.Composing; - using Umbraco.Web.PropertyEditors; - using System.ComponentModel.DataAnnotations; - using Microsoft.AspNetCore.Mvc.ModelBinding; - using Microsoft.Extensions.DependencyInjection; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using Microsoft.AspNetCore.Mvc.ModelBinding; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; - using Newtonsoft.Json; - using Newtonsoft.Json.Linq; - using Umbraco.Core; - using Umbraco.Core.IO; - using Umbraco.Core.Mapping; - using Umbraco.Core.Models; - using Umbraco.Core.Security; - using Umbraco.Core.Strings; - using Umbraco.Tests.Integration.Testing; - using Umbraco.Tests.TestHelpers.Entities; - using Umbraco.Web.BackOffice.Filters; - using Umbraco.Web.BackOffice.ModelBinders; - using Umbraco.Web.Security; - using DataType = Umbraco.Core.Models.DataType; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using NUnit.Framework; +using Umbraco.Core; +using Umbraco.Core.IO; +using Umbraco.Core.Logging; +using Umbraco.Core.Mapping; +using Umbraco.Core.Models; +using Umbraco.Core.PropertyEditors; +using Umbraco.Core.Security; +using Umbraco.Core.Services; +using Umbraco.Core.Strings; +using Umbraco.Tests.Common.Builders; +using Umbraco.Tests.Integration.Testing; +using Umbraco.Tests.Testing; +using Umbraco.Web.BackOffice.Filters; +using Umbraco.Web.BackOffice.ModelBinders; +using Umbraco.Web.Models.ContentEditing; +using Umbraco.Web.PropertyEditors; +using DataType = Umbraco.Core.Models.DataType; - namespace Umbraco.Tests.Web.Validation - { - [TestFixture] - [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest, Mapper = true, WithApplication = true, Logger = UmbracoTestOptions.Logger.Console)] - public class ContentModelValidatorTests : UmbracoIntegrationTest - { - private const string ContentTypeAlias = "textPage"; - private IContentType _contentType; - private ContentModelBinderHelper _modelBinderHelper = new ContentModelBinderHelper(); - private IShortStringHelper _shortStringHelper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig()); +namespace Umbraco.Tests.Web.Validation +{ + [TestFixture] + [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest, Mapper = true, WithApplication = true, Logger = UmbracoTestOptions.Logger.Console)] + public class ContentModelValidatorTests : UmbracoIntegrationTest + { + private const string ContentTypeAlias = "textPage"; + private IContentType _contentType; + private ContentModelBinderHelper _modelBinderHelper = new ContentModelBinderHelper(); + private IShortStringHelper _shortStringHelper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig()); - [SetUp] - public void SetUp() - { - var complexEditorConfig = new NestedContentConfiguration - { - ContentTypes = new[] - { + [SetUp] + public void SetUp() + { + var complexEditorConfig = new NestedContentConfiguration + { + ContentTypes = new[] + { new NestedContentConfiguration.ContentType { Alias = "feature" } } - }; + }; - var complexTestEditor = Services.GetRequiredService(); - var testEditor = Services.GetRequiredService(); - var dataTypeService = Services.GetRequiredService(); + var complexTestEditor = Services.GetRequiredService(); + var testEditor = Services.GetRequiredService(); + var dataTypeService = Services.GetRequiredService(); - var complexDataType = new DataType(complexTestEditor) - { - Name = "ComplexTest", - Configuration = complexEditorConfig - }; + var complexDataType = new DataType(complexTestEditor) + { + Name = "ComplexTest", + Configuration = complexEditorConfig + }; - var testDataType = new DataType(testEditor) - { - Name = "Test", - }; - dataTypeService.Save(complexDataType); - dataTypeService.Save(testDataType); + var testDataType = new DataType(testEditor) + { + Name = "Test", + }; + dataTypeService.Save(complexDataType); + dataTypeService.Save(testDataType); + var fileService = Services.GetRequiredService(); + var template = TemplateBuilder.CreateTextPageTemplate(); + fileService.SaveTemplate(template); + _contentType = ContentTypeBuilder.CreateTextPageContentType(ContentTypeAlias, defaultTemplateId: template.Id); - _contentType = MockedContentTypes.CreateTextPageContentType(ContentTypeAlias); - // add complex editor + // add complex editor + foreach (var pt in _contentType.PropertyTypes) + { + pt.DataTypeId = testDataType.Id; + } - foreach (var pt in _contentType.PropertyTypes) - { - pt.DataTypeId = testDataType.Id; - } + _contentType.AddPropertyType( + new PropertyType(_shortStringHelper, "complexTest", ValueStorageType.Ntext) { Alias = "complex", Name = "Complex", Description = "", Mandatory = false, SortOrder = 1, DataTypeId = complexDataType.Id }, + "Content"); - _contentType.AddPropertyType( - new PropertyType(_shortStringHelper, "complexTest", ValueStorageType.Ntext) { Alias = "complex", Name = "Complex", Description = "", Mandatory = false, SortOrder = 1, DataTypeId = complexDataType.Id }, - "Content"); + // make them all validate with a regex rule that will not pass + foreach (var prop in _contentType.PropertyTypes) + { + prop.ValidationRegExp = "^donotmatch$"; + prop.ValidationRegExpMessage = "Does not match!"; + } - // make them all validate with a regex rule that will not pass - foreach (var prop in _contentType.PropertyTypes) - { - prop.ValidationRegExp = "^donotmatch$"; - prop.ValidationRegExpMessage = "Does not match!"; - } + var contentTypeService = Services.GetRequiredService(); + contentTypeService.Save(_contentType); + } - var contentTypeService = Services.GetRequiredService(); + // + // protected override void Compose() + // { + // base.Compose(); + // + // var complexEditorConfig = new NestedContentConfiguration + // { + // ContentTypes = new[] + // { + // new NestedContentConfiguration.ContentType { Alias = "feature" } + // } + // }; + // var dataTypeService = new Mock(); + // dataTypeService.Setup(x => x.GetDataType(It.IsAny())) + // .Returns((int id) => id == ComplexDataTypeId + // ? Mock.Of(x => x.Configuration == complexEditorConfig) + // : Mock.Of()); + // + // var contentTypeService = new Mock(); + // contentTypeService.Setup(x => x.GetAll(It.IsAny())) + // .Returns(() => new List + // { + // _contentType + // }); + // + // var textService = new Mock(); + // textService.Setup(x => x.Localize("validation/invalidPattern", It.IsAny(), It.IsAny>())).Returns(() => "invalidPattern"); + // textService.Setup(x => x.Localize("validation/invalidNull", It.IsAny(), It.IsAny>())).Returns("invalidNull"); + // textService.Setup(x => x.Localize("validation/invalidEmpty", It.IsAny(), It.IsAny>())).Returns("invalidEmpty"); + // + // Composition.RegisterUnique(x => Mock.Of(x => x.GetDataType(It.IsAny()) == Mock.Of())); + // Composition.RegisterUnique(x => dataTypeService.Object); + // Composition.RegisterUnique(x => contentTypeService.Object); + // Composition.RegisterUnique(x => textService.Object); + // + // Composition.WithCollectionBuilder() + // .Add() + // .Add(); + // } + [Test] + public void Validating_ContentItemSave() + { + var logger = Services.GetRequiredService>(); + var backofficeSecurityFactory = Services.GetRequiredService(); + backofficeSecurityFactory.EnsureBackofficeSecurity(); + var backofficeSecurityAccessor = Services.GetRequiredService(); + var localizedTextService = Services.GetRequiredService(); + var propertyValidationService = Services.GetRequiredService(); + var umbracoMapper = Services.GetRequiredService(); + var validator = new ContentSaveModelValidator(logger, backofficeSecurityAccessor.BackofficeSecurity, localizedTextService, propertyValidationService); - contentTypeService.Save(_contentType); + var content = ContentBuilder.CreateTextpageContent(_contentType, "test", -1); - } + var id1 = new Guid("c8df5136-d606-41f0-9134-dea6ae0c2fd9"); + var id2 = new Guid("f916104a-4082-48b2-a515-5c4bf2230f38"); + var id3 = new Guid("77E15DE9-1C79-47B2-BC60-4913BC4D4C6A"); - // - // protected override void Compose() - // { - // base.Compose(); - // - // var complexEditorConfig = new NestedContentConfiguration - // { - // ContentTypes = new[] - // { - // new NestedContentConfiguration.ContentType { Alias = "feature" } - // } - // }; - // var dataTypeService = new Mock(); - // dataTypeService.Setup(x => x.GetDataType(It.IsAny())) - // .Returns((int id) => id == ComplexDataTypeId - // ? Mock.Of(x => x.Configuration == complexEditorConfig) - // : Mock.Of()); - // - // var contentTypeService = new Mock(); - // contentTypeService.Setup(x => x.GetAll(It.IsAny())) - // .Returns(() => new List - // { - // _contentType - // }); - // - // var textService = new Mock(); - // textService.Setup(x => x.Localize("validation/invalidPattern", It.IsAny(), It.IsAny>())).Returns(() => "invalidPattern"); - // textService.Setup(x => x.Localize("validation/invalidNull", It.IsAny(), It.IsAny>())).Returns("invalidNull"); - // textService.Setup(x => x.Localize("validation/invalidEmpty", It.IsAny(), It.IsAny>())).Returns("invalidEmpty"); - // - // Composition.RegisterUnique(x => Mock.Of(x => x.GetDataType(It.IsAny()) == Mock.Of())); - // Composition.RegisterUnique(x => dataTypeService.Object); - // Composition.RegisterUnique(x => contentTypeService.Object); - // Composition.RegisterUnique(x => textService.Object); - // - // Composition.WithCollectionBuilder() - // .Add() - // .Add(); - // } + // TODO: Ok now test with a 4th level complex nested editor - [Test] - public void Validating_ContentItemSave() - { - var logger = Services.GetRequiredService>(); - var backofficeSecurityFactory = Services.GetRequiredService(); - backofficeSecurityFactory.EnsureBackofficeSecurity(); - var backofficeSecurityAccessor = Services.GetRequiredService(); - var localizedTextService = Services.GetRequiredService(); - var propertyValidationService = Services.GetRequiredService(); - var umbracoMapper = Services.GetRequiredService(); - - var validator = new ContentSaveModelValidator(logger, backofficeSecurityAccessor.BackofficeSecurity, localizedTextService, propertyValidationService); - - var content = MockedContent.CreateTextpageContent(_contentType, "test", -1); - - var id1 = new Guid("c8df5136-d606-41f0-9134-dea6ae0c2fd9"); - var id2 = new Guid("f916104a-4082-48b2-a515-5c4bf2230f38"); - var id3 = new Guid("77E15DE9-1C79-47B2-BC60-4913BC4D4C6A"); - - // TODO: Ok now test with a 4th level complex nested editor - - var complexValue = @"[{ + var complexValue = @"[{ ""key"": """ + id1.ToString() + @""", ""name"": ""Hello world"", ""ncContentTypeAlias"": """ + ContentTypeAlias + @""", @@ -177,21 +174,21 @@ }] } ]"; - content.SetValue("complex", complexValue); + content.SetValue("complex", complexValue); - // map the persisted properties to a model representing properties to save - //var saveProperties = content.Properties.Select(x => Mapper.Map(x)).ToList(); - var saveProperties = content.Properties.Select(x => - { - return new ContentPropertyBasic - { - Alias = x.Alias, - Id = x.Id, - Value = x.GetValue() - }; - }).ToList(); + // map the persisted properties to a model representing properties to save + //var saveProperties = content.Properties.Select(x => Mapper.Map(x)).ToList(); + var saveProperties = content.Properties.Select(x => + { + return new ContentPropertyBasic + { + Alias = x.Alias, + Id = x.Id, + Value = x.GetValue() + }; + }).ToList(); - var saveVariants = new List + var saveVariants = new List { new ContentVariantSave { @@ -203,132 +200,132 @@ } }; - var save = new ContentItemSave - { - Id = content.Id, - Action = ContentSaveAction.Save, - ContentTypeAlias = _contentType.Alias, - ParentId = -1, - PersistedContent = content, - TemplateAlias = null, - Variants = saveVariants - }; + var save = new ContentItemSave + { + Id = content.Id, + Action = ContentSaveAction.Save, + ContentTypeAlias = _contentType.Alias, + ParentId = -1, + PersistedContent = content, + TemplateAlias = null, + Variants = saveVariants + }; - // This will map the ContentItemSave.Variants.PropertyCollectionDto and then map the values in the saved model - // back onto the persisted IContent model. - ContentItemBinder.BindModel(save, content, _modelBinderHelper, umbracoMapper); + // This will map the ContentItemSave.Variants.PropertyCollectionDto and then map the values in the saved model + // back onto the persisted IContent model. + ContentItemBinder.BindModel(save, content, _modelBinderHelper, umbracoMapper); - var modelState = new ModelStateDictionary(); - var isValid = validator.ValidatePropertiesData(save, saveVariants[0], saveVariants[0].PropertyCollectionDto, modelState); + var modelState = new ModelStateDictionary(); + var isValid = validator.ValidatePropertiesData(save, saveVariants[0], saveVariants[0].PropertyCollectionDto, modelState); - // list results for debugging - foreach (var state in modelState) - { - Console.WriteLine(state.Key); - foreach (var error in state.Value.Errors) - { - Console.WriteLine("\t" + error.ErrorMessage); - } - } + // list results for debugging + foreach (var state in modelState) + { + Console.WriteLine(state.Key); + foreach (var error in state.Value.Errors) + { + Console.WriteLine("\t" + error.ErrorMessage); + } + } - // assert - Assert.IsFalse(isValid); - Assert.AreEqual(11, modelState.Keys.Count()); - const string complexPropertyKey = "_Properties.complex.invariant.null"; - Assert.IsTrue(modelState.Keys.Contains(complexPropertyKey)); - foreach (var state in modelState.Where(x => x.Key != complexPropertyKey)) - { - foreach (var error in state.Value.Errors) - { - Assert.IsFalse(error.ErrorMessage.DetectIsJson()); // non complex is just an error message - } - } - var complexEditorErrors = modelState.Single(x => x.Key == complexPropertyKey).Value.Errors; - Assert.AreEqual(1, complexEditorErrors.Count); - var nestedError = complexEditorErrors[0]; - var jsonError = JsonConvert.DeserializeObject(nestedError.ErrorMessage); + // assert + Assert.IsFalse(isValid); + Assert.AreEqual(11, modelState.Keys.Count()); + const string complexPropertyKey = "_Properties.complex.invariant.null"; + Assert.IsTrue(modelState.Keys.Contains(complexPropertyKey)); + foreach (var state in modelState.Where(x => x.Key != complexPropertyKey)) + { + foreach (var error in state.Value.Errors) + { + Assert.IsFalse(error.ErrorMessage.DetectIsJson()); // non complex is just an error message + } + } + var complexEditorErrors = modelState.Single(x => x.Key == complexPropertyKey).Value.Errors; + Assert.AreEqual(1, complexEditorErrors.Count); + var nestedError = complexEditorErrors[0]; + var jsonError = JsonConvert.DeserializeObject(nestedError.ErrorMessage); - var modelStateKeys = new[] { "_Properties.title.invariant.null.innerFieldId", "_Properties.title.invariant.null.value", "_Properties.bodyText.invariant.null.innerFieldId", "_Properties.bodyText.invariant.null.value" }; - AssertNestedValidation(jsonError, 0, id1, modelStateKeys); - AssertNestedValidation(jsonError, 1, id2, modelStateKeys.Concat(new[] { "_Properties.complex.invariant.null.innerFieldId", "_Properties.complex.invariant.null.value" }).ToArray()); - var nestedJsonError = jsonError.SelectToken("$[1].complex") as JArray; - Assert.IsNotNull(nestedJsonError); - AssertNestedValidation(nestedJsonError, 0, id3, modelStateKeys); + var modelStateKeys = new[] { "_Properties.title.invariant.null.innerFieldId", "_Properties.title.invariant.null.value", "_Properties.bodyText.invariant.null.innerFieldId", "_Properties.bodyText.invariant.null.value" }; + AssertNestedValidation(jsonError, 0, id1, modelStateKeys); + AssertNestedValidation(jsonError, 1, id2, modelStateKeys.Concat(new[] { "_Properties.complex.invariant.null.innerFieldId", "_Properties.complex.invariant.null.value" }).ToArray()); + var nestedJsonError = jsonError.SelectToken("$[1].complex") as JArray; + Assert.IsNotNull(nestedJsonError); + AssertNestedValidation(nestedJsonError, 0, id3, modelStateKeys); - } + } - private void AssertNestedValidation(JArray jsonError, int index, Guid id, string[] modelStateKeys) - { - Assert.IsNotNull(jsonError.SelectToken("$[" + index + "]")); - Assert.AreEqual(id.ToString(), jsonError.SelectToken("$[" + index + "].$id").Value()); - Assert.AreEqual("textPage", jsonError.SelectToken("$[" + index + "].$elementTypeAlias").Value()); - Assert.IsNotNull(jsonError.SelectToken("$[" + index + "].ModelState")); - foreach (var key in modelStateKeys) - { - var error = jsonError.SelectToken("$[" + index + "].ModelState['" + key + "']") as JArray; - Assert.IsNotNull(error); - Assert.AreEqual(1, error.Count); - } - } + private void AssertNestedValidation(JArray jsonError, int index, Guid id, string[] modelStateKeys) + { + Assert.IsNotNull(jsonError.SelectToken("$[" + index + "]")); + Assert.AreEqual(id.ToString(), jsonError.SelectToken("$[" + index + "].$id").Value()); + Assert.AreEqual("textPage", jsonError.SelectToken("$[" + index + "].$elementTypeAlias").Value()); + Assert.IsNotNull(jsonError.SelectToken("$[" + index + "].ModelState")); + foreach (var key in modelStateKeys) + { + var error = jsonError.SelectToken("$[" + index + "].ModelState['" + key + "']") as JArray; + Assert.IsNotNull(error); + Assert.AreEqual(1, error.Count); + } + } - //[HideFromTypeFinder] - [DataEditor("complexTest", "test", "test")] - public class ComplexTestEditor : NestedContentPropertyEditor - { + //[HideFromTypeFinder] + [DataEditor("complexTest", "test", "test")] + public class ComplexTestEditor : NestedContentPropertyEditor + { public ComplexTestEditor(ILoggerFactory loggerFactory, Lazy propertyEditors, IDataTypeService dataTypeService, IContentTypeService contentTypeService, ILocalizationService localizationService, - IIOHelper ioHelper, ILocalizedTextService localizedTextService, IShortStringHelper shortStringHelper) + IIOHelper ioHelper, ILocalizedTextService localizedTextService, IShortStringHelper shortStringHelper) : base(loggerFactory, propertyEditors, dataTypeService, localizationService, contentTypeService, ioHelper, shortStringHelper, localizedTextService) - { - } + { + } - protected override IDataValueEditor CreateValueEditor() - { - var editor = base.CreateValueEditor(); - editor.Validators.Add(new NeverValidateValidator()); - return editor; - } - } + protected override IDataValueEditor CreateValueEditor() + { + var editor = base.CreateValueEditor(); + editor.Validators.Add(new NeverValidateValidator()); + return editor; + } + } //[HideFromTypeFinder] [DataEditor("test", "test", "test")] // This alias aligns with the prop editor alias for all properties created from MockedContentTypes.CreateTextPageContentType public class TestEditor : DataEditor { public TestEditor(ILoggerFactory loggerFactory, - IDataTypeService dataTypeService, - ILocalizationService localizationService, - ILocalizedTextService localizedTextService, - IShortStringHelper shortStringHelper) + IDataTypeService dataTypeService, + ILocalizationService localizationService, + ILocalizedTextService localizedTextService, + IShortStringHelper shortStringHelper) : base(loggerFactory, dataTypeService, localizationService, localizedTextService, shortStringHelper) - { + { - } + } - protected override IDataValueEditor CreateValueEditor() => new TestValueEditor(DataTypeService, LocalizationService, LocalizedTextService, ShortStringHelper, Attribute); + protected override IDataValueEditor CreateValueEditor() => new TestValueEditor(DataTypeService, LocalizationService, LocalizedTextService, ShortStringHelper, Attribute); - private class TestValueEditor : DataValueEditor - { - public TestValueEditor( - IDataTypeService dataTypeService, - ILocalizationService localizationService, - ILocalizedTextService localizedTextService, - IShortStringHelper shortStringHelper, - DataEditorAttribute attribute) - : base(dataTypeService, localizationService, localizedTextService, shortStringHelper, attribute) - { - Validators.Add(new NeverValidateValidator()); - } + private class TestValueEditor : DataValueEditor + { + public TestValueEditor( + IDataTypeService dataTypeService, + ILocalizationService localizationService, + ILocalizedTextService localizedTextService, + IShortStringHelper shortStringHelper, + DataEditorAttribute attribute) + : base(dataTypeService, localizationService, localizedTextService, shortStringHelper, attribute) + { + Validators.Add(new NeverValidateValidator()); + } - } - } + } + } - public class NeverValidateValidator : IValueValidator - { - public IEnumerable Validate(object value, string valueType, object dataTypeConfiguration) - { - yield return new ValidationResult("WRONG!", new[] { "innerFieldId" }); - } - } + public class NeverValidateValidator : IValueValidator + { + public IEnumerable Validate(object value, string valueType, object dataTypeConfiguration) + { + yield return new ValidationResult("WRONG!", new[] { "innerFieldId" }); + } + } - } - } + } +} diff --git a/src/Umbraco.Tests.Common/TestHelpers/Entities/MockedContent.cs b/src/Umbraco.Tests/TestHelpers/Entities/MockedContent.cs similarity index 100% rename from src/Umbraco.Tests.Common/TestHelpers/Entities/MockedContent.cs rename to src/Umbraco.Tests/TestHelpers/Entities/MockedContent.cs diff --git a/src/Umbraco.Tests.Common/TestHelpers/MockedContentTypes.cs b/src/Umbraco.Tests/TestHelpers/Entities/MockedContentTypes.cs similarity index 100% rename from src/Umbraco.Tests.Common/TestHelpers/MockedContentTypes.cs rename to src/Umbraco.Tests/TestHelpers/Entities/MockedContentTypes.cs diff --git a/src/Umbraco.Tests.Common/TestHelpers/Entities/MockedMedia.cs b/src/Umbraco.Tests/TestHelpers/Entities/MockedMedia.cs similarity index 100% rename from src/Umbraco.Tests.Common/TestHelpers/Entities/MockedMedia.cs rename to src/Umbraco.Tests/TestHelpers/Entities/MockedMedia.cs diff --git a/src/Umbraco.Tests.Common/TestHelpers/Entities/MockedMember.cs b/src/Umbraco.Tests/TestHelpers/Entities/MockedMember.cs similarity index 100% rename from src/Umbraco.Tests.Common/TestHelpers/Entities/MockedMember.cs rename to src/Umbraco.Tests/TestHelpers/Entities/MockedMember.cs diff --git a/src/Umbraco.Tests.Common/TestHelpers/Entities/MockedUserGroup.cs b/src/Umbraco.Tests/TestHelpers/Entities/MockedUserGroup.cs similarity index 100% rename from src/Umbraco.Tests.Common/TestHelpers/Entities/MockedUserGroup.cs rename to src/Umbraco.Tests/TestHelpers/Entities/MockedUserGroup.cs diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index e8b188bd63..07e8107dfd 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -153,9 +153,14 @@ + + + + +