Exemplo 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);
            }
        }
Exemplo n.º 2
0
 private static bool CheckBoolSiteOptionChanged(List<SiteOption> updatedOptions, Dictionary<string, string[]> values, SiteOption so, string key, bool optionChanged, SiteOption update)
 {
     bool newValue = (String)values[key].GetValue(0) == "1";
     if (update.GetValueBool() != newValue)
     {
         update.SetValueBool(newValue);
         updatedOptions.Add(update);
         optionChanged = true;
     }
     return optionChanged;
 }
Exemplo 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);
            }
        }
Exemplo n.º 4
0
        public void SetValueBool_NotBoolType_ThrowsException()
        {
            string section = string.Empty;
            string name = string.Empty;
            string value = "1";
            SiteOption.SiteOptionType type = SiteOption.SiteOptionType.Int;
            string description = string.Empty;
            SiteOption target = new SiteOption(DEFAULT_SITE_ID, section, name, value, type, description);

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