Exemplo n.º 1
0
        public void TestObjectMethods()
        {
            bool        v1  = true;
            SimpleValue sv1 = new SimpleValue(v1);
            int         v2  = 5;
            SimpleValue sv2 = new SimpleValue(v2);
            long        v3  = 999L;
            SimpleValue sv3 = new SimpleValue(v3);
            double      v4  = 5.257;
            SimpleValue sv4 = new SimpleValue(v4);
            decimal     v5  = decimal.MinusOne;
            SimpleValue sv5 = new SimpleValue(v5);
            string      v6  = "test";
            SimpleValue sv6 = new SimpleValue(v6);
            Binary      v7  = new Binary(new byte[] { 99, 50, 27 });
            SimpleValue sv7 = new SimpleValue(v7);
            DateTime    v8  = new DateTime(1976, 4, 19);
            SimpleValue sv8 = new SimpleValue(v8);

            //ToString
            Assert.AreEqual(v1.ToString(), sv1.ToString());
            Assert.AreEqual(v2.ToString(), sv2.ToString());
            Assert.AreEqual(v3.ToString(), sv3.ToString());
            Assert.AreEqual(v4.ToString(), sv4.ToString());
            Assert.AreEqual(v5.ToString(), sv5.ToString());
            Assert.AreEqual(v6, sv6.ToString());
            Assert.AreEqual(Convert.ToBase64String(v7.ToByteArray()), sv7.ToString());
            Assert.AreEqual(v8.ToString(), sv8.ToString());

            //Equals
            sv1.SetBoolean(false);
            sv6.SetString("False");
            Assert.IsTrue(sv1.Equals(sv6));
            Assert.IsFalse(sv1.Equals(sv7));
            Assert.IsFalse(sv1.Equals("test"));

            //GetHashCode
            Assert.AreEqual(XmlHelper.HashValue(sv6), sv6.GetHashCode());

            //Clone
            SimpleValue sv1c = (SimpleValue)sv1.Clone();
            SimpleValue sv2c = (SimpleValue)sv2.Clone();
            SimpleValue sv3c = (SimpleValue)sv3.Clone();
            SimpleValue sv4c = (SimpleValue)sv4.Clone();
            SimpleValue sv5c = (SimpleValue)sv5.Clone();
            SimpleValue sv6c = (SimpleValue)sv6.Clone();
            SimpleValue sv7c = (SimpleValue)sv7.Clone();
            SimpleValue sv8c = (SimpleValue)sv8.Clone();

            Assert.AreEqual(sv1c, sv1);
            Assert.AreNotSame(sv1c, sv1);
            Assert.AreEqual(sv2c, sv2);
            Assert.AreNotSame(sv2c, sv2);
            Assert.AreEqual(sv3c, sv3);
            Assert.AreNotSame(sv3c, sv3);
            Assert.AreEqual(sv4c, sv4);
            Assert.AreNotSame(sv4c, sv4);
            Assert.AreEqual(sv5c, sv5);
            Assert.AreNotSame(sv5c, sv5);
            Assert.AreEqual(sv6c, sv6);
            Assert.AreNotSame(sv6c, sv6);
            Assert.AreEqual(sv7c, sv7);
            Assert.AreNotSame(sv7c, sv7);
            Assert.AreEqual(sv8c, sv8);
            Assert.AreNotSame(sv8c, sv8);
            Assert.IsTrue(sv1c.IsMutable);
            Assert.IsNull(sv1c.Parent);

            sv6.SetString("newtest");
            Assert.AreNotEqual(sv6c, sv6);
        }