예제 #1
0
        public static void TryGetValueTests()
        {
            KeyValuePair <int, string>[] expectedArr = new KeyValuePair <int, string>[] {
                new KeyValuePair <int, string>(1, "one"),
                new KeyValuePair <int, string>(2, "two"),
                new KeyValuePair <int, string>(3, "three"),
                new KeyValuePair <int, string>(4, "four"),
                new KeyValuePair <int, string>(5, "five")
            };
            DummyDictionary <int, string>            dummyExpectedDict = new DummyDictionary <int, string>(expectedArr);
            ReadOnlyDictionary <int, string>         dictionary        = new ReadOnlyDictionary <int, string>(dummyExpectedDict);
            IReadOnlyDictionary_T_Test <int, string> helper            = new IReadOnlyDictionary_T_Test <int, string>(dictionary, expectedArr, s_generateItemFunc);

            helper.TryGetValue_Tests();
        }
예제 #2
0
        public static void CtorTests()
        {
            KeyValuePair <int, string>[] expectedArr = new KeyValuePair <int, string>[] {
                new KeyValuePair <int, string>(1, "one"),
                new KeyValuePair <int, string>(2, "two"),
                new KeyValuePair <int, string>(3, "three"),
                new KeyValuePair <int, string>(4, "four"),
                new KeyValuePair <int, string>(5, "five")
            };
            DummyDictionary <int, string>            dummyExpectedDict = new DummyDictionary <int, string>(expectedArr);
            ReadOnlyDictionary <int, string>         dictionary        = new ReadOnlyDictionary <int, string>(dummyExpectedDict);
            IReadOnlyDictionary_T_Test <int, string> helper            = new IReadOnlyDictionary_T_Test <int, string>(dictionary, expectedArr, s_generateItemFunc);

            helper.InitialItems_Tests();

            IDictionary <int, string> dictAsIDictionary = dictionary;

            Assert.True(dictAsIDictionary.IsReadOnly, "ReadonlyDictionary Should be readonly");
        }
예제 #3
0
        public static void CannotModifyDictionaryTests_Negative()
        {
            KeyValuePair <int, string>[] expectedArr = new KeyValuePair <int, string>[] {
                new KeyValuePair <int, string>(1, "one"),
                new KeyValuePair <int, string>(2, "two"),
                new KeyValuePair <int, string>(3, "three"),
                new KeyValuePair <int, string>(4, "four"),
                new KeyValuePair <int, string>(5, "five")
            };
            DummyDictionary <int, string>            dummyExpectedDict = new DummyDictionary <int, string>(expectedArr);
            ReadOnlyDictionary <int, string>         dictionary        = new ReadOnlyDictionary <int, string>(dummyExpectedDict);
            IReadOnlyDictionary_T_Test <int, string> helper            = new IReadOnlyDictionary_T_Test <int, string>();
            IDictionary <int, string> dictAsIDictionary = dictionary;

            Assert.Throws <NotSupportedException>(() => dictAsIDictionary.Add(new KeyValuePair <int, string>(7, "seven")));
            Assert.Throws <NotSupportedException>(() => dictAsIDictionary.Add(7, "seven"));
            Assert.Throws <NotSupportedException>(() => dictAsIDictionary.Remove(new KeyValuePair <int, string>(1, "one")));
            Assert.Throws <NotSupportedException>(() => dictAsIDictionary.Remove(1));
            Assert.Throws <NotSupportedException>(() => dictAsIDictionary.Clear());

            helper.VerifyCollection(dictionary, expectedArr); //verifying that the collection has not changed.
        }