2020-12-05 11:12:55 +01:00
|
|
|
// Copyright (c) Umbraco.
|
|
|
|
|
// See LICENSE for more details.
|
|
|
|
|
|
2020-01-09 14:24:20 +01:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2021-02-18 11:06:02 +01:00
|
|
|
using Umbraco.Cms.Core.Models;
|
|
|
|
|
using Umbraco.Cms.Tests.Common.Builders.Interfaces;
|
2020-01-09 14:24:20 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
namespace Umbraco.Cms.Tests.Common.Builders;
|
|
|
|
|
|
|
|
|
|
public class DictionaryItemBuilder
|
|
|
|
|
: BuilderBase<DictionaryItem>,
|
|
|
|
|
IWithIdBuilder,
|
|
|
|
|
IWithCreateDateBuilder,
|
|
|
|
|
IWithUpdateDateBuilder,
|
|
|
|
|
IWithDeleteDateBuilder,
|
|
|
|
|
IWithKeyBuilder
|
2020-01-09 13:04:27 +01:00
|
|
|
{
|
2022-06-21 08:09:38 +02:00
|
|
|
private readonly List<DictionaryTranslationBuilder> _translationBuilders = new();
|
|
|
|
|
|
|
|
|
|
private DateTime? _createDate;
|
|
|
|
|
private DateTime? _deleteDate;
|
|
|
|
|
private int? _id;
|
|
|
|
|
private string _itemKey;
|
|
|
|
|
private Guid? _key;
|
|
|
|
|
private Guid? _parentId;
|
|
|
|
|
private DateTime? _updateDate;
|
|
|
|
|
|
|
|
|
|
DateTime? IWithCreateDateBuilder.CreateDate
|
2020-01-09 13:04:27 +01:00
|
|
|
{
|
2022-06-21 08:09:38 +02:00
|
|
|
get => _createDate;
|
|
|
|
|
set => _createDate = value;
|
|
|
|
|
}
|
2020-01-13 07:29:12 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
DateTime? IWithDeleteDateBuilder.DeleteDate
|
|
|
|
|
{
|
|
|
|
|
get => _deleteDate;
|
|
|
|
|
set => _deleteDate = value;
|
|
|
|
|
}
|
2020-01-13 07:29:12 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
int? IWithIdBuilder.Id
|
|
|
|
|
{
|
|
|
|
|
get => _id;
|
|
|
|
|
set => _id = value;
|
|
|
|
|
}
|
2020-01-13 07:29:12 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
Guid? IWithKeyBuilder.Key
|
|
|
|
|
{
|
|
|
|
|
get => _key;
|
|
|
|
|
set => _key = value;
|
|
|
|
|
}
|
2020-01-13 07:29:12 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
DateTime? IWithUpdateDateBuilder.UpdateDate
|
|
|
|
|
{
|
|
|
|
|
get => _updateDate;
|
|
|
|
|
set => _updateDate = value;
|
|
|
|
|
}
|
2020-01-13 07:29:12 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
public override DictionaryItem Build()
|
|
|
|
|
{
|
|
|
|
|
var createDate = _createDate ?? DateTime.Now;
|
|
|
|
|
var updateDate = _updateDate ?? DateTime.Now;
|
|
|
|
|
var deleteDate = _deleteDate;
|
|
|
|
|
var id = _id ?? 1;
|
|
|
|
|
var key = _key ?? Guid.NewGuid();
|
|
|
|
|
var parentId = _parentId;
|
|
|
|
|
var itemKey = _itemKey ?? Guid.NewGuid().ToString();
|
|
|
|
|
|
|
|
|
|
var result = new DictionaryItem(itemKey)
|
2020-01-09 13:04:27 +01:00
|
|
|
{
|
2022-06-21 08:09:38 +02:00
|
|
|
Translations = _translationBuilders.Select(x => x.Build()),
|
|
|
|
|
CreateDate = createDate,
|
|
|
|
|
UpdateDate = updateDate,
|
|
|
|
|
DeleteDate = deleteDate,
|
|
|
|
|
Id = id,
|
|
|
|
|
ParentId = parentId,
|
|
|
|
|
Key = key
|
|
|
|
|
};
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2020-01-09 14:24:20 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
public DictionaryItemBuilder WithParentId(Guid parentId)
|
|
|
|
|
{
|
|
|
|
|
_parentId = parentId;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
2020-01-13 07:29:12 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
public DictionaryItemBuilder WithItemKey(string itemKey)
|
|
|
|
|
{
|
|
|
|
|
_itemKey = itemKey;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
2020-01-13 07:29:12 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
public DictionaryTranslationBuilder AddTranslation()
|
|
|
|
|
{
|
|
|
|
|
var builder = new DictionaryTranslationBuilder(this);
|
2020-01-09 14:24:20 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
_translationBuilders.Add(builder);
|
2020-01-09 14:24:20 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
return builder;
|
|
|
|
|
}
|
2020-01-09 14:24:20 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
public DictionaryItemBuilder WithRandomTranslations(int count)
|
|
|
|
|
{
|
|
|
|
|
for (var i = 0; i < count; i++)
|
2020-01-09 14:24:20 +01:00
|
|
|
{
|
2022-06-21 08:09:38 +02:00
|
|
|
AddTranslation().Done();
|
2020-01-09 14:49:11 +01:00
|
|
|
}
|
2022-06-21 08:09:38 +02:00
|
|
|
|
|
|
|
|
return this;
|
2020-01-09 13:04:27 +01:00
|
|
|
}
|
|
|
|
|
}
|