2020-12-05 11:12:55 +01:00
|
|
|
// Copyright (c) Umbraco.
|
|
|
|
|
// See LICENSE for more details.
|
|
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
2020-06-17 16:39:28 +02:00
|
|
|
using System.Globalization;
|
|
|
|
|
using System.Linq;
|
2021-02-18 11:06:02 +01:00
|
|
|
using Umbraco.Cms.Core.Models.ContentEditing;
|
|
|
|
|
using Umbraco.Cms.Tests.Common.Builders.Interfaces;
|
2020-06-17 16:39:28 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
namespace Umbraco.Cms.Tests.Common.Builders;
|
|
|
|
|
|
|
|
|
|
public class ContentVariantSaveBuilder<TParent> : ChildBuilderBase<TParent, ContentVariantSave>,
|
|
|
|
|
IWithNameBuilder,
|
|
|
|
|
IWithCultureInfoBuilder
|
2020-06-17 16:39:28 +02:00
|
|
|
{
|
2022-06-21 08:09:38 +02:00
|
|
|
private readonly List<ContentPropertyBasicBuilder<ContentVariantSaveBuilder<TParent>>> _propertyBuilders = new();
|
|
|
|
|
private CultureInfo _cultureInfo;
|
2020-06-17 16:39:28 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
private string _name;
|
|
|
|
|
private bool? _publish;
|
|
|
|
|
private bool? _save;
|
2020-06-17 16:39:28 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
public ContentVariantSaveBuilder(TParent parentBuilder)
|
|
|
|
|
: base(parentBuilder)
|
|
|
|
|
{
|
|
|
|
|
}
|
2020-12-05 11:12:55 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
CultureInfo IWithCultureInfoBuilder.CultureInfo
|
|
|
|
|
{
|
|
|
|
|
get => _cultureInfo;
|
|
|
|
|
set => _cultureInfo = value;
|
|
|
|
|
}
|
2020-12-05 11:12:55 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
string IWithNameBuilder.Name
|
|
|
|
|
{
|
|
|
|
|
get => _name;
|
|
|
|
|
set => _name = value;
|
|
|
|
|
}
|
2020-06-17 16:39:28 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
public ContentVariantSaveBuilder<TParent> WithSave(bool save)
|
|
|
|
|
{
|
|
|
|
|
_save = save;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
2020-06-17 16:39:28 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
public ContentVariantSaveBuilder<TParent> WithPublish(bool publish)
|
|
|
|
|
{
|
|
|
|
|
_publish = publish;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
2020-06-17 16:39:28 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
public ContentPropertyBasicBuilder<ContentVariantSaveBuilder<TParent>> AddProperty()
|
|
|
|
|
{
|
|
|
|
|
var builder = new ContentPropertyBasicBuilder<ContentVariantSaveBuilder<TParent>>(this);
|
|
|
|
|
_propertyBuilders.Add(builder);
|
|
|
|
|
return builder;
|
|
|
|
|
}
|
2020-06-17 16:39:28 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
public override ContentVariantSave Build()
|
|
|
|
|
{
|
|
|
|
|
var name = _name;
|
|
|
|
|
var culture = _cultureInfo?.Name;
|
|
|
|
|
var save = _save ?? true;
|
|
|
|
|
var publish = _publish ?? true;
|
|
|
|
|
var properties = _propertyBuilders.Select(x => x.Build());
|
2020-06-17 16:39:28 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
return new ContentVariantSave
|
2020-06-17 16:39:28 +02:00
|
|
|
{
|
2022-06-21 08:09:38 +02:00
|
|
|
Name = name,
|
|
|
|
|
Culture = culture,
|
|
|
|
|
Save = save,
|
|
|
|
|
Publish = publish,
|
|
|
|
|
Properties = properties
|
|
|
|
|
};
|
2020-06-17 16:39:28 +02:00
|
|
|
}
|
|
|
|
|
}
|