Ejemplo n.º 1
0
        public void TestSpecialStrings()
        {
            // Empty
            this.expected[String.Empty] = this.actual[String.Empty] = String.Empty;

            // Numbers
            this.expected["1"]  = this.actual["1"] = "1";
            this.expected["11"] = this.actual["11"] = "2";
            this.expected["2"]  = this.actual["2"] = "3";

            // Punctuation
            this.expected["`"] = this.actual["`"] = "4";
            this.expected["!"] = this.actual["!"] = "5";
            this.expected[" "] = this.actual[" "] = "6";

            // Unicode
            this.expected["字会意"]    = this.actual["字会意"] = "字会意";
            this.expected["한글"]     = this.actual["한글"] = "한글";
            this.expected["?字3한会X"] = this.actual["?字3한会X"] = "xyzzy";
            DictionaryAssert.AreEqual(this.expected, this.actual);
        }
        public void TestCloseAndDelete()
        {
            var rand = new Random();

            for (int i = 0; i < 64; ++i)
            {
                string k = rand.NextDouble().ToString();
                string v = rand.Next().ToString();
                this.expected.Add(k, v);
                this.actual.Add(k, v);
            }

            this.actual.Dispose();
            PersistentDictionaryFile.DeleteFiles(DictionaryLocation);

            // Deleting the files clears the dictionary
            this.expected.Clear();

            this.actual = new PersistentDictionary <string, string>(DictionaryLocation);
            DictionaryAssert.AreEqual(this.expected, this.actual);
        }
        /// <summary>
        /// Create and modify a generic dictionary.
        /// </summary>
        /// <typeparam name="TKey">The key type for the dictionary.</typeparam>
        /// <typeparam name="TValue">The value type for the dictionary.</typeparam>
        private static void TestNullableGenericDictionary <TKey, TValue>() where TKey : IComparable <TKey> where TValue : struct
        {
            // Test the version with a nullable value. Use both null and non-null values.
            using (var dictionary = new PersistentDictionary <TKey, TValue?>(DictionaryPath))
            {
                RunDictionaryTests(dictionary, default(TKey), default(TValue));
                dictionary.Clear();
                RunDictionaryTests(dictionary, default(TKey), default(TValue?));
            }

            PersistentDictionaryFile.DeleteFiles(DictionaryPath);

            using (var dictionary = new PersistentDictionary <TKey, TValue>(DictionaryPath))
            {
                TKey   key   = default(TKey);
                TValue value = default(TValue);
                RunDictionaryTests(dictionary, key, value);
            }

            // Reopen the database
            Dictionary <TKey, TValue> temp;

            using (var dictionary = new PersistentDictionary <TKey, TValue>(DictionaryPath))
            {
                temp = new Dictionary <TKey, TValue>(dictionary);
            }

            // Delete the database
            Assert.IsTrue(PersistentDictionaryFile.Exists(DictionaryPath), "Dictionary should exist");
            PersistentDictionaryFile.DeleteFiles(DictionaryPath);
            Assert.IsFalse(PersistentDictionaryFile.Exists(DictionaryPath), "Dictionary should have been deleted");

            // Recreate the database
            using (var dictionary = new PersistentDictionary <TKey, TValue>(temp, DictionaryPath))
            {
                DictionaryAssert.AreEqual(temp, dictionary);
            }

            PersistentDictionaryFile.DeleteFiles(DictionaryPath);
        }
        public void TestInsertPreservesCaseOfFirstItem()
        {
            this.expected["MixedCase"] = this.actual["MixedCase"] = "MixedCase";
            this.expected["mixedcase"] = this.actual["mixedcase"] = "lower";

            Assert.IsTrue(this.expected.ContainsKey("MixedCase"));
            Assert.IsTrue(this.expected.ContainsKey("mixedcase"));
            Assert.IsTrue(this.actual.ContainsKey("MixedCase"));
            Assert.IsTrue(this.actual.ContainsKey("mixedcase"));

            var expectedKeys = this.actual.Keys;
            var actualKeys   = this.expected.Keys;

            Assert.IsTrue(actualKeys.Any(x => { return(string.Equals(x, "MixedCase")); }));
            Assert.IsFalse(actualKeys.Any(x => { return(string.Equals(x, "mixedcase")); }));
            //// Strange, I get a compile error for the regular Dictionary.
////            Assert.IsTrue(expectedKeys.Any(x => { return string.Equals(x, "MixedCase"); }));
////            Assert.IsTrue(expectedKeys.Any(x => { return string.Equals(x, "mixedcase"); }));

            DictionaryAssert.AreEqual(this.expected, this.actual);
            Assert.AreEqual("lower", this.expected["mIxEdCaSe"]);
        }
        public void TestAddOfDuplicateWithDifferentCaseShouldThrow()
        {
            this.expected["new"] = this.actual["new"] = "1";
            try
            {
                this.expected.Add("NEW", "never!!!");
                Assert.Fail("Inserting a duplicate key should have thrown ArgumentException.");
            }
            catch (ArgumentException)
            {
            }

            try
            {
                this.actual.Add("NEW", "never!!!");
                Assert.Fail("Inserting a duplicate key should have thrown ArgumentException.");
            }
            catch (ArgumentException)
            {
            }

            DictionaryAssert.AreEqual(this.expected, this.actual);
        }
 public void TestReplace()
 {
     this.expected["foo"] = this.actual["foo"] = "1";
     this.expected["foo"] = this.actual["foo"] = "2";
     DictionaryAssert.AreSortedAndEqual(this.expected, this.actual);
 }
 public void TestEmptyDictionary()
 {
     DictionaryAssert.AreSortedAndEqual(this.expected, this.actual);
 }
 public void TestNullValue()
 {
     this.expected["a"] = this.actual["a"] = null;
     DictionaryAssert.AreSortedAndEqual(this.expected, this.actual);
 }
 public void TestClearEmptyDictionary()
 {
     this.expected.Clear();
     this.actual.Clear();
     DictionaryAssert.AreSortedAndEqual(this.expected, this.actual);
 }
Ejemplo n.º 10
0
 public void TestInsert()
 {
     this.expected["foo"] = this.actual["foo"] = "1";
     DictionaryAssert.AreEqual(this.expected, this.actual);
 }
 public void TestReplaceWithDifferentCaseOfKey()
 {
     this.expected["foo"] = this.actual["foo"] = "1";
     this.expected["fOo"] = this.actual["FOO"] = "2";
     DictionaryAssert.AreEqual(this.expected, this.actual);
 }