Beispiel #1
0
        public void TestListAdd()
        {
            Variant v = new Variant(Variant.EnumType.List);

            Assert.Throws<VariantException>(delegate { v.Add("key", new Variant()); });
            Assert.Throws<VariantException>(delegate { v.Add(new DateTime(0), new Variant()); });

            v.Add(new Variant("value1"));
            v.Add(new Variant(2.0));

            Assert.AreEqual(v.Count, 2);
            Assert.IsFalse(v.Empty);

            Assert.AreEqual(Variant.EnumType.String, v[0].Type);
            Assert.AreEqual("value1", v[0].As<string>());
            Assert.AreEqual(Variant.EnumType.Double, v[1].Type);
            Assert.AreEqual(2.0, v[1].As<double>());

            Assert.Throws<VariantException>(delegate { Variant w = v[-1]; });
            Assert.Throws<VariantException>(delegate { Variant w = v[2]; });

            v[0] = new Variant("other");
            Assert.AreEqual(v[0].As<string>(), "other");

            v.Clear();
            Assert.AreEqual(v.Count, 0);
            Assert.IsTrue(v.Empty);
        }