* Update gitignore * Move csproj * Update project references * Update solutions * Update build scripts * Tests used to share editorconfig with projects in src * Fix broken tests. * Stop copying around .editorconfig merged root one with linting * csharp_style_expression_bodied -> suggestion * Move StyleCop rulesets to matching directories and update shared build properties * Remove legacy build files, update NuGet.cofig and solution files * Restore myget source * Clean up .gitignore * Update .gitignore * Move new test classes to tests after merge * Gitignore + nuget config * Move new test Co-authored-by: Ronald Barendse <ronald@barend.se>
53 lines
1.9 KiB
C#
53 lines
1.9 KiB
C#
// Copyright (c) Umbraco.
|
|
// See LICENSE for more details.
|
|
|
|
using Umbraco.Cms.Core.Models;
|
|
|
|
namespace Umbraco.Cms.Tests.Common.Builders.Extensions
|
|
{
|
|
public static class ContentItemSaveBuilderExtensions
|
|
{
|
|
public static ContentItemSaveBuilder WithContent(this ContentItemSaveBuilder builder, IContent content)
|
|
{
|
|
builder.WithId(content.Id);
|
|
builder.WithContentTypeAlias(content.ContentType.Alias);
|
|
|
|
if (content.CultureInfos.Count == 0)
|
|
{
|
|
ContentVariantSaveBuilder<ContentItemSaveBuilder> variantBuilder = builder.AddVariant();
|
|
variantBuilder.WithName(content.Name);
|
|
|
|
foreach (IProperty contentProperty in content.Properties)
|
|
{
|
|
AddInvariantProperty(variantBuilder, contentProperty);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
foreach (ContentCultureInfos contentCultureInfos in content.CultureInfos)
|
|
{
|
|
ContentVariantSaveBuilder<ContentItemSaveBuilder> variantBuilder = builder.AddVariant();
|
|
|
|
variantBuilder.WithName(contentCultureInfos.Name);
|
|
variantBuilder.WithCultureInfo(contentCultureInfos.Culture);
|
|
|
|
foreach (IProperty contentProperty in content.Properties)
|
|
{
|
|
AddInvariantProperty(variantBuilder, contentProperty);
|
|
}
|
|
}
|
|
}
|
|
|
|
return builder;
|
|
}
|
|
|
|
private static void AddInvariantProperty(ContentVariantSaveBuilder<ContentItemSaveBuilder> variantBuilder, IProperty contentProperty) =>
|
|
variantBuilder
|
|
.AddProperty()
|
|
.WithId(contentProperty.Id)
|
|
.WithAlias(contentProperty.Alias)
|
|
.WithValue(contentProperty.GetValue())
|
|
.Done();
|
|
}
|
|
}
|