Beispiel #1
0
        public void TestRandomValues()
        {
            var tddHandler = new TDDHandler();

            var settings1_1 = new DynamicSettings1();
            var plugin1_1   = settings1_1.GetObjectPlugin <ILocalDynamicSettingsPlugin>();

            var dsn1 = "name1";
            var dsn2 = "name2";

            var rand          = new MyRandom();
            var randValue     = rand.NextDouble();
            var randEnumValue = (EEnumValues)rand.Next((int)EEnumValues.Ten);

            plugin1_1.SetSetting(dsn1, randValue);
            plugin1_1.SetSetting(dsn2, randEnumValue);

            var storedValue1 = plugin1_1.GetSetting <double>(dsn1);

            Assert.AreEqual(randValue, storedValue1);

            var storedEnum1 = plugin1_1.GetSetting <EEnumValues>(dsn2);

            Assert.AreEqual(randEnumValue, storedEnum1);

            plugin1_1.SaveSettings();

            var settings1_2 = new DynamicSettings1();
            var plugin1_2   = settings1_2.GetObjectPlugin <ILocalDynamicSettingsPlugin>();

            plugin1_2.LoadSettings();

            var storedValue2 = plugin1_2.GetSetting <double>(dsn1);

            Assert.AreEqual(randValue, storedValue2);

            var storedEnum2 = plugin1_2.GetSetting <EEnumValues>(dsn2);

            Assert.AreEqual(randEnumValue, storedEnum2);

            tddHandler.CheckErrors();
        }
        public void Test()
        {
            var tddHandler = new TDDHandler();

            CustomObjectSettings.FooClassInstance       = new FooClass();
            CustomObjectSettings.SecureFooClassInstance = new FooClass();

            Random rand = new MyRandom();

            Int32 fooValue       = rand.NextInt32();
            Int32 secureFooValue = rand.NextInt32();

            CustomObjectSettings.FooClassInstance.IntValue       = fooValue;
            CustomObjectSettings.SecureFooClassInstance.IntValue = secureFooValue;

            FooEnum fooEnumValue       = (FooEnum)rand.Next((Int32)FooEnum.One, (Int32)FooEnum.Ten);
            FooEnum secureFooEnumValue = (FooEnum)rand.Next((Int32)FooEnum.One, (Int32)FooEnum.Ten);

            CustomObjectSettings.FooEnumValue       = fooEnumValue;
            CustomObjectSettings.SecureFooEnumValue = secureFooEnumValue;
            CustomObjectSettings.SaveSettings();

            CustomObjectSettings.FooClassInstance       = null;
            CustomObjectSettings.SecureFooClassInstance = null;
            CustomObjectSettings.FooEnumValue           = FooEnum.Zero;
            CustomObjectSettings.SecureFooEnumValue     = FooEnum.Zero;

            CustomObjectSettings.LoadSettings();

            Assert.IsNotNull(CustomObjectSettings.FooClassInstance);
            Assert.IsTrue(typeof(FooClass) == CustomObjectSettings.FooClassInstance.GetType());
            Assert.AreEqual(CustomObjectSettings.FooClassInstance.IntValue, fooValue);
            Assert.AreEqual(CustomObjectSettings.FooEnumValue, fooEnumValue);

            Assert.IsNotNull(CustomObjectSettings.SecureFooClassInstance);
            Assert.IsTrue(typeof(FooClass) == CustomObjectSettings.SecureFooClassInstance.GetType());
            Assert.AreEqual(CustomObjectSettings.SecureFooClassInstance.IntValue, secureFooValue);
            Assert.AreEqual(CustomObjectSettings.SecureFooEnumValue, secureFooEnumValue);

            tddHandler.CheckErrors();
        }
Beispiel #3
0
        public void TestDynamicSettingsCustomOrder()
        {
            var tddHandler = new TDDHandler();

            //==============================

            var settings1_1 = new DynamicSettings1();
            var plugin1_1   = settings1_1.GetObjectPlugin <ILocalDynamicSettingsPlugin>();

            const int    settingsCount     = 50;
            const string settingNameFormat = "setting{0}";

            var settingsOrder = new List <string>();

            for (int i = 0; i < settingsCount; i++)
            {
                var settingName = String.Format(settingNameFormat, i);
                plugin1_1.SetSetting(settingName, i);

                settingsOrder.Add(settingName);
            }

            plugin1_1.SaveSettings();

            var settings1_2 = new DynamicSettings1();
            var plugin1_2   = settings1_2.GetObjectPlugin <ILocalDynamicSettingsPlugin>();

            plugin1_2.LoadSettings();

            // set custom filter

            settingsOrder.Shuffle();
            plugin1_2.SetSettingsOrder(settingsOrder);

            int index = 0;

            foreach (var ds in plugin1_2)
            {
                Assert.AreEqual(settingsOrder[index], ds);
                index++;
            }

            //==============================

            // save and restore settings in the new instance
            // check settings custom order

            settingsOrder.Shuffle();
            plugin1_2.SetSettingsOrder(settingsOrder);

            plugin1_2.SaveSettings();

            var settings1_3 = new DynamicSettings1();
            var plugin1_3   = settings1_3.GetObjectPlugin <ILocalDynamicSettingsPlugin>();

            plugin1_3.LoadSettings();

            // compare with custom order
            CompareDynamicSettings(plugin1_2, plugin1_3);

            plugin1_2.SetSettingsOrder(null);
            plugin1_3.SetSettingsOrder(null);

            // compare with default order
            CompareDynamicSettings(plugin1_2, plugin1_3);

            //==============================

            // set empty custom filter

            plugin1_2.SetSettingsOrder(new List <string>());
            Assert.AreEqual(0, plugin1_2.Count);

            //==============================

            // reset custom filter

            plugin1_2.SetSettingsOrder(null);

            index = 0;
            foreach (var ds in plugin1_2)
            {
                Assert.AreEqual(String.Format(settingNameFormat, index), ds);
                index++;
            }

            //==============================

            // add new dynamic setting when custom filter was set

            const string newDynamicSettingName = "new";

            plugin1_2.SetSettingsOrder(settingsOrder);
            plugin1_2.SetSetting(newDynamicSettingName, 1);

            index = 0;
            foreach (var ds in plugin1_2)
            {
                if (index < settingsOrder.Count)
                {
                    Assert.AreEqual(settingsOrder[index], ds);
                    index++;
                }
                else
                {
                    Assert.AreEqual(newDynamicSettingName, ds);
                }
            }

            //==============================

            // delete existing dynamic setting when custom filter was set

            var rng = new MyRandom();
            var randomTargetIndex = rng.Next(settingsCount);
            var targetSettingName = String.Format(settingNameFormat, randomTargetIndex);

            plugin1_2.SetSettingsOrder(settingsOrder);
            var preCount = plugin1_2.Count;

            plugin1_2.DeleteSetting(targetSettingName);
            settingsOrder.Remove(targetSettingName);

            Assert.AreEqual(preCount - 1, plugin1_2.Count);
            Assert.AreEqual(settingsOrder.Count, plugin1_2.Count);

            index = 0;
            foreach (var ds in plugin1_2)
            {
                Assert.AreEqual(settingsOrder[index], ds);
                index++;
            }

            tddHandler.CheckErrors();
        }