コード例 #1
0
        public void SetIndexer_IDictionary(string input)
        {
            IDictionary <string, bool> dict = new KeyThrowingDictionary <string, bool>();

            dict[input] = default;
            Assert.True(dict.ContainsKey(input));
        }
コード例 #2
0
        public void Contains_IDictionary(string input)
        {
            IDictionary <string, bool> dict = new KeyThrowingDictionary <string, bool>();

            dict.Add(input, true);
            Assert.True(dict.ContainsKey(input));
        }
コード例 #3
0
        public void Contains_IReadOnlyDictionary(string input)
        {
            KeyThrowingDictionary <string, bool> dict = new KeyThrowingDictionary <string, bool>();

            dict.Add(input, true);
            Assert.True(((IReadOnlyDictionary <string, bool>)dict).ContainsKey(input));
        }
コード例 #4
0
        public void Missing_IDictionary(string input)
        {
            IDictionary <string, bool> dict = new KeyThrowingDictionary <string, bool>();

            Assert.Throws <KeyNotFoundException>(() => dict[input]);
            try
            {
                var discard = dict[input];
                Assert.True(false);
            }
            catch (KeyNotFoundException ex)
            {
                Assert.Contains(input.ToString(), ex.Message);
                return;
            }
            Assert.True(false);
        }
コード例 #5
0
        public void DoubleAdd(string input)
        {
            KeyThrowingDictionary <string, bool> dict = new KeyThrowingDictionary <string, bool>();

            dict.Add(input, true);
            Assert.Throws <ArgumentException>(() => dict.Add(input, true));
            try
            {
                dict.Add(input, true);
                Assert.True(false);
            }
            catch (ArgumentException ex)
            {
                Assert.Contains(input.ToString(), ex.Message);
                return;
            }
            Assert.True(false);
        }
コード例 #6
0
        public void KeyNotNull()
        {
            KeyThrowingDictionary <string, bool> dict = new KeyThrowingDictionary <string, bool>();

            Assert.Throws <ArgumentNullException>(() => dict.Add(null, true));
        }