2020-03-28 20:54:10 +01:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Tests.Common.Builders
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
|
|
|
public GenericDictionaryBuilder(TBuilder parentBuilder) : base(parentBuilder)
|
|
|
|
|
{
|
2020-04-16 11:39:30 +02:00
|
|
|
_dictionary = new Dictionary<TKey, TValue>();
|
2020-03-28 20:54:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override IDictionary<TKey, TValue> Build()
|
|
|
|
|
{
|
2020-04-16 11:39:30 +02:00
|
|
|
return _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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|