public void Remove_ValidKeyWithoutDictionary_Success(IEqualityComparer <string> comparer, string key, bool expected, string[] expectedItems)
        {
            var collection = new StringKeyedCollection <string>(comparer, 3);

            collection.GetKeyForItemHandler = i => i + "_key";
            collection.Add("first");
            Assert.Null(collection.Dictionary);

            Assert.Equal(expected, collection.Remove(key));
            Assert.Equal(expectedItems, collection.Items.Cast <string>());
            Assert.Null(collection.Dictionary);
        }
        public void Remove_NullKeyForItemResult_Success()
        {
            var collection = new StringKeyedCollection <int>(null, 3);

            collection.GetKeyForItemHandler = item => item.ToString();
            collection.Add(1);
            collection.Add(2);
            collection.Add(3);
            collection.Add(4);

            // Don't add/remove even numbers.
            collection.GetKeyForItemHandler = item => item % 2 == 0 ? null : item.ToString();

            // Remove null key.
            Assert.True(collection.Remove("2"));
            Assert.Equal(new int[] { 1, 3, 4 }, collection.Items.Cast <int>());
            Assert.Equal(new Dictionary <string, int>
            {
                { "1", 1 },
                { "2", 2 },
                { "3", 3 },
                { "4", 4 }
            }, collection.Dictionary
                         );

            // Remove non-null key.
            Assert.True(collection.Remove("1"));
            Assert.Equal(new int[] { 3, 4 }, collection.Items.Cast <int>());
            Assert.Equal(new Dictionary <string, int>
            {
                { "2", 2 },
                { "3", 3 },
                { "4", 4 }
            }, collection.Dictionary
                         );
        }
        public void Remove_Invoke_ResetsCurrentThresholdCount()
        {
            var collection = new StringKeyedCollection <string>(null, 3);

            collection.GetKeyForItemHandler = item => item + "_key";
            collection.Add("first");
            collection.Remove("first_key");

            // Add more items - make sure the current count has been reset.
            collection.Add("first");
            Assert.Null(collection.Dictionary);

            collection.Add("second");
            Assert.Null(collection.Dictionary);

            collection.Add("third");
            Assert.Null(collection.Dictionary);

            collection.Add("fourth");
            Assert.NotEmpty(collection.Dictionary);
        }
        public void Remove_NullKey_ThrowsArgumentNullException()
        {
            var collection = new StringKeyedCollection <string>();

            AssertExtensions.Throws <ArgumentNullException>("key", () => collection.Remove(null));
        }