This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
gameservicewarden/tests/GameServiceWarden.Core.Tests/Modules/Games/FakePersistence.cs

84 lines
2.2 KiB
C#
Raw Normal View History

using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using GameServiceWarden.Core.Games;
using GameServiceWarden.Core.Persistence;
namespace GameServiceWarden.Core.Tests.Modules
{
2021-04-01 01:29:22 +00:00
public class FakePersistence<V> : IPersistent<V>
{
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; } }
IEnumerable<V> IReadOnlyPersistent<V>.Values => backing.Values;
IEnumerable<string> IReadOnlyPersistent<V>.Keys => backing.Keys;
2021-04-01 00:33:37 +00:00
public void AddToPersistence(string key, V value)
{
backing.Add(key, value);
}
public void Add(KeyValuePair<string, V> item)
{
backing.Add(item);
}
public void Add(string key, GameServiceInfo value)
{
throw new System.NotImplementedException();
}
public void Clear()
{
backing.Clear();
}
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)
{
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)
{
return backing.TryGetValue(key, out value);
}
IEnumerator IEnumerable.GetEnumerator()
{
return backing.GetEnumerator();
}
}
}