Beispiel #1
0
 public void VerifyCountThrowsExceptionWhenExpressionIsNull()
 {
     using (var persistentDictionary = new PersistentDictionary <Guid, Guid>(DictionaryLocation))
     {
         persistentDictionary.Count(null);
     }
 }
Beispiel #2
0
        /// <summary>
        /// Test LINQ queries on the dictionary.
        /// </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 TestDictionaryLinq <TKey, TValue>(PersistentDictionary <TKey, TValue> dictionary, TKey key, TValue value)
            where TKey : IComparable <TKey>
        {
            var kvp = new KeyValuePair <TKey, TValue>(key, value);

            Assert.IsTrue(dictionary.Any(x => 0 == x.Key.CompareTo(key)), "Any == should have found {0}", key);
            Assert.IsTrue(dictionary.Any(x => 0 <= x.Key.CompareTo(key)), "Any <= should have found {0}", key);
            Assert.IsTrue(dictionary.Any(x => 0 >= x.Key.CompareTo(key)), "Any >= should have found {0}", key);
            Assert.IsTrue(dictionary.Any(x => !(0 != x.Key.CompareTo(key))), "Any !(!=) should have found {0}", key);

            var query = from x in dictionary where x.Key.CompareTo(key) == 0 select x.Value;

            Assert.AreEqual(value, query.Single(), "Where == failed");
            query = from x in dictionary where x.Key.CompareTo(key) == 0 select x.Value;
            Assert.AreEqual(value, query.Reverse().Single(), "Where == failed (reversed)");
            query = from x in dictionary where x.Key.CompareTo(key) <= 0 select x.Value;
            Assert.AreEqual(value, query.Single(), "Where <= failed");
            query = from x in dictionary where x.Key.CompareTo(key) >= 0 select x.Value;
            Assert.AreEqual(value, query.Single(), "Where >= failed");
            query = from x in dictionary where !(x.Key.CompareTo(key) != 0) select x.Value;
            Assert.AreEqual(value, query.Single(), "Where !(!=) failed");
            Assert.AreEqual(kvp, dictionary.Where(x => x.Key.CompareTo(key) >= 0).Reverse().Last(), "Where.Reverse.Last failed");

            Assert.AreEqual(kvp, dictionary.First(), "First");
            Assert.AreEqual(kvp, dictionary.First(x => x.Key.CompareTo(key) == 0), "First");
            Assert.AreEqual(kvp, dictionary.FirstOrDefault(), "FirstOrDefault");
            Assert.AreEqual(kvp, dictionary.FirstOrDefault(x => x.Key.CompareTo(key) == 0), "FirstOrDefault");
            Assert.AreEqual(kvp, dictionary.Last(), "Last");
            Assert.AreEqual(kvp, dictionary.Last(x => x.Key.CompareTo(key) == 0), "Last");
            Assert.AreEqual(kvp, dictionary.LastOrDefault(), "LastOrDefault");
            Assert.AreEqual(kvp, dictionary.LastOrDefault(x => x.Key.CompareTo(key) == 0), "LastOrDefault");

            Assert.AreEqual(1, dictionary.Count(x => x.Key.CompareTo(key) <= 0), "Count failed");
        }