public static void CopyToTest()
        {
            string[] anArray = new string[] { "one", "two", "three", "four" };
            ObservableList <string> collection = new ObservableList <string>((IEnumerable <string>)anArray);

            string[] aCopy = new string[collection.Count];
            collection.CopyTo(aCopy, 0);
            for (int i = 0; i < anArray.Length; ++i)
            {
                Assert.Equal(anArray[i], aCopy[i]);
            }

            // copy observable collection starting in middle, where array is larger than source.
            aCopy = new string[collection.Count + 2];
            int offsetIndex = 1;

            collection.CopyTo(aCopy, offsetIndex);
            for (int i = 0; i < aCopy.Length; i++)
            {
                string value = aCopy[i];
                if (i == 0)
                {
                    Assert.True(null == value, "Should not have a value since we did not start copying there.");
                }
                else if (i == (aCopy.Length - 1))
                {
                    Assert.True(null == value, "Should not have a value since the collection is shorter than the copy array..");
                }
                else
                {
                    int indexInCollection = i - offsetIndex;
                    Assert.Equal(collection[indexInCollection], aCopy[i]);
                }
            }
        }
        public void Observable_List_Info_Operations_Should_Subscribe_To_Version(bool triggerViaIndexer)
        {
            var lst = new ObservableList <int>()
            {
                1, 2, 3
            };
            var copyTo = WhenTwice(() => lst.CopyTo(new int[3], 0));
            // ReSharper disable ReturnValueOfPureMethodIsNotUsed
            var contains   = WhenTwice(() => lst.Contains(5));
            var indexOf    = WhenTwice(() => lst.IndexOf(5));
            var enumerator = WhenTwice(() => lst.GetEnumerator());
            // ReSharper restore ReturnValueOfPureMethodIsNotUsed

            var arr = new[] { copyTo, contains, indexOf, enumerator };

            Assert.True(arr.All(t => !t.IsCompleted));

            if (triggerViaIndexer)
            {
                lst[0] = 5;
            }
            else
            {
                lst.Add(5);
            }
            Assert.True(arr.All(t => t.IsCompleted));
        }
    public void CopyToArrayWithIndex()
    {
        var list = new ObservableList <int>(sampleList);

        int[] array = new int[10];

        list.CopyTo(array, 2);

        Assert.AreEqual(1, array[2]);
        Assert.AreEqual(2, array[3]);
        Assert.AreEqual(3, array[4]);
        Assert.AreEqual(4, array[5]);
        Assert.AreEqual(5, array[6]);
    }
        public void CopyToArrayWithIndex()
        {
            var list = new ObservableList <int>(new List <int> {
                1, 2, 3, 4, 5
            });

            var array = new int[10];

            list.CopyTo(array, 2);

            Assert.AreEqual(1, array[2]);
            Assert.AreEqual(2, array[3]);
            Assert.AreEqual(3, array[4]);
            Assert.AreEqual(4, array[5]);
            Assert.AreEqual(5, array[6]);
        }
 public void CopyTo(ContentItem[] array, int arrayIndex)
 {
     contents.CopyTo(array, arrayIndex);
 }
        public static void CopyToTest_Negative()
        {
            string[] anArray = new string[] { "one", "two", "three", "four" };
            ObservableList <string> collection = new ObservableList <string>(anArray);

            int[] iArrInvalidValues = new int[] { -1, -2, -100, -1000, -10000, -100000, -1000000, -10000000, -100000000, -1000000000, int.MinValue };
            foreach (var index in iArrInvalidValues)
            {
                string[] aCopy = new string[collection.Count];
                AssertExtensions.Throws <ArgumentOutOfRangeException>("destinationIndex", "dstIndex", () => collection.CopyTo(aCopy, index));
            }

            int[] iArrLargeValues = new int[] { collection.Count, int.MaxValue, int.MaxValue / 2, int.MaxValue / 10 };
            foreach (var index in iArrLargeValues)
            {
                string[] aCopy = new string[collection.Count];
                AssertExtensions.Throws <ArgumentException>("destinationArray", null, () => collection.CopyTo(aCopy, index));
            }

            AssertExtensions.Throws <ArgumentNullException>("destinationArray", "dest", () => collection.CopyTo(null, 1));

            string[] copy = new string[collection.Count - 1];
            AssertExtensions.Throws <ArgumentException>("destinationArray", "", () => collection.CopyTo(copy, 0));

            copy = new string[0];
            AssertExtensions.Throws <ArgumentException>("destinationArray", "", () => collection.CopyTo(copy, 0));
        }