예제 #1
0
        public void WeakKeyDictionaryWithData_CopyToEndOfSufficientlyLargeKeyValuePairArray_Succeeds()
        {
            const int NumValuesToAdd = 20;
            var       keeperArounder = new List <KeyValuePair <string, int> >();
            ICollection <KeyValuePair <string, int> > dictionary = new WeakKeyDictionary <string, int>();

            for (int i = 0; i < NumValuesToAdd; ++i)
            {
                var entry = new KeyValuePair <string, int>(i.ToString(), i);
                keeperArounder.Add(entry);
                dictionary.Add(entry);
            }
            Assert.Equal(NumValuesToAdd, dictionary.Count);

            var       destination = new KeyValuePair <string, int> [50];
            const int StartIndex  = 30;

            dictionary.CopyTo(destination, StartIndex);

            for (int i = 0; i < NumValuesToAdd; ++i)
            {
                Assert.Equal(i.ToString(), destination[i + StartIndex].Key);
                Assert.Equal(i, destination[i + StartIndex].Value);
            }
        }
예제 #2
0
        public void WeakKeyDictionaryWithData_CopyToBeginningOfSufficientlyLargeKeyValuePairArray_Succeeds()
        {
            const int NumValuesToAdd = 4;
            ICollection <KeyValuePair <string, int> > dictionary = new WeakKeyDictionary <string, int>();

            for (int i = 0; i < NumValuesToAdd; ++i)
            {
                dictionary.Add(new KeyValuePair <string, int>(i.ToString(), i));
            }
            Assert.Equal(NumValuesToAdd, dictionary.Count);

            var       destination = new KeyValuePair <string, int> [50];
            const int StartIndex  = 0;

            dictionary.CopyTo(destination, StartIndex);
        }
예제 #3
0
        public void WeakKeyDictionaryWithData_CopyToNullKeyValuePairArray_ThrowsArgumentNullException()
        {
            const int NumValuesToAdd = 10;
            var       keeperArounder = new List <KeyValuePair <string, int> >();
            ICollection <KeyValuePair <string, int> > dictionary = new WeakKeyDictionary <string, int>();

            for (int i = 0; i < NumValuesToAdd; ++i)
            {
                var entry = new KeyValuePair <string, int>(i.ToString(), i);
                keeperArounder.Add(entry);
                dictionary.Add(entry);
            }
            Assert.Equal(NumValuesToAdd, dictionary.Count);

            Assert.Throws <ArgumentNullException>(() => dictionary.CopyTo(null, 0));
        }
예제 #4
0
        public void WeakKeyDictionaryWithData_CopyToKeyValuePairArrayWithIndexResultingInWritePastEndOfArray_ThrowsArgumentException()
        {
            const int NumValuesToAdd = 80;
            var       keeperArounder = new List <KeyValuePair <string, int> >();
            ICollection <KeyValuePair <string, int> > dictionary = new WeakKeyDictionary <string, int>();

            for (int i = 0; i < NumValuesToAdd; ++i)
            {
                var data = new KeyValuePair <string, int>(i.ToString(), i);
                keeperArounder.Add(data);
                dictionary.Add(data);
            }
            Assert.True(NumValuesToAdd >= dictionary.Count);

            var destination = new KeyValuePair <string, int> [50];

            Assert.Throws <ArgumentException>(() => dictionary.CopyTo(destination, 48));
        }
예제 #5
0
        public void WeakKeyDictionaryWithData_CopyToKeyValuePairArrayWithNegativeIndex_ThrowsArgumentOutOfRangeException()
        {
            const int NumValuesToAdd = 6;
            var       keeperArounder = new List <KeyValuePair <string, int> >();
            ICollection <KeyValuePair <string, int> > dictionary = new WeakKeyDictionary <string, int>();

            for (int i = 0; i < NumValuesToAdd; ++i)
            {
                var entry = new KeyValuePair <string, int>(i.ToString(), i);
                keeperArounder.Add(entry);
                dictionary.Add(entry);
            }
            Assert.Equal(NumValuesToAdd, dictionary.Count);

            var destination = new KeyValuePair <string, int> [2];

            Assert.Throws <ArgumentOutOfRangeException>(() => dictionary.CopyTo(destination, -1));
        }