2020-12-05 11:12:55 +01:00
|
|
|
// Copyright (c) Umbraco.
|
|
|
|
|
// See LICENSE for more details.
|
|
|
|
|
|
2020-03-29 16:17:06 +02:00
|
|
|
using System.Collections.Generic;
|
2020-04-12 09:47:44 +02:00
|
|
|
using System.Linq;
|
2020-03-29 16:17:06 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
namespace Umbraco.Cms.Tests.Common.Builders;
|
|
|
|
|
|
|
|
|
|
public class GenericCollectionBuilder<TBuilder, T>
|
|
|
|
|
: ChildBuilderBase<TBuilder, IEnumerable<T>>
|
2020-03-29 16:17:06 +02:00
|
|
|
{
|
2022-06-21 08:09:38 +02:00
|
|
|
private readonly IList<T> _collection;
|
2020-03-29 16:17:06 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
public GenericCollectionBuilder(TBuilder parentBuilder)
|
|
|
|
|
: base(parentBuilder) => _collection = new List<T>();
|
2020-03-29 16:17:06 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
public override IEnumerable<T> Build()
|
|
|
|
|
{
|
|
|
|
|
var collection = _collection?.ToList() ?? Enumerable.Empty<T>();
|
|
|
|
|
return collection;
|
|
|
|
|
}
|
2020-04-12 09:47:44 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
public GenericCollectionBuilder<TBuilder, T> WithValue(T value)
|
|
|
|
|
{
|
|
|
|
|
_collection.Add(value);
|
|
|
|
|
return this;
|
2020-03-29 16:17:06 +02:00
|
|
|
}
|
|
|
|
|
}
|