Esempio n. 1
0
        public void TestSiteOptionMethodsInt()
        {
            Console.WriteLine("TestSiteOptionMethodsInt");
            SiteOption soInt = new SiteOption(1, "sect", "name", "0", SiteOption.SiteOptionType.Int, "desc");

            Assert.AreEqual(1, soInt.SiteId);
            Assert.AreEqual("sect", soInt.Section);
            Assert.AreEqual("name", soInt.Name);
            Assert.AreEqual(soInt.GetValueInt(), 0);
            Assert.IsFalse(soInt.IsTypeBool());
            Assert.IsTrue(soInt.IsTypeInt());

            try
            {
                soInt.GetValueBool();
            }
            catch (SiteOptionInvalidTypeException ex)
            {
                Assert.AreEqual("Value is not a bool", ex.Message);
            }

            soInt.SetValueInt(1);
            Assert.AreEqual(1, soInt.GetValueInt());
            soInt.SetValueInt(0);
            Assert.AreEqual(0, soInt.GetValueInt());
            soInt.SetValueInt(int.MaxValue);
            Assert.AreEqual(int.MaxValue, soInt.GetValueInt());
            soInt.SetValueInt(int.MinValue);
            Assert.AreEqual(int.MinValue, soInt.GetValueInt());

            try
            {
                soInt.SetValueBool(false);
            }
            catch (SiteOptionInvalidTypeException ex)
            {
                Assert.AreEqual("Type is not a bool", ex.Message);
            }
        }
Esempio n. 2
0
 private static bool CheckIntSiteOptionChanged(List<SiteOption> updatedOptions, Dictionary<string, string[]> values, SiteOption so, string key, bool optionChanged, SiteOption update)
 {
     int newValue = 0;
     if (Int32.TryParse((String)values[key].GetValue(0), out newValue))
     {
         if (update.GetValueInt() != newValue)
         {
             update.SetValueInt(newValue);
             updatedOptions.Add(update);
             optionChanged = true;
         }
     }
     return optionChanged;
 }
Esempio n. 3
0
        public void TestSiteOptionMethodsBool()
        {
            Console.WriteLine("TestSiteOptionMethodsBool");
            SiteOption soBool = new SiteOption(1, "sect", "name", "0", SiteOption.SiteOptionType.Bool, "desc");

            Assert.AreEqual(1, soBool.SiteId);
            Assert.AreEqual("sect", soBool.Section);
            Assert.AreEqual("name", soBool.Name);
            Assert.IsFalse(soBool.GetValueBool());
            Assert.IsTrue(soBool.IsTypeBool());
            Assert.IsFalse(soBool.IsTypeInt());

            try
            {
                soBool.GetValueInt();
            }
            catch (SiteOptionInvalidTypeException ex)
            {
                Assert.AreEqual("Value is not an int", ex.Message);
            }

            soBool = new SiteOption(1, "sect", "name", "1", SiteOption.SiteOptionType.Bool, "desc");

            Assert.AreEqual(1, soBool.SiteId);
            Assert.AreEqual("sect", soBool.Section);
            Assert.AreEqual("name", soBool.Name);
            Assert.IsTrue(soBool.GetValueBool());
            Assert.IsTrue(soBool.IsTypeBool());
            Assert.IsFalse(soBool.IsTypeInt());

            try
            {
                soBool.GetValueInt();
            }
            catch (SiteOptionInvalidTypeException ex)
            {
                Assert.AreEqual("Value is not an int", ex.Message);
            }

            soBool.SetValueBool(true);
            Assert.IsTrue(soBool.GetValueBool());

            soBool.SetValueBool(false);
            Assert.IsFalse(soBool.GetValueBool());

            try
            {
                soBool.SetValueInt(42);
            }
            catch (SiteOptionInvalidTypeException ex)
            {
                Assert.AreEqual("Type is not an int", ex.Message);
            }
        }
Esempio n. 4
0
        public void SetValueInt_NotIntType_ThrowsException()
        {
            string section = string.Empty;
            string name = string.Empty;
            string value = "1";
            SiteOption.SiteOptionType type = SiteOption.SiteOptionType.Bool;
            string description = string.Empty;
            SiteOption target = new SiteOption(DEFAULT_SITE_ID, section, name, value, type, description);

            try
            {
                target.SetValueInt(1);
                throw new Exception("SetValueInt should throw exception");
            }
            catch (SiteOptionInvalidTypeException)
            {
            }
        }