Example #1
0
        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 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);
        }
Example #3
0
        private static UserAccount CreateNewUser(DiscordUser user)
        {
            System.Console.WriteLine($"Creating new user: {user.GetUser().Mention}");

            UserAccount acc = new UserAccount(user);

            _storage.StoreObject(acc, Convert.ToString(acc.getID()));
            SaveUsers();
            return(acc);
        }
Example #4
0
        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_HasObject_Existing()
        {
            IDataStorage storage = new InMemoryStorage();

            const string key = "Test/key";
            const int    obj = 6;

            storage.StoreObject(obj, key);

            const bool expected = true;
            var        actual   = storage.HasObject(key);

            Assert.Equal(expected, actual);
        }
Example #6
0
 /// <summary>
 /// Save to storage.
 /// </summary>
 public void Save() => _storage.StoreObject();