Пример #1
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);
        }
Пример #2
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);
        }
Пример #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);
        }
Пример #4
0
        public void TestForCOH2353()
        {
            LiteDictionary ld = new LiteDictionary();

            ld.Add(1, 1);
            ld.Add(2, 2);
            ld.Add(3, 3);
            ld.Add(null, 4);
            ld.Add(5, 5);
            ld.Add(6, 6);
            ld.Add(7, 7);
            ld.Remove(7);
            ld.Add(8, 8);
            ld.Add(9, 9);
            ld.Add(10, 10);

            Assert.IsTrue(ld.Contains(null));
        }
Пример #5
0
        public void ConstructorWithDictionaryTest()
        {
            Hashtable ht = new Hashtable();

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

            LiteDictionary ld = new LiteDictionary(ht);

            Assert.IsNotNull(ld);
            Assert.AreEqual(ld.Count, 3);
            Assert.IsFalse(ld.IsEmpty);

            Assert.AreEqual(ld.Keys.Count, 3);
            Assert.AreEqual(ld.Values.Count, 3);
            Assert.AreEqual(ld["key1"], ht["key1"]);
            Assert.IsTrue(ld.Contains("key2"));

            ld.Clear();
            Assert.IsTrue(ld.IsEmpty);
        }