2020-12-05 11:12:55 +01:00
|
|
|
// Copyright (c) Umbraco.
|
|
|
|
|
// See LICENSE for more details.
|
|
|
|
|
|
2020-03-28 20:54:10 +01:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
2021-02-18 11:06:02 +01:00
|
|
|
namespace Umbraco.Cms.Tests.Common.Builders
|
2020-03-28 20:54:10 +01:00
|
|
|
{
|
|
|
|
|
public class GenericDictionaryBuilder<TBuilder, TKey, TValue>
|
|
|
|
|
: ChildBuilderBase<TBuilder, IDictionary<TKey, TValue>>
|
|
|
|
|
{
|
2020-04-16 11:39:30 +02:00
|
|
|
private readonly IDictionary<TKey, TValue> _dictionary;
|
2020-03-28 20:54:10 +01:00
|
|
|
|
2020-12-05 11:12:55 +01:00
|
|
|
public GenericDictionaryBuilder(TBuilder parentBuilder)
|
|
|
|
|
: base(parentBuilder) => _dictionary = new Dictionary<TKey, TValue>();
|
2020-03-28 20:54:10 +01:00
|
|
|
|
2020-12-05 11:12:55 +01:00
|
|
|
public override IDictionary<TKey, TValue> Build() => _dictionary == null
|
2020-04-12 09:47:44 +02:00
|
|
|
? new Dictionary<TKey, TValue>()
|
|
|
|
|
: new Dictionary<TKey, TValue>(_dictionary);
|
2020-03-28 20:54:10 +01:00
|
|
|
|
2020-03-29 16:17:06 +02:00
|
|
|
public GenericDictionaryBuilder<TBuilder, TKey, TValue> WithKeyValue(TKey key, TValue value)
|
2020-03-28 20:54:10 +01:00
|
|
|
{
|
|
|
|
|
_dictionary.Add(key, value);
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|