示例#1
0
 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));
     }
 }
示例#2
0
 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)));
     }
 }
示例#3
0
 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));
     }
 }
示例#4
0
 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));
     }
 }
示例#5
0
 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));
     }
 }
示例#6
0
 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));
     }
 }
示例#7
0
        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);
        }
示例#8
0
        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);
        }
示例#9
0
        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));
            }
        }
示例#10
0
        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);
            }
        }
示例#11
0
 private bool AddShortLivedObjectToDictionary(WeakKeyDictionary <DisposableTestObject, string> dictionary, string name)
 {
     return(dictionary.AddEntry(new DisposableTestObject(name), name));
 }