diff --git a/src/Core/Services/InMemoryStorageService.cs b/src/Core/Services/InMemoryStorageService.cs new file mode 100644 index 000000000..1c6ed114b --- /dev/null +++ b/src/Core/Services/InMemoryStorageService.cs @@ -0,0 +1,40 @@ +using Bit.Core.Abstractions; +using Newtonsoft.Json; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Bit.Core.Services +{ + public class InMemoryStorageService : IStorageService + { + private readonly Dictionary _dict = new Dictionary(); + + public Task GetAsync(string key) + { + if(!_dict.ContainsKey(key)) + { + return Task.FromResult(default(T)); + } + return Task.FromResult(JsonConvert.DeserializeObject(_dict[key])); + } + + public Task SaveAsync(string key, T obj) + { + if(obj == null) + { + return RemoveAsync(key); + } + _dict.Add(key, JsonConvert.SerializeObject(obj)); + return Task.FromResult(0); + } + + public Task RemoveAsync(string key) + { + if(_dict.ContainsKey(key)) + { + _dict.Remove(key); + } + return Task.FromResult(0); + } + } +}