public void TestListPreferences()
        {
            Preferences prefs = new Preferences();
            prefs.Set("p1", "p1");
            prefs.Set("p12", "p12");
            prefs.Set("P12", "P12");
            prefs.Set("P123", "P123");
            prefs.Set("o123", "o123");

            List<string> actual = new List<string>(prefs.ListPreferences().Keys);
            AssertList(actual, "p1", "p12", "P12", "P123", "o123");
        }
        public void TestFindMissingPreferences()
        {
            Preferences prefs = new Preferences();
            prefs.Set("p1", "p1");
            prefs.Set("p12", "p12");
            prefs.Set("P12", "P12");
            prefs.Set("P123", "P123");
            prefs.Set("o123", "o123");

            object value;
            bool succeed = prefs.TryGetValue("p1!", out value);

            Assert.IsFalse(succeed);
        }
        public void TestFindPreferences()
        {
            Preferences prefs = new Preferences();
            prefs.Set("p1", "p1");
            prefs.Set("p12", "p12");
            prefs.Set("P12", "P12");
            prefs.Set("P123", "P123");
            prefs.Set("o123", "o123");

            object value;
            bool succeed = prefs.TryGetValue("p1", out value);

            Assert.IsTrue(succeed);
            Assert.AreEqual("p1", value);
        }
        public void TestSaveDelayed()
        {
            Preferences prefs = new Preferences(kPreferencesPath);
            prefs.Set("key", "value");

            Preferences otherPrefs = new Preferences(kPreferencesPath);
            Assert.IsNull(otherPrefs.GetString("key"));

            TimerManager.RunUpdate(0.5f);

            otherPrefs = new Preferences(kPreferencesPath);
            Assert.AreEqual("value", otherPrefs.GetString("key"));
        }
        public void TestPrefs()
        {
            bool boolValue = true;
            bool boolValue2 = true;

            int intValue = 10;
            int intValue2 = Int32.MaxValue;
            int intValue3 = Int32.MinValue;

            float floatValue = 3.14f;
            float floatValue2 = -3.14f;
            float floatValue3 = 0.0f;
            float floatValue4 = float.NegativeInfinity;
            float floatValue5 = float.PositiveInfinity;
            float floatValue6 = float.NaN;

            double doubleValue = 6.28;
            double doubleValue2 = -6.28;
            double doubleValue3 = 0.0;
            double doubleValue4 = double.NegativeInfinity;
            double doubleValue5 = double.PositiveInfinity;
            double doubleValue6 = double.NaN;

            DateTime timeValue = new DateTime(2015, 2, 25, 16, 04, 31);

            string stringValue = "String value";
            string stringValue2 = "";
            string stringValue3 = null;

            byte[] byteArrayValue = { 1, 2, 3 };
            byte[] byteArrayValue2 = {};
            byte[] byteArrayValue3 = null;

            Dictionary<string, object> dictionaryValue = new Dictionary<string, object>();
            dictionaryValue["key1"] = "value1";
            dictionaryValue["key2"] = "value2";
            dictionaryValue["key3"] = "value3";
            Dictionary<string, object> dictionaryValue2 = new Dictionary<string, object>();
            Dictionary<string, object> dictionaryValue3 = null;

            List<object> listValue = new List<object>();
            listValue.Add("value1");
            listValue.Add("value2");
            listValue.Add("value3");
            List<object> listValue2 = new List<object>();
            List<object> listValue3 = null;

            Preferences prefs = new Preferences(kPreferencesPath);
            prefs.Set("boolValue", boolValue);
            prefs.Set("boolValue2", boolValue2);

            prefs.Set("intValue", intValue);
            prefs.Set("intValue2", intValue2);
            prefs.Set("intValue3", intValue3);

            prefs.Set("floatValue", floatValue);
            prefs.Set("floatValue2", floatValue2);
            prefs.Set("floatValue3", floatValue3);
            prefs.Set("floatValue4", floatValue4);
            prefs.Set("floatValue5", floatValue5);
            prefs.Set("floatValue6", floatValue6);

            prefs.Set("doubleValue", doubleValue);
            prefs.Set("doubleValue2", doubleValue2);
            prefs.Set("doubleValue3", doubleValue3);
            prefs.Set("doubleValue4", doubleValue4);
            prefs.Set("doubleValue5", doubleValue5);
            prefs.Set("doubleValue6", doubleValue6);

            prefs.Set("timeValue", timeValue);

            prefs.Set("stringValue", stringValue);
            prefs.Set("stringValue2", stringValue2);
            prefs.Set("stringValue3", stringValue3);

            prefs.Set("byteArrayValue", byteArrayValue);
            prefs.Set("byteArrayValue2", byteArrayValue2);
            prefs.Set("byteArrayValue3", byteArrayValue3);

            prefs.Set("dictionaryValue", dictionaryValue);
            prefs.Set("dictionaryValue2", dictionaryValue2);
            prefs.Set("dictionaryValue3", dictionaryValue3);

            prefs.Set("listValue", listValue);
            prefs.Set("listValue2", listValue2);
            prefs.Set("listValue3", listValue3);

            prefs.Save();

            prefs = new Preferences(kPreferencesPath);

            Assert.AreEqual(boolValue, prefs.GetBool("boolValue"));
            Assert.AreEqual(boolValue2, prefs.GetBool("boolValue2"));

            Assert.AreEqual(intValue, prefs.GetInt("intValue"));
            Assert.AreEqual(intValue2, prefs.GetInt("intValue2"));
            Assert.AreEqual(intValue3, prefs.GetInt("intValue3"));

            Assert.AreEqual(floatValue, prefs.GetFloat("floatValue"));
            Assert.AreEqual(floatValue2, prefs.GetFloat("floatValue2"));
            Assert.AreEqual(floatValue3, prefs.GetFloat("floatValue3"));
            Assert.AreEqual(floatValue4, prefs.GetFloat("floatValue4"));
            Assert.AreEqual(floatValue5, prefs.GetFloat("floatValue5"));
            Assert.AreEqual(floatValue6, prefs.GetFloat("floatValue6"));

            Assert.AreEqual(doubleValue, prefs.GetDouble("doubleValue"));
            Assert.AreEqual(doubleValue2, prefs.GetDouble("doubleValue2"));
            Assert.AreEqual(doubleValue3, prefs.GetDouble("doubleValue3"));
            Assert.AreEqual(doubleValue4, prefs.GetDouble("doubleValue4"));
            Assert.AreEqual(doubleValue5, prefs.GetDouble("doubleValue5"));
            Assert.AreEqual(doubleValue6, prefs.GetDouble("doubleValue6"));

            Assert.AreEqual(timeValue, prefs.GetDate("timeValue"));

            Assert.AreEqual(stringValue, prefs.GetString("stringValue"));
            Assert.AreEqual(stringValue2, prefs.GetString("stringValue2"));
            Assert.AreEqual(stringValue3, prefs.GetString("stringValue3"));

            Assert.AreEqual(byteArrayValue, prefs.GetByteArray("byteArrayValue"));
            Assert.AreEqual(byteArrayValue2, prefs.GetByteArray("byteArrayValue2"));
            Assert.AreEqual(byteArrayValue3, prefs.GetByteArray("byteArrayValue3"));

            Assert.AreEqual(dictionaryValue, prefs.GetDictionary("dictionaryValue"));
            Assert.AreEqual(dictionaryValue2, prefs.GetDictionary("dictionaryValue2"));
            Assert.AreEqual(dictionaryValue3, prefs.GetDictionary("dictionaryValue3"));

            Assert.AreEqual(listValue, prefs.GetArray("listValue"));
            Assert.AreEqual(listValue2, prefs.GetArray("listValue2"));
            Assert.AreEqual(listValue3, prefs.GetArray("listValue3"));
        }