Exemplo n.º 1
0
        public IEnumerator TestSwapUser()
        {
            string user    = "******";
            string toStore = "hey";
            string key     = "key";

            string toStore2 = "hey2";
            string key2     = "key2";

            TestInitConditions();

            persistance.LoadDefaultUser();

            persistance.StoreValue <string>(key, toStore);
            persistance.StoreValue <string>(key2, toStore2);

            Assert.IsTrue(persistance.Contains(key), "Invalid key");
            Assert.IsTrue(persistance.Contains(key2), "Invalid key");

            Assert.IsTrue(toStore.CompareTo(persistance.GetValue <string>(key)) == 0, "Invalid store/retrieve");
            Assert.IsTrue(toStore2.CompareTo(persistance.GetValue <string>(key2)) == 0, "Invalid store/retrieve");

            persistance.LoadUser(user);

            Assert.IsFalse(persistance.Contains(key), "Invalid key");
            Assert.IsFalse(persistance.Contains(key2), "Invalid key");

            persistance.StoreValue <string>(key, toStore);
            persistance.StoreValue <string>(key2, toStore2);
            persistance.Save();

            persistance.LoadDefaultUser();
            Assert.IsFalse(persistance.Contains(key), "Invalid key");
            Assert.IsFalse(persistance.Contains(key2), "Invalid key");

            persistance = new UserPersistance(saveApp);
            persistance.LoadUser(user);

            Assert.IsTrue(persistance.Contains(key), "Invalid key");
            Assert.IsTrue(persistance.Contains(key2), "Invalid key");

            Assert.IsTrue(toStore.CompareTo(persistance.GetValue <string>(key)) == 0, "Invalid store/retrieve");
            Assert.IsTrue(toStore2.CompareTo(persistance.GetValue <string>(key2)) == 0, "Invalid store/retrieve");

            Assert.IsTrue(persistance.HasStoredData(), "Persistance has no stored data");
            Assert.IsFalse(persistance.HasUserStoredData(UserPersistance.DEFAULT_USER), "Persistance has default stored data");
            Assert.IsTrue(persistance.HasUserStoredData(user), "Persistance has no user stored data");

            yield return(null);
        }
Exemplo n.º 2
0
        public IEnumerator TestUserStoreRetrieveValue()
        {
            string user = "******";

            string toStore = "hey";
            string key     = "key";

            int    toStore2 = 25;
            string key2     = "key2";

            TestStruct toStore3 = new TestStruct(45, "asdasd");
            string     key3     = "key3";

            bool   toStore4 = true;
            string key4     = "key4";


            string     toOverride  = "Override";
            int        toOverride2 = 234;
            TestStruct toOverride3 = new TestStruct(23543, "asdasf3e");

            bool toOverride4 = false;

            TestInitConditions();

            persistance.LoadUser(user);

            persistance.StoreValue <string>(key, toStore);
            persistance.StoreValue <int>(key2, toStore2);
            persistance.StoreValue <TestStruct>(key3, toStore3);
            persistance.StoreValue <bool>(key4, toStore4);

            Assert.IsTrue(persistance.Contains(key), "Invalid key");
            Assert.IsTrue(persistance.Contains(key2), "Invalid key");
            Assert.IsTrue(persistance.Contains(key3), "Invalid key");
            Assert.IsTrue(persistance.Contains(key4), "Invalid key");

            Assert.IsFalse(persistance.HasStoredData(), "Persistance has no stored data");
            Assert.IsFalse(persistance.HasUserStoredData(UserPersistance.DEFAULT_USER), "Persistance has default stored data");
            Assert.IsFalse(persistance.HasUserStoredData(user), "Persistance has no user stored data");

            Assert.IsTrue(toStore.CompareTo(persistance.GetValue <string>(key)) == 0, "Invalid store/retrieve");
            Assert.IsTrue(toStore2 == persistance.GetValue <int>(key2), "Invalid store/retrieve");
            Assert.IsTrue(toStore3.Same(persistance.GetValue <TestStruct>(key3)), "Invalid store/retrieve");
            Assert.IsTrue(toStore4 == persistance.GetValue <bool>(key4), "Invalid store/retrieve");

            persistance.StoreValue <string>(key, toOverride);
            persistance.StoreValue <int>(key2, toOverride2);
            persistance.StoreValue <TestStruct>(key3, toOverride3);
            persistance.StoreValue <bool>(key4, toOverride4);
            persistance.Save();

            persistance = new UserPersistance(saveApp);
            persistance.LoadUser(user);

            Assert.IsTrue(toOverride.CompareTo(persistance.GetValue <string>(key)) == 0, "Invalid store/retrieve");
            Assert.IsTrue(toOverride2 == persistance.GetValue <int>(key2), "Invalid store/retrieve");
            Assert.IsTrue(toOverride3.Same(persistance.GetValue <TestStruct>(key3)), "Invalid store/retrieve");
            Assert.IsTrue(toOverride4 == persistance.GetValue <bool>(key4), "Invalid store/retrieve");

            Assert.IsTrue(persistance.HasStoredData(), "Persistance has no stored data");
            Assert.IsFalse(persistance.HasUserStoredData(UserPersistance.DEFAULT_USER), "Persistance has default stored data");
            Assert.IsTrue(persistance.HasUserStoredData(user), "Persistance has no user stored data");

            yield return(null);
        }