Example #1
0
        public void EntryClassTest()
        {
            // Test the default ctor
            Entry e = new Entry();

            Assert.IsNotNull(e);

            // Test the two param ctor
            Entry ee = new Entry("sectionName", "property");

            Assert.IsNotNull(ee);
            Assert.AreEqual("sectionName", ee.Section);
            Assert.AreEqual("property", ee.Property);
            Assert.IsNull(ee.Value);

            // Test the three param ctor
            Entry eee = new Entry("sectionName", "property", "value");

            Assert.IsNotNull(eee);
            Assert.AreEqual("sectionName", eee.Section);
            Assert.AreEqual("property", eee.Property);
            Assert.AreEqual("value", eee.Value);

            // Test that a Value can be returned as an Integer
            Entry intVal = new Entry("section", "property", "1");

            Assert.IsNotNull(intVal);
            int  value   = 0;
            bool success = intVal.AsInteger(out value);

            Assert.AreEqual(1, value);
            Assert.IsTrue(success);

            // Test that a string value will fail to return as an Integer
            int  badValue = 999;
            bool failure  = eee.AsInteger(out badValue);

            Assert.IsFalse(failure);
            // The out param gets set to 0 on failing.
            Assert.AreEqual(0, badValue);

            // Test that a Value can be returned as a Boolean.
            Entry eBool = new Entry("section", "property", "true");

            Assert.IsNotNull(eBool);
            bool val;
            bool bSuccess = eBool.AsBoolean(out val);

            Assert.IsTrue(bSuccess);
            Assert.AreEqual(true, val);

            Entry fBool = new Entry("section", "property", "False");

            Assert.IsNotNull(fBool);
            bool val2;
            bool fSuccess = fBool.AsBoolean(out val2);

            Assert.IsTrue(fSuccess);
            Assert.AreEqual(false, val2);

            // Test that a string will fail to return as a Boolean
            bool badVal;
            bool boolFailure = eee.AsBoolean(out badVal);

            Assert.IsFalse(boolFailure);
            // The out param gets set to false on failing.
            Assert.AreEqual(false, badVal);
        }