public static void PerformActionOnAllHashtableWrappers(Hashtable hashtable, Action<Hashtable> action) { // Synchronized returns a slightly different version of Hashtable Hashtable[] hashtableTypes = { (Hashtable)hashtable.Clone(), Hashtable.Synchronized(hashtable) }; foreach (Hashtable hashtableType in hashtableTypes) { action(hashtableType); } }
public void ContainsValue() { Hashtable hash1 = Helpers.CreateStringHashtable(100); Helpers.PerformActionOnAllHashtableWrappers(hash1, hash2 => { for (int i = 0; i < hash2.Count; i++) { string value = "Value_" + i; Assert.True(hash2.ContainsValue(value)); } Assert.False(hash2.ContainsValue("Non Existent Value")); Assert.False(hash2.ContainsValue(101)); Assert.False(hash2.ContainsValue(null)); hash2.Add("Key_101", null); Assert.True(hash2.ContainsValue(null)); string removedKey = "Key_1"; string removedValue = "Value_1"; hash2.Remove(removedKey); Assert.False(hash2.ContainsValue(removedValue)); }); }