-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
V15 updated the hybrid caching integration tests to use ContentEditin…
…gService (#16947) * Added builder extension withParentKey * Created builder with ContentEditingService * Added usage of the ContentEditingService to SETUP * Started using ContentEditingService builder in tests * Updated builder extensions * Fixed builder * Clean up * Clean up, not done * Added Ids
- Loading branch information
Showing
10 changed files
with
619 additions
and
114 deletions.
There are no files selected for viewing
172 changes: 172 additions & 0 deletions
172
tests/Umbraco.Tests.Common/Builders/ContentEditingBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
// Copyright (c) Umbraco. | ||
Check warning on line 1 in tests/Umbraco.Tests.Common/Builders/ContentEditingBuilder.cs CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (v15/dev)❌ New issue: Primitive Obsession
|
||
// See LICENSE for more details. | ||
|
||
using Umbraco.Cms.Core.Models; | ||
using Umbraco.Cms.Core.Models.ContentEditing; | ||
using Umbraco.Cms.Tests.Common.Builders.Extensions; | ||
using Umbraco.Cms.Tests.Common.Builders.Interfaces; | ||
using Umbraco.Cms.Tests.Common.Builders.Interfaces.ContentCreateModel; | ||
|
||
namespace Umbraco.Cms.Tests.Common.Builders; | ||
|
||
public class ContentEditingBuilder | ||
: BuilderBase<ContentCreateModel>, | ||
IWithInvariantNameBuilder, | ||
IWithInvariantPropertiesBuilder, | ||
IWithVariantsBuilder, | ||
IWithKeyBuilder, | ||
IWithContentTypeKeyBuilder, | ||
IWithParentKeyBuilder, | ||
IWithTemplateKeyBuilder | ||
{ | ||
private IContentType _contentType; | ||
private ContentTypeBuilder _contentTypeBuilder; | ||
private IEnumerable<PropertyValueModel> _invariantProperties = []; | ||
private IEnumerable<VariantModel> _variants = []; | ||
private Guid _contentTypeKey; | ||
private Guid? _parentKey; | ||
private Guid? _templateKey; | ||
private Guid? _key; | ||
private string _invariantName; | ||
|
||
Guid? IWithKeyBuilder.Key | ||
{ | ||
get => _key; | ||
set => _key = value; | ||
} | ||
|
||
string IWithInvariantNameBuilder.InvariantName | ||
{ | ||
get => _invariantName; | ||
set => _invariantName = value; | ||
} | ||
|
||
IEnumerable<PropertyValueModel> IWithInvariantPropertiesBuilder.InvariantProperties | ||
{ | ||
get => _invariantProperties; | ||
set => _invariantProperties = value; | ||
} | ||
|
||
IEnumerable<VariantModel> IWithVariantsBuilder.Variants | ||
{ | ||
get => _variants; | ||
set => _variants = value; | ||
} | ||
|
||
Guid? IWithParentKeyBuilder.ParentKey | ||
{ | ||
get => _parentKey; | ||
set => _parentKey = value; | ||
} | ||
|
||
Guid IWithContentTypeKeyBuilder.ContentTypeKey | ||
{ | ||
get => _contentTypeKey; | ||
set => _contentTypeKey = value; | ||
} | ||
|
||
Guid? IWithTemplateKeyBuilder.TemplateKey | ||
{ | ||
get => _templateKey; | ||
set => _templateKey = value; | ||
} | ||
|
||
public ContentEditingBuilder WithInvariantName(string invariantName) | ||
{ | ||
_invariantName = invariantName; | ||
return this; | ||
} | ||
|
||
public ContentEditingBuilder WithInvariantProperty(string alias, object value) | ||
{ | ||
var property = new PropertyValueModel { Alias = alias, Value = value }; | ||
_invariantProperties = _invariantProperties.Concat(new[] { property }); | ||
return this; | ||
} | ||
|
||
public ContentEditingBuilder AddVariant(string culture, string segment, string name, | ||
IEnumerable<PropertyValueModel> properties) | ||
{ | ||
var variant = new VariantModel { Culture = culture, Segment = segment, Name = name, Properties = properties }; | ||
_variants = _variants.Concat(new[] { variant }); | ||
return this; | ||
} | ||
|
||
public ContentEditingBuilder WithParentKey(Guid parentKey) | ||
{ | ||
_parentKey = parentKey; | ||
return this; | ||
} | ||
|
||
public ContentEditingBuilder WithTemplateKey(Guid templateKey) | ||
{ | ||
_templateKey = templateKey; | ||
return this; | ||
} | ||
|
||
public ContentEditingBuilder WithContentType(IContentType contentType) | ||
{ | ||
_contentTypeBuilder = null; | ||
_contentType = contentType; | ||
return this; | ||
} | ||
|
||
public override ContentCreateModel Build() | ||
{ | ||
var key = _key ?? Guid.NewGuid(); | ||
var parentKey = _parentKey; | ||
var templateKey = _templateKey; | ||
var invariantName = _invariantName ?? Guid.NewGuid().ToString(); | ||
var invariantProperties = _invariantProperties; | ||
var variants = _variants; | ||
|
||
if (_contentTypeBuilder is null && _contentType is null) | ||
{ | ||
throw new InvalidOperationException( | ||
"A content item cannot be constructed without providing a content type. Use AddContentType() or WithContentType()."); | ||
} | ||
|
||
var contentType = _contentType ?? _contentTypeBuilder.Build(); | ||
var content = new ContentCreateModel(); | ||
|
||
content.InvariantName = invariantName; | ||
if (parentKey is not null) | ||
{ | ||
content.ParentKey = parentKey; | ||
} | ||
|
||
if (templateKey is not null) | ||
{ | ||
content.TemplateKey = templateKey; | ||
} | ||
|
||
content.ContentTypeKey = contentType.Key; | ||
content.Key = key; | ||
content.InvariantProperties = invariantProperties; | ||
content.Variants = variants; | ||
|
||
return content; | ||
} | ||
|
||
public static ContentCreateModel CreateBasicContent(IContentType contentType, Guid? key) => | ||
new ContentEditingBuilder() | ||
.WithKey(key) | ||
.WithContentType(contentType) | ||
.WithInvariantName("Home") | ||
.Build(); | ||
|
||
public static ContentCreateModel CreateSimpleContent(IContentType contentType) => | ||
new ContentEditingBuilder() | ||
.WithContentType(contentType) | ||
.WithInvariantName("Home") | ||
.WithInvariantProperty("title", "Welcome to our Home page") | ||
.Build(); | ||
|
||
public static ContentCreateModel CreateSimpleContent(IContentType contentType, string name, Guid? parentKey) => | ||
new ContentEditingBuilder() | ||
.WithContentType(contentType) | ||
.WithInvariantName(name) | ||
.WithParentKey(parentKey) | ||
.WithInvariantProperty("title", "Welcome to our Home page") | ||
.Build(); | ||
} |
58 changes: 58 additions & 0 deletions
58
tests/Umbraco.Tests.Common/Builders/Extensions/ContentEditingBuilderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using Umbraco.Cms.Core.Models.ContentEditing; | ||
using Umbraco.Cms.Tests.Common.Builders.Interfaces; | ||
using Umbraco.Cms.Tests.Common.Builders.Interfaces.ContentCreateModel; | ||
|
||
namespace Umbraco.Cms.Tests.Common.Builders.Extensions; | ||
|
||
public static class ContentEditingBuilderExtensions | ||
{ | ||
public static T WithInvariantName<T>(this T Builder, string invariantName) | ||
where T : IWithInvariantNameBuilder | ||
{ | ||
Builder.InvariantName = invariantName; | ||
return Builder; | ||
} | ||
|
||
public static T WithInvariantProperties<T>(this T Builder, IEnumerable<PropertyValueModel> invariantProperties) | ||
where T : IWithInvariantPropertiesBuilder | ||
{ | ||
Builder.InvariantProperties = invariantProperties; | ||
return Builder; | ||
} | ||
|
||
public static T WithVariants<T>(this T Builder, IEnumerable<VariantModel> variants) | ||
where T : IWithVariantsBuilder | ||
{ | ||
Builder.Variants = variants; | ||
return Builder; | ||
} | ||
|
||
public static T WithKey<T>(this T Builder, Guid? key) | ||
where T : IWithKeyBuilder | ||
{ | ||
Builder.Key = key; | ||
return Builder; | ||
} | ||
|
||
public static T WithContentTypeKey<T>(this T Builder, Guid contentTypeKey) | ||
where T : IWithContentTypeKeyBuilder | ||
{ | ||
Builder.ContentTypeKey = contentTypeKey; | ||
return Builder; | ||
} | ||
|
||
public static T WithParentKey<T>(this T Builder, Guid? parentKey) | ||
where T : IWithParentKeyBuilder | ||
{ | ||
Builder.ParentKey = parentKey; | ||
return Builder; | ||
} | ||
|
||
|
||
public static T WithTemplateKey<T>(this T Builder, Guid? templateKey) | ||
where T : IWithTemplateKeyBuilder | ||
{ | ||
Builder.TemplateKey = templateKey; | ||
return Builder; | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...Umbraco.Tests.Common/Builders/Interfaces/ContentCreateModel/IWithContentTypeKeyBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Umbraco.Cms.Tests.Common.Builders.Interfaces.ContentCreateModel; | ||
|
||
public interface IWithContentTypeKeyBuilder | ||
{ | ||
public Guid ContentTypeKey { get; set; } | ||
} |
6 changes: 6 additions & 0 deletions
6
.../Umbraco.Tests.Common/Builders/Interfaces/ContentCreateModel/IWithInvariantNameBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Umbraco.Cms.Tests.Common.Builders.Interfaces.ContentCreateModel; | ||
|
||
public interface IWithInvariantNameBuilder | ||
{ | ||
public string? InvariantName { get; set; } | ||
} |
8 changes: 8 additions & 0 deletions
8
...co.Tests.Common/Builders/Interfaces/ContentCreateModel/IWithInvariantPropertiesBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using Umbraco.Cms.Core.Models.ContentEditing; | ||
|
||
namespace Umbraco.Cms.Tests.Common.Builders.Interfaces.ContentCreateModel; | ||
|
||
public interface IWithInvariantPropertiesBuilder | ||
{ | ||
public IEnumerable<PropertyValueModel> InvariantProperties { get; set; } | ||
} |
9 changes: 9 additions & 0 deletions
9
tests/Umbraco.Tests.Common/Builders/Interfaces/ContentCreateModel/IWithParentKeyBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Copyright (c) Umbraco. | ||
// See LICENSE for more details. | ||
|
||
namespace Umbraco.Cms.Tests.Common.Builders.Interfaces; | ||
|
||
public interface IWithParentKeyBuilder | ||
{ | ||
Guid? ParentKey { get; set; } | ||
} |
6 changes: 6 additions & 0 deletions
6
tests/Umbraco.Tests.Common/Builders/Interfaces/ContentCreateModel/IWithTemplateKeyBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Umbraco.Cms.Tests.Common.Builders.Interfaces.ContentCreateModel; | ||
|
||
public interface IWithTemplateKeyBuilder | ||
{ | ||
public Guid? TemplateKey { get; set; } | ||
} |
8 changes: 8 additions & 0 deletions
8
tests/Umbraco.Tests.Common/Builders/Interfaces/ContentCreateModel/IWithVariantsBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using Umbraco.Cms.Core.Models.ContentEditing; | ||
|
||
namespace Umbraco.Cms.Tests.Common.Builders.Interfaces.ContentCreateModel; | ||
|
||
public interface IWithVariantsBuilder | ||
{ | ||
public IEnumerable<VariantModel> Variants { get; set; } | ||
} |
Oops, something went wrong.