コード例 #1
0
ファイル: SiteOptionTests.cs プロジェクト: rocketeerbkw/DNA
        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
ファイル: SiteOptionTest.cs プロジェクト: rocketeerbkw/DNA
 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
ファイル: SiteOptionTests.cs プロジェクト: rocketeerbkw/DNA
        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
ファイル: SiteOptionTests.cs プロジェクト: rocketeerbkw/DNA
        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
ファイル: SiteOptionTests.cs プロジェクト: rocketeerbkw/DNA
        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
ファイル: SiteOption.cs プロジェクト: rocketeerbkw/DNA
 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
ファイル: SiteOptionTest.cs プロジェクト: rocketeerbkw/DNA
 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
ファイル: SiteOption.cs プロジェクト: rocketeerbkw/DNA
        /// <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
ファイル: SiteOptionTests.cs プロジェクト: rocketeerbkw/DNA
        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
ファイル: SiteOptionTest.cs プロジェクト: rocketeerbkw/DNA
 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
ファイル: SiteOptionTest.cs プロジェクト: rocketeerbkw/DNA
        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
ファイル: SiteOptionTest.cs プロジェクト: rocketeerbkw/DNA
        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
ファイル: SiteOptionTest.cs プロジェクト: rocketeerbkw/DNA
        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
ファイル: SiteOptionTest.cs プロジェクト: rocketeerbkw/DNA
        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
ファイル: SiteOptionTest.cs プロジェクト: rocketeerbkw/DNA
        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
ファイル: SiteOptionTest.cs プロジェクト: rocketeerbkw/DNA
 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
ファイル: SiteOptionTest.cs プロジェクト: rocketeerbkw/DNA
        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
ファイル: SiteOptionTest.cs プロジェクト: rocketeerbkw/DNA
 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
ファイル: SiteOptionTest.cs プロジェクト: rocketeerbkw/DNA
 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
ファイル: SiteOptionTest.cs プロジェクト: rocketeerbkw/DNA
 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
ファイル: SiteOptionTest.cs プロジェクト: rocketeerbkw/DNA
        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)
            {
            }
        }