Пример #1
0
        public void AddTest()
        {
            var pair = new KeyValuePair <int, int>(4, 2);
            var dict = new DictionaryCollection <int, int>(4);

            dict.Add(pair);
            Assert.Single(dict);
        }
Пример #2
0
        public void SetIndexNullKeyException()
        {
            var dictionary = new DictionaryCollection <int?, string>(5);

            dictionary.Add(1, "a");
            dictionary.Add(2, "b");
            dictionary.Add(10, "c");
            dictionary.Add(7, "d");
            dictionary.Add(12, "e");
            Assert.Throws <ArgumentNullException>(() => dictionary[null] = "f");
        }
Пример #3
0
        public void KeyAlreadyInListAddException()
        {
            var dictionary = new DictionaryCollection <int, string>(5);

            dictionary.Add(1, "a");
            dictionary.Add(2, "b");
            dictionary.Add(10, "c");
            dictionary.Add(7, "d");
            dictionary.Add(12, "e");
            Assert.Throws <ArgumentException>(() => dictionary.Add(1, "f"));
        }
Пример #4
0
        public void KeyNotFoundGetIndexException()
        {
            var dictionary = new DictionaryCollection <int, string>(5);

            dictionary.Add(1, "a");
            dictionary.Add(2, "b");
            dictionary.Add(10, "c");
            dictionary.Add(7, "d");
            dictionary.Add(12, "e");
            Assert.Throws <KeyNotFoundException>(() => dictionary[5] == "f");
        }
Пример #5
0
        public void NullKeyTryGetValueException()
        {
            var dictionary = new DictionaryCollection <int?, string>(5);

            dictionary.Add(1, "a");
            dictionary.Add(2, "b");
            dictionary.Add(10, "c");
            dictionary.Add(7, "d");
            dictionary.Add(12, "e");
            Assert.Throws <ArgumentNullException>(() => dictionary.TryGetValue(null, out string value));
        }
Пример #6
0
        public void NullKeyRemoveException()
        {
            var dictionary = new DictionaryCollection <int?, string>(5);

            dictionary.Add(1, "a");
            dictionary.Add(2, "b");
            dictionary.Add(10, "c");
            dictionary.Add(7, "d");
            dictionary.Add(12, "e");
            Assert.Throws <ArgumentNullException>(() => dictionary.Remove(null));
        }
Пример #7
0
        public void GetValuesTest()
        {
            var dict = new DictionaryCollection <string, int>(5);

            dict.Add(new KeyValuePair <string, int>("Cat", 1));
            dict.Add(new KeyValuePair <string, int>("Dog", 2));
            dict.Add(new KeyValuePair <string, int>("Rabbit", 4));
            ICollection <int> valueList = dict.Values;

            Assert.Equal(3, valueList.Count);
        }
Пример #8
0
        public void ContainsKeyTest()
        {
            var dictionary = new DictionaryCollection <int, string>(5);

            dictionary.Add(1, "a");
            dictionary.Add(2, "b");
            dictionary.Add(10, "c");
            dictionary.Add(7, "d");
            dictionary.Add(12, "e");
            Assert.True(dictionary.ContainsKey(7));
        }
Пример #9
0
        public void GetIndexerTest()
        {
            var dictionary = new DictionaryCollection <int, string>(5);

            dictionary.Add(1, "a");
            dictionary.Add(2, "b");
            dictionary.Add(10, "c");
            dictionary.Add(7, "d");
            dictionary.Add(12, "e");
            Assert.Equal("a", dictionary[1]);
        }
Пример #10
0
        public void IsReadonlyAddException()
        {
            var dictionary = new DictionaryCollection <int, string>(5);

            dictionary.Add(1, "a");
            dictionary.Add(2, "b");
            dictionary.Add(10, "c");
            dictionary.Add(7, "d");
            dictionary.Add(12, "e");
            dictionary = dictionary.ReadOnlyDictionary();
            Assert.Throws <NotSupportedException>(() => dictionary.Add(13, "f"));
        }
Пример #11
0
        public void RemoveTest()
        {
            var dictionary = new DictionaryCollection <int, string>(5);

            dictionary.Add(1, "a");
            dictionary.Add(2, "b");
            dictionary.Add(10, "c");
            dictionary.Add(7, "d");
            dictionary.Add(12, "e");
            dictionary.Remove(2);
            Assert.False(dictionary.ContainsKey(2));
        }
Пример #12
0
        public void CointainsTest()
        {
            var dictionary = new DictionaryCollection <int, string>(5);

            dictionary.Add(1, "a");
            dictionary.Add(2, "b");
            dictionary.Add(10, "c");
            dictionary.Add(7, "d");
            dictionary.Add(12, "e");
            KeyValuePair <int, string> toFind = new KeyValuePair <int, string>(2, "b");

            Assert.Contains(toFind, dictionary);
        }
Пример #13
0
        public void ReadOnlyAddPairException()
        {
            var dictionary = new DictionaryCollection <int, string>(5);

            dictionary.Add(1, "a");
            dictionary.Add(2, "b");
            dictionary.Add(10, "c");
            dictionary.Add(7, "d");
            dictionary.Add(12, "e");
            dictionary = dictionary.ReadOnlyDictionary();
            KeyValuePair <int, string> pair = new KeyValuePair <int, string>(13, "f");

            Assert.Throws <NotSupportedException>(() => dictionary.Add(pair));
        }
Пример #14
0
        public void RemoveLastPairTest()
        {
            var dictionary = new DictionaryCollection <int, string>(5);

            dictionary.Add(1, "a");
            dictionary.Add(2, "b");
            dictionary.Add(10, "c");
            dictionary.Add(7, "d");
            dictionary.Add(12, "e");
            KeyValuePair <int, string> pair = new KeyValuePair <int, string>(12, "e");

            dictionary.Remove(pair);
            Assert.False(dictionary.ContainsKey(12));
        }
Пример #15
0
        public void RemoveThenAddOnEmptySpaceTest()
        {
            var dictionary = new DictionaryCollection <int, string>(5);

            dictionary.Add(1, "a");
            dictionary.Add(2, "b");
            dictionary.Add(10, "c");
            dictionary.Add(7, "d");
            dictionary.Add(12, "e");
            KeyValuePair <int, string> pair = new KeyValuePair <int, string>(2, "b");

            dictionary.Remove(pair);
            dictionary.Add(5, "b");
            Assert.Contains(5, dictionary);
        }