public static void InMemoryStorageTest() { const string expected = "I'm a unit test!"; const string expectedKey = "TEST"; IDataStorage storage = new InMemoryStorage(); storage.StoreObject("I'm different.", expectedKey); storage.StoreObject(expected, expectedKey); var actual = storage.RestoreObject <string>(expectedKey); Assert.Equal(expected, actual); Assert.Throws <ArgumentException>(() => storage.RestoreObject <object>("FAKE-KEY")); }
public static UserAccount GetUser(DiscordUser user) { if (DoesUserExist(user.GetID())) { System.Console.WriteLine("1"); SaveUsers(); System.Console.WriteLine("2"); return(_storage.RestoreObject <UserAccount>(Convert.ToString(user.GetID()))); } else { System.Console.WriteLine("3"); return(CreateNewUser(user)); } }
/// <summary> /// Update class with data from storage. /// </summary> public void Update() { var User = _storage.RestoreObject <UserAccount>(ID.ToString()); this.Points = User.Points; this.Xp = User.Xp; this.Reputation = User.Reputation; }
public void DataStorage_InMemoryStorage_OverrideTest() { const string key = "Config/TestKey"; const string firstString = "I should be overriden"; const string expected = "I should override the previous data"; IDataStorage storage = new InMemoryStorage(); storage.StoreObject(firstString, key); storage.StoreObject(expected, key); var actual = storage.RestoreObject <string>(key); Assert.Equal(expected, actual); }
public UserAccount(ulong id, IDataStorage storage) { this.ID = id; _storage = (InMemoryStorage)storage; _storage.Initialize(this, ID.ToString(), UserAccounts.UsersFolder); var User = _storage.RestoreObject <UserAccount>(ID.ToString()); if (User != null) { this.Points = User.Points; this.Xp = User.Xp; this.Reputation = User.Reputation; _storage.StoreObject(); Utilities.Log($"UserAccount [{ID}]", "User restored from storage.", LogSeverity.Verbose); } else { _storage.StoreObject(); Utilities.Log($"UserAccount [{ID}]", "New user created.", LogSeverity.Verbose); } }
public void DataStorage_InMemoryStorage_RestoreObject_MissingKeyTest() { IDataStorage storage = new InMemoryStorage(); Assert.Throws <System.ArgumentException>(() => storage.RestoreObject <string>("fake-key")); }