Esempio n. 1
0
        public void RemoveFromDictionary_Args1_EvensRemoved()
        {
            Dictionary <object, int> dictionary = new Dictionary <object, int>();
            object object1 = new object();
            object object2 = new object();
            object object3 = new object();
            object object4 = new object();

            dictionary.Add(object1, 1);
            dictionary.Add(object2, 2);
            dictionary.Add(object3, 3);
            dictionary.Add(object4, 4);
            object expectedArgument = new object();

            Func <KeyValuePair <object, int>, object, bool> removeAction = (
                KeyValuePair <object, int> entry,
                object arg
                ) =>
            {
                Assert.Equal(expectedArgument, arg);
                // remove even values
                return((entry.Value % 2) == 0);
            };

            dictionary.RemoveFromDictionary(removeAction, expectedArgument);

            Assert.Equal(2, dictionary.Count);
            Assert.True(dictionary.ContainsKey(object1));
            Assert.False(dictionary.ContainsKey(object2));
            Assert.True(dictionary.ContainsKey(object3));
            Assert.False(dictionary.ContainsKey(object4));
        }