示例#1
0
        public void SingleLiteDictionaryTest()
        {
            LiteDictionary ld = new LiteDictionary();

            ld.Add("key", "value");

            Assert.AreEqual(ld.Count, 1);
            Assert.IsFalse(ld.IsEmpty);
            Assert.IsTrue(ld.Contains("key"));
            Assert.IsFalse(ld.Contains("dummy"));
            Assert.AreEqual(ld.Keys.Count, 1);
            Assert.AreEqual(ld.Values.Count, 1);
            Assert.AreEqual(ld["key"], "value");
            ld["key"] = "new value";
            Assert.AreEqual(ld["key"], "new value");
            foreach (object o in ld)
            {
                Assert.IsInstanceOf(typeof(DictionaryEntry), o);
            }

            object[] array = new object[1];
            ld.CopyTo(array, 0);
            Assert.AreEqual(array.Length, ld.Count);
            Assert.IsInstanceOf(typeof(DictionaryEntry), array[0]);
            Assert.AreEqual(((DictionaryEntry)array[0]).Value, ld["key"]);
            ld.Remove("key");
            Assert.AreEqual(ld.Count, 0);
        }
示例#2
0
        public void Array3LiteDictionaryTest()
        {
            LiteDictionary ld = new LiteDictionary();

            ld.Add("key1", "value1");
            ld.Add("key2", "value2");
            ld.Add("key3", "value3");

            Assert.AreEqual(ld.Count, 3);
            Assert.IsFalse(ld.IsEmpty);
            Assert.IsTrue(ld.Contains("key1"));
            Assert.IsFalse(ld.Contains("dummy"));
            Assert.AreEqual(ld.Keys.Count, 3);
            Assert.AreEqual(ld.Values.Count, 3);
            Assert.AreEqual(ld["key1"], "value1");
            ld["key1"] = "new value1";
            Assert.AreEqual(ld["key1"], "new value1");
            foreach (object o in ld)
            {
                Assert.IsInstanceOf(typeof(DictionaryEntry), o);
            }

            object[] array = new object[3];
            ld.CopyTo(array, 0);
            Assert.AreEqual(array.Length, ld.Count);
            Assert.IsInstanceOf(typeof(DictionaryEntry), array[0]);
            ld.Remove("key1");
            Assert.AreEqual(ld.Count, 2);
        }
示例#3
0
        public void OtherLiteDictionaryTest()
        {
            Hashtable ht = new Hashtable();

            for (int i = 0; i < 9; i++)
            {
                ht.Add("key" + (i + 1), "value" + (i + 1));
            }
            LiteDictionary ld = new LiteDictionary(ht);

            Assert.AreEqual(ld.Count, ht.Count);
            Assert.IsFalse(ld.IsEmpty);
            Assert.IsTrue(ld.Contains("key1"));
            Assert.IsFalse(ld.Contains("dummy"));
            Assert.AreEqual(ld.Keys.Count, ht.Keys.Count);
            Assert.AreEqual(ld.Values.Count, ht.Values.Count);
            Assert.AreEqual(ld["key1"], ht["key1"]);
            ld["key1"] = "new value1";
            Assert.AreEqual(ld["key1"], "new value1");
            foreach (object o in ld)
            {
                Assert.IsInstanceOf(typeof(DictionaryEntry), o);
            }

            object[] array = new object[9];
            ld.CopyTo(array, 0);
            Assert.AreEqual(array.Length, ld.Count);
            Assert.IsInstanceOf(typeof(DictionaryEntry), array[0]);
            ld.Remove("key1");
            Assert.AreEqual(ld.Count, 8);
        }