public void WeakKeyDictionary_AddDuplicateEntry_DuplicateNotAdded() { using (var key = new DisposableTestObject("dontDupMeBro")) { const int FortyTwo = 42; var dictionary = new WeakKeyDictionary <DisposableTestObject, int>(); Assert.True(dictionary.AddEntry(key, FortyTwo)); Assert.True(dictionary.ContainsKey(key)); Assert.False(dictionary.AddEntry(key, -1)); } }
public void WeakKeyDictionary_AddEntry_ContainsKeyValuePairFails() { using (var key = new DisposableTestObject("Curly")) { const int FortyTwo = 42; var dictionary = new WeakKeyDictionary <DisposableTestObject, int>(); Assert.True(dictionary.AddEntry(key, FortyTwo)); Assert.False(dictionary.Contains(new KeyValuePair <DisposableTestObject, int>(key, -3))); } }
public void WeakKeyDictionary_AddEntry_ContainsKeyAsObjectSucceeds() { using (var key = new DisposableTestObject("Shemp")) { const int FortyTwo = 42; var dictionary = new WeakKeyDictionary <DisposableTestObject, int>(); Assert.True(dictionary.AddEntry(key, FortyTwo)); Assert.True(dictionary.Contains((object)key)); } }
public void WeakKeyDictionary_RemoveKeyValuePair_EntryNotRemoved() { using (var key = new DisposableTestObject("Just kidding!")) { const int FortyTwo = 42; var dictionary = new WeakKeyDictionary <DisposableTestObject, int>(); Assert.True(dictionary.AddEntry(key, FortyTwo)); Assert.False(dictionary.Remove(new KeyValuePair <DisposableTestObject, int>(key, 54))); Assert.True(dictionary.ContainsKey(key)); } }
public void WeakKeyDictionary_RemoveKey_EntryRemoved() { using (var key = new DisposableTestObject("That's it, I'm outta here!")) { const int FortyTwo = 42; var dictionary = new WeakKeyDictionary <DisposableTestObject, int>(); Assert.True(dictionary.AddEntry(key, FortyTwo)); Assert.True(dictionary.Remove(key)); Assert.False(dictionary.ContainsKey(key)); } }
public void WeakKeyDictionary_RemoveKeyAsObject_EntryRemoved() { using (var key = new DisposableTestObject("Remove Me, too!")) { const int FortyTwo = 42; var dictionary = new WeakKeyDictionary <DisposableTestObject, int>(); Assert.True(dictionary.AddEntry(key, FortyTwo)); dictionary.Remove((object)key); Assert.False(dictionary.ContainsKey(key)); } }
public void WeakKeyDictionary_GetUsingItemUsingObject_GetsItem() { var dictionary = new WeakKeyDictionary <object, object>(); var key = new DisposableTestObject("howdy, pardner"); object value = "how's it goin'"; Assert.True(dictionary.AddEntry(key, value)); var valueOut = dictionary[key]; Assert.Equal(value, valueOut); }
public void WeakKeyDictionary_GetUsingItem_GetsItem() { var dictionary = new WeakKeyDictionary <DisposableTestObject, string>(); var key = new DisposableTestObject("howdy, pardner"); const string Value = "how's it goin'"; Assert.True(dictionary.AddEntry(key, Value)); var value = dictionary[key]; Assert.Equal(Value, value); }
public void WeakKeyDictionary_TryGetRemovedValue_ValueNotRetrieved() { using (var key = new DisposableTestObject("What? Where'd that one go?")) { const int FortyTwo = 42; var dictionary = new WeakKeyDictionary <DisposableTestObject, int>(); Assert.True(dictionary.AddEntry(key, FortyTwo)); Assert.True(dictionary.RemoveEntry(key)); int value; Assert.False(dictionary.TryGetValue(key, out value)); } }
public void WeakKeyDictionary_AddEntry_TryGetValueSucceeds() { using (var key = new DisposableTestObject("Moe")) { const int FortyTwo = 42; var dictionary = new WeakKeyDictionary <DisposableTestObject, int>(); Assert.True(dictionary.AddEntry(key, FortyTwo)); Assert.True(dictionary.ContainsKey(key)); int value; Assert.True(dictionary.TryGetValue(key, out value)); Assert.Equal(FortyTwo, value); } }
private bool AddShortLivedObjectToDictionary(WeakKeyDictionary <DisposableTestObject, string> dictionary, string name) { return(dictionary.AddEntry(new DisposableTestObject(name), name)); }