public static void TestICollection()
        {
            ICollection dictionary = new ConcurrentDictionary <int, int>();

            Assert.False(dictionary.IsSynchronized, "TestICollection:  FAILED.  IsSynchronized returned true!");

            int key   = -1;
            int value = +1;

            //add one item to the dictionary
            ((ConcurrentDictionary <int, int>)dictionary).TryAdd(key, value);

            var objectArray = new Object[1];

            dictionary.CopyTo(objectArray, 0);

            Assert.Equal(key, ((KeyValuePair <int, int>)objectArray[0]).Key);
            Assert.Equal(value, ((KeyValuePair <int, int>)objectArray[0]).Value);

            var keyValueArray = new KeyValuePair <int, int> [1];

            dictionary.CopyTo(keyValueArray, 0);
            Assert.Equal(key, keyValueArray[0].Key);
            Assert.Equal(value, keyValueArray[0].Value);

            var entryArray = new DictionaryEntry[1];

            dictionary.CopyTo(entryArray, 0);
            Assert.Equal(key, (int)entryArray[0].Key);
            Assert.Equal(value, (int)entryArray[0].Value);
        }
        public void CopyTo_ThrowsNotImplementedException()
        {
            // Arrange
            ConcurrentDictionary <int, int> dictionary = new ConcurrentDictionary <int, int>();

            // Act/Assert
            Assert.Throws <NotImplementedException>(() => dictionary.CopyTo(new KeyValuePair <int, int> [1], 1));
        }
        public static void TestICollection_Negative()
        {
            ICollection dictionary = new ConcurrentDictionary<int, int>();
            Assert.False(dictionary.IsSynchronized, "TestICollection:  FAILED.  IsSynchronized returned true!");

            Assert.Throws<NotSupportedException>(() => { var obj = dictionary.SyncRoot; });
            // "TestICollection:  FAILED.  SyncRoot property didn't throw");
            Assert.Throws<ArgumentNullException>(() => dictionary.CopyTo(null, 0));
            // "TestICollection:  FAILED.  CopyTo didn't throw ANE when null Array is passed");
            Assert.Throws<ArgumentOutOfRangeException>(() => dictionary.CopyTo(new object[] { }, -1));
            // "TestICollection:  FAILED.  CopyTo didn't throw AORE when negative index passed");

            //add one item to the dictionary
            ((ConcurrentDictionary<int, int>)dictionary).TryAdd(1, 1);
            Assert.Throws<ArgumentException>(() => dictionary.CopyTo(new object[] { }, 0));
            // "TestICollection:  FAILED.  CopyTo didn't throw AE when the Array size is smaller than the dictionary count");
        }
 public void CopyToTest()
 {
     var Test = new ConcurrentDictionary<string, int>();
     var Test2 = new ConcurrentDictionary<string, int>();
     Test.AddOrUpdate("Q", 4, (x, y) => 4);
     Test.AddOrUpdate("Z", 2, (x, y) => 2);
     Test.AddOrUpdate("C", 3, (x, y) => 3);
     Test.AddOrUpdate("A", 1, (x, y) => 1);
     Test.CopyTo(Test2);
     string Value = "";
     int Value2 = 0;
     foreach (string Key in Test2.Keys.OrderBy(x => x))
     {
         Value += Key;
         Value2 += Test2[Key];
     }
     Assert.Equal("ACQZ", Value);
     Assert.Equal(10, Value2);
 }
        public void CopyToTest()
        {
            var Test  = new ConcurrentDictionary <string, int>();
            var Test2 = new ConcurrentDictionary <string, int>();

            Test.AddOrUpdate("Q", 4, (x, y) => 4);
            Test.AddOrUpdate("Z", 2, (x, y) => 2);
            Test.AddOrUpdate("C", 3, (x, y) => 3);
            Test.AddOrUpdate("A", 1, (x, y) => 1);
            Test.CopyTo(Test2);
            string Value  = "";
            int    Value2 = 0;

            foreach (string Key in Test2.Keys.OrderBy(x => x))
            {
                Value  += Key;
                Value2 += Test2[Key];
            }
            Assert.Equal("ACQZ", Value);
            Assert.Equal(10, Value2);
        }
        public void CopyTo_ThrowsNotImplementedException()
        {
            // Arrange
            ConcurrentDictionary<int, int> dictionary = new ConcurrentDictionary<int, int>();

            // Act/Assert
            Assert.Throws<NotImplementedException>(() => dictionary.CopyTo(new KeyValuePair<int, int>[1], 1));
        }