Exemplo n.º 1
0
        public void TestDefaultValueAccessors()
        {
            SimpleValue sv = new SimpleValue();

            Assert.IsNull(sv.Value);
            Assert.AreEqual(true, sv.GetBoolean(true));
            Assert.AreEqual(5, sv.GetInt(5));
            Assert.AreEqual(long.MaxValue, sv.GetLong(long.MaxValue));
            Assert.AreEqual("test", sv.GetString("test"));
            Assert.AreEqual(double.MaxValue, sv.GetDouble(double.MaxValue));
            Assert.AreEqual(decimal.MinValue, sv.GetDecimal(decimal.MinValue));
            Assert.AreEqual(Binary.NO_BINARY, sv.GetBinary(Binary.NO_BINARY));
            DateTime dt = DateTime.Now;

            Assert.AreEqual(dt, sv.GetDateTime(dt));

            sv.SetBoolean(false);
            Assert.AreNotEqual(true, sv.GetBoolean(true));
            sv.SetInt(100);
            Assert.AreNotEqual(5, sv.GetInt(5));
            sv.SetLong(100L);
            Assert.AreNotEqual((object)long.MaxValue, (object)sv.GetLong(long.MaxValue));
            sv.SetString("testing");
            Assert.AreNotEqual("test", sv.GetString("test"));
            sv.SetDouble(100D);
            Assert.AreNotEqual(double.MaxValue, sv.GetDouble(double.MaxValue));
            sv.SetDecimal(decimal.MinusOne);
            Assert.AreNotEqual(decimal.MinValue, sv.GetDecimal(decimal.MinValue));
            sv.SetBinary(new Binary(new byte[] { 3, 4, 5 }));
            Assert.AreNotEqual(Binary.NO_BINARY, sv.GetBinary(Binary.NO_BINARY));
            sv.SetDateTime(DateTime.Today);
            Assert.AreNotEqual(dt, sv.GetDateTime(dt));
        }
Exemplo n.º 2
0
        public void TestProperties()
        {
            SimpleValue sv = new SimpleValue("value", false, false);

            Assert.IsFalse(sv.IsAttribute);
            Assert.IsTrue(sv.IsContent);
            Assert.IsFalse(sv.IsEmpty);
            Assert.IsNull(sv.Parent);

            sv.SetString(null);
            Assert.IsTrue(sv.IsEmpty);
            sv.SetString("");
            Assert.IsTrue(sv.IsEmpty);
            sv.SetBinary(Binary.NO_BINARY);
            Assert.IsTrue(sv.IsEmpty);

            SimpleElement element = new SimpleElement();

            sv.Parent = element;
            Assert.IsNotNull(sv.Parent);

            Exception e = null;

            try
            {
                sv.Parent = new SimpleElement(); //already set
            }
            catch (Exception ex)
            {
                e = ex;
            }
            Assert.IsNotNull(e);
            Assert.IsInstanceOf(typeof(InvalidOperationException), e);
            e = null;
            try
            {
                sv.Parent = null; //cannot be null
            }
            catch (Exception ex)
            {
                e = ex;
            }
            Assert.IsNotNull(e);
            Assert.IsInstanceOf(typeof(ArgumentException), e);
            e = null;
            IXmlValue immutable = element.GetSafeAttribute("attr");

            Assert.IsNotNull(immutable);
            Assert.IsFalse(immutable.IsMutable);
            try
            {
                immutable.Parent = element;
            }
            catch (Exception ex)
            {
                e = ex;
            }
            Assert.IsNotNull(e);
            Assert.IsInstanceOf(typeof(InvalidOperationException), e);

            sv = new SimpleValue("value", false, false);
            Assert.IsTrue(sv.IsMutable);
            sv.Parent = element.GetSafeElement("test");
            Assert.IsFalse(sv.IsMutable);
        }