2020-12-30 05:14:42 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Diagnostics.CodeAnalysis;
|
|
|
|
using System.IO;
|
2021-04-19 06:34:45 +00:00
|
|
|
using GameServiceWarden.Core.Module;
|
2020-12-30 05:14:42 +00:00
|
|
|
using GameServiceWarden.Core.Persistence;
|
|
|
|
|
|
|
|
namespace GameServiceWarden.Core.Tests.Modules
|
|
|
|
{
|
2021-04-01 01:29:22 +00:00
|
|
|
public class FakePersistence<V> : IPersistent<V>
|
2020-12-30 05:14:42 +00:00
|
|
|
{
|
|
|
|
private IDictionary<string, V> backing = new Dictionary<string, V>();
|
|
|
|
public V this[string key] { get { return backing[key]; } set { backing[key] = value; } }
|
|
|
|
|
|
|
|
public string MapDirectory { get { return "fake/directory/"; } }
|
|
|
|
|
|
|
|
public ICollection<string> Keys { get { return backing.Keys; } }
|
|
|
|
|
|
|
|
public ICollection<V> Values { get { return backing.Values; } }
|
|
|
|
|
|
|
|
public int Count { get { return backing.Count; } }
|
|
|
|
|
|
|
|
public bool IsReadOnly { get { return false; } }
|
|
|
|
|
2021-03-31 20:37:40 +00:00
|
|
|
IEnumerable<V> IReadOnlyPersistent<V>.Values => backing.Values;
|
2020-12-30 05:14:42 +00:00
|
|
|
|
2021-03-31 20:37:40 +00:00
|
|
|
IEnumerable<string> IReadOnlyPersistent<V>.Keys => backing.Keys;
|
2020-12-30 05:14:42 +00:00
|
|
|
|
2021-04-01 00:33:37 +00:00
|
|
|
public void AddToPersistence(string key, V value)
|
2020-12-30 05:14:42 +00:00
|
|
|
{
|
|
|
|
backing.Add(key, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Add(KeyValuePair<string, V> item)
|
|
|
|
{
|
|
|
|
backing.Add(item);
|
|
|
|
}
|
|
|
|
|
2021-04-09 02:36:08 +00:00
|
|
|
public void Add(string key, ServiceDescriptor value)
|
2020-12-30 05:14:42 +00:00
|
|
|
{
|
2021-03-31 20:37:40 +00:00
|
|
|
throw new System.NotImplementedException();
|
2020-12-30 05:14:42 +00:00
|
|
|
}
|
|
|
|
|
2021-03-31 20:37:40 +00:00
|
|
|
public void Clear()
|
2020-12-30 05:14:42 +00:00
|
|
|
{
|
2021-03-31 20:37:40 +00:00
|
|
|
backing.Clear();
|
2020-12-30 05:14:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public bool ContainsKey(string key)
|
|
|
|
{
|
|
|
|
return backing.ContainsKey(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
public IEnumerator<KeyValuePair<string, V>> GetEnumerator()
|
|
|
|
{
|
|
|
|
return backing.GetEnumerator();
|
|
|
|
}
|
|
|
|
|
|
|
|
public string GetPathForKey(string key)
|
|
|
|
{
|
|
|
|
return MapDirectory + Path.DirectorySeparatorChar + key;
|
|
|
|
}
|
|
|
|
|
2021-04-01 00:33:37 +00:00
|
|
|
public bool Delete(string key)
|
2020-12-30 05:14:42 +00:00
|
|
|
{
|
|
|
|
return backing.Remove(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool Remove(KeyValuePair<string, V> item)
|
|
|
|
{
|
|
|
|
return backing.Remove(item);
|
|
|
|
}
|
|
|
|
|
2021-04-01 00:33:37 +00:00
|
|
|
public bool TryLoadValue(string key, [MaybeNullWhen(false)] out V value)
|
2020-12-30 05:14:42 +00:00
|
|
|
{
|
|
|
|
return backing.TryGetValue(key, out value);
|
|
|
|
}
|
|
|
|
|
|
|
|
IEnumerator IEnumerable.GetEnumerator()
|
|
|
|
{
|
|
|
|
return backing.GetEnumerator();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|