예제 #1
0
        public void TestSiteOptionConstructor()
        {
            Console.WriteLine("TestSiteOptionConstructor");
            SiteOption so;

            so = new SiteOption(1, "hello", "there", "0", SiteOption.SiteOptionType.Bool, "bool");
            so = new SiteOption(1, "hello", "there", "1", SiteOption.SiteOptionType.Bool, "bool");

            so = new SiteOption(1, "hello", "there", int.MinValue.ToString(), SiteOption.SiteOptionType.Int, "int");
            so = new SiteOption(1, "hello", "there", "0", SiteOption.SiteOptionType.Int, "int");
            so = new SiteOption(1, "hello", "there", "1", SiteOption.SiteOptionType.Int, "int");
            so = new SiteOption(1, "hello", "there", int.MaxValue.ToString(), SiteOption.SiteOptionType.Int, "int");

            TestSiteOptionInvalidBool("");
            TestSiteOptionInvalidBool("-1");
            TestSiteOptionInvalidBool("2");
            TestSiteOptionInvalidBool("e");

            Int64 i64 = int.MaxValue;
            i64 += 1;

            TestSiteOptionInvalidInt("");
            TestSiteOptionInvalidInt("agh");
            TestSiteOptionInvalidInt("1.0");
            TestSiteOptionInvalidInt("7E09");

            Int64 overflowInt1 = int.MaxValue;
            overflowInt1 += 1;
            Int64 overflowInt2 = int.MinValue;
            overflowInt2 -= 1;

            TestSiteOptionInvalidInt(overflowInt1.ToString());
            TestSiteOptionInvalidInt(overflowInt2.ToString());
        }
예제 #2
0
 public void SiteOptionConstructorTest()
 {
     string section = string.Empty;
     string name = string.Empty;
     string value = "1";
     SiteOption.SiteOptionType type = SiteOption.SiteOptionType.Int;
     string description = string.Empty;
     var target = new SiteOption(DEFAULT_SITE_ID, section, name, value, type, description);
     Assert.AreEqual(type, target.OptionType);
 }
예제 #3
0
        private void TestSiteOptionInvalidInt(string value)
        {
            try
            {
                SiteOption so = new SiteOption(1, "eh up", "chuck", value, SiteOption.SiteOptionType.Int, "int");
            }
            catch (OverflowException)
            {
                return;
            }
            catch (FormatException)
            {
                return;
            }

            Assert.Fail("TestSiteOptionInvalidInt() should always throw an exception");
        }
예제 #4
0
        private void TestSiteOptionInvalidBool(string value)
        {
            try
            {
                SiteOption so = new SiteOption(1, "eh up", "chuck", value, SiteOption.SiteOptionType.Bool, "bool");
            }
            catch (SiteOptionInvalidTypeException ex)
            {
                Assert.AreEqual("Value is not a bool", ex.Message);
                return;
            }
            catch (FormatException)
            {
                return;
            }

            Assert.Fail("TestSiteOptionInvalidBool() should always throw an exception");
        }
예제 #5
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);
            }
        }
예제 #6
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;
 }
예제 #7
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;
 }
예제 #8
0
 public static void RemoveSiteOptionFromSite(SiteOption so, int siteID, IDnaDataReaderCreator readerCreator)
 {
     using (IDnaDataReader reader = readerCreator.CreateDnaDataReader("deletesiteoption"))
     {
         reader.AddParameter("siteid", siteID);
         reader.AddParameter("section", so.Section);
         reader.AddParameter("name", so.Name);
         reader.Execute2();
     }
 }
예제 #9
0
 private bool CheckAndAddOptionForUpdate(List<SiteOption> updatedOptions, Dictionary<string, string[]> values, SiteOption so, string key)
 {
     bool optionChanged = false;
     SiteOption update = SiteOption.CreateFromDefault(so, selectedSite.SiteID);
     if (update.IsTypeBool())
     {
         optionChanged = CheckBoolSiteOptionChanged(updatedOptions, values, so, key, optionChanged, update);
     }
     else if (update.IsTypeInt())
     {
         optionChanged = CheckIntSiteOptionChanged(updatedOptions, values, so, key, optionChanged, update);
     }
     else if (update.IsTypeString())
     {
         optionChanged = CheckStringSiteOptionChanged(updatedOptions, values, so, key, optionChanged, update);
     }
     return optionChanged;
 }
예제 #10
0
 public void GetRawValue_ValidInt_ReturnsIntString()
 {
     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);
     Assert.AreEqual(value, target.GetRawValue());
 }
예제 #11
0
        /// <summary>
        /// Creates a new SiteOption with exactly the same values as the default on passed in,
        /// except the site id is set to the value you pass in separately
        /// </summary>
        /// <param name="defaultSiteOption">The one to copy</param>
        /// <param name="siteId">The site id to use</param>
        /// <returns></returns>
        public static SiteOption CreateFromDefault(SiteOption defaultSiteOption, int siteId)
        {
            var newSiteOption = new SiteOption(
                siteId,
                defaultSiteOption.Section,
                defaultSiteOption.Name,
                defaultSiteOption.GetRawValue(),
                defaultSiteOption.OptionType,
                defaultSiteOption.Description);

            return newSiteOption;
        }
예제 #12
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);
            }
        }
예제 #13
0
 public void GetValueInt_InvalidInt_ThrowsException()
 {
     string section = string.Empty;
     string name = string.Empty;
     string value = "0";
     SiteOption.SiteOptionType type = SiteOption.SiteOptionType.Bool;
     string description = string.Empty;
     SiteOption target = new SiteOption(DEFAULT_SITE_ID, section, name, value, type, description);
     bool actual = target.GetValueBool();
     Assert.IsFalse(actual);
     try
     {
         target.GetValueInt();
         throw new Exception("GetValueInt should throw exception");
     }
     catch (SiteOptionInvalidTypeException)
     {
     }
 }
예제 #14
0
        public void ShouldRemoveSiteOptionForSite()
        {
            IDnaDataReaderCreator readerCreator;
            SetupDataBaseMockedDataReaderCreator(out readerCreator);

            string section = "General";
            string name = "IsURLFiltered";
            string description = "Set if this site is to be url filtered";
            int siteID = 1;
            
            // Check the option exists first
            GetValueForGivenSiteOptionAssertFail(readerCreator, section, name, siteID, true);
            
            SiteOption siteOption = new SiteOption(siteID, section, name, "0", SiteOption.SiteOptionType.Bool, description);
            SiteOption.RemoveSiteOptionFromSite(siteOption, siteID, readerCreator);
            GetValueForTheSpecificSiteSiteOptionAssertFail(readerCreator, section, name, siteID, false);
        }
예제 #15
0
        private void UpdateBooleanSiteOption(int siteID, string section, string name, string value, string description)
        {
            IDnaDataReaderCreator readerCreator;
            SetupDataBaseMockedDataReaderCreator(out readerCreator);

            SiteOption updatedSiteOption = new SiteOption(siteID, section, name, value, SiteOption.SiteOptionType.Bool, description);
            List<SiteOption> updatedSiteoptions = new List<SiteOption>();
            updatedSiteoptions.Add(updatedSiteOption);
            SiteOption.UpdateSiteOptions(updatedSiteoptions, readerCreator);
        }
예제 #16
0
        public void ShouldUpdateSiteOptionsWithValidUpdateOption()
        {
            IDnaDataReaderCreator readerCreator;
            SetupDataBaseMockedDataReaderCreator(out readerCreator);

            string section = "General";
            string name = "SiteIsPrivate";
            string description = "If true, this site's content won't get pulled out on lists in any other site";
            int siteID = 1;
            int changeToValue = GetValueForGivenSiteOptionAssertFail(readerCreator, section, name, siteID, true) == 1 ? 0 : 1;

            SiteOption siteOption = new SiteOption(siteID, section, name, changeToValue.ToString(), SiteOption.SiteOptionType.Bool, description);
            List<SiteOption> updatedSiteoptions = new List<SiteOption>();
            updatedSiteoptions.Add(siteOption);

            SiteOption.UpdateSiteOptions(updatedSiteoptions, readerCreator);
            int storedValue = GetValueForGivenSiteOptionAssertFail(readerCreator, section, name, siteID, true);

            Assert.AreEqual(changeToValue, storedValue);
        }
예제 #17
0
        public void GetValueString_InvalidString_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.GetValueString();
                throw new Exception("GetValueString should throw exception");
            }
            catch (SiteOptionInvalidTypeException)
            {
            }
        }
예제 #18
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)
            {
            }
        }
예제 #19
0
 public void GetValueString_ValidString_ReturnsString()
 {
     string section = string.Empty;
     string name = string.Empty;
     string value = "1";
     SiteOption.SiteOptionType type = SiteOption.SiteOptionType.String;
     string description = string.Empty;
     SiteOption target = new SiteOption(DEFAULT_SITE_ID, section, name, value, type, description);
     string expected = "1";
     string actual = target.GetValueString();
     Assert.AreEqual(expected, actual);
 }
예제 #20
0
        public void GetValueBool_InvalidBool_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);
            int expected = 1;
            int actual = target.GetValueInt();
            Assert.AreEqual(expected, actual);

            try
            {
                target.GetValueBool();
                throw new Exception("GetValueBool should throw exception");
            }
            catch (SiteOptionInvalidTypeException)
            {
            }
        }
예제 #21
0
 public void GetRawValue_ValidString_ReturnsString()
 {
     int siteId = 0;
     string section = string.Empty;
     string name = string.Empty;
     string value = "1";
     SiteOption.SiteOptionType type = SiteOption.SiteOptionType.String;
     string description = string.Empty;
     SiteOption target = new SiteOption(siteId, section, name, value, type, description);
     Assert.AreEqual(value, target.GetRawValue());
 }
예제 #22
0
 public void GetValueBool_ValidBool_ReturnsBool()
 {
     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);
     bool actual = target.GetValueBool();
     Assert.IsTrue(actual);
 }
예제 #23
0
 public void GetValueInt_ValidInt_ReturnsInt()
 {
     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); 
     int expected = 1;
     int actual = target.GetValueInt();
     Assert.AreEqual(expected, actual);
 }
예제 #24
0
        public void SetValueInt_NotIntType_ThrowsException()
        {
            int siteId = 0;
            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(siteId, section, name, value, type, description);

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