/// <summary> /// Test dictionary enumeration. /// </summary> /// <typeparam name="TKey">Key type of the dictionary.</typeparam> /// <typeparam name="TValue">Value type of the dictionary.</typeparam> /// <param name="dictionary">The dictionary to test.</param> /// <param name="key">Key that is present in the dictionary.</param> /// <param name="value">Value associated with the key in the dictionary.</param> private static void TestDictionaryEnumeration <TKey, TValue>(PersistentDictionary <TKey, TValue> dictionary, TKey key, TValue value) where TKey : IComparable <TKey> { var kvp = new KeyValuePair <TKey, TValue>(key, value); IEnumerable enumerator = dictionary.Where(x => true); foreach (object o in enumerator) { Assert.AreEqual(o, kvp, "Dictionary query enumeration"); } enumerator = dictionary.Keys.Where(x => true); foreach (object o in enumerator) { Assert.AreEqual(o, kvp.Key, "Dictionary query enumeration"); } foreach (KeyValuePair <TKey, TValue> o in dictionary.Where(x => true).Reverse()) { Assert.AreEqual(o, kvp, "Dictionary query enumeration"); } foreach (object o in (IEnumerable)dictionary) { Assert.AreEqual(o, kvp, "Dictionary enumeration"); } foreach (KeyValuePair <TKey, TValue> a in dictionary.Reverse()) { Assert.AreEqual(a, kvp, "Reverse dictionary enumeration"); } foreach (object o in (IEnumerable)dictionary.Keys) { Assert.AreEqual(o, key, "Key enumeration"); } foreach (TKey k in dictionary.Keys.Reverse()) { Assert.AreEqual(k, key, "Reverse key enumeration"); } foreach (TValue v in dictionary.Values.Reverse()) { Assert.AreEqual(v, value, "Value enumeration"); } foreach (TKey k in ((IDictionary <TKey, TValue>)dictionary).Keys) { Assert.AreEqual(k, key, "Key enumeration"); } foreach (TValue v in ((IDictionary <TKey, TValue>)dictionary).Values) { Assert.AreEqual(v, value, "Value enumeration"); } }