public static void InsertTest()
        {
            Guid[] anArray             = { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() };
            ObservableList <Guid> col0 = new ObservableList <Guid>((IEnumerable <Guid>)anArray);
            ObservableList <Guid> col1 = new ObservableList <Guid>((IEnumerable <Guid>)anArray);
            ObservableList <Guid> col3 = new ObservableList <Guid>((IEnumerable <Guid>)anArray);

            //inserting item at the beginning.
            Guid g0 = Guid.NewGuid();

            col0.Insert(0, g0);
            Assert.Equal(g0, col0[0]);

            // inserting item in the middle
            Guid g1 = Guid.NewGuid();

            col1.Insert(1, g1);
            Assert.Equal(g1, col1[1]);

            // inserting item at the end.
            Guid g3 = Guid.NewGuid();

            col3.Insert(col3.Count, g3);
            Assert.Equal(g3, col3[col3.Count - 1]);

            string[] anArrayString = new string[] { "one", "two", "three", "four" };
            ObservableList <string>            collection = new ObservableList <string>((IEnumerable <string>)anArrayString);
            CollectionAndPropertyChangedTester helper     = new CollectionAndPropertyChangedTester();

            helper.AddOrInsertItemTest(collection, "seven", 2);
            helper.AddOrInsertItemTest(collection, "zero", 0);
            helper.AddOrInsertItemTest(collection, "eight", collection.Count);
        }
        public static void AddTest()
        {
            string[] anArray = { "one", "two", "three" };
            ObservableList <string>            col    = new ObservableList <string>(anArray);
            CollectionAndPropertyChangedTester helper = new CollectionAndPropertyChangedTester();

            helper.AddOrInsertItemTest(col, "four");
        }
        public static void ReplaceItemTest()
        {
            string[] anArray = new string[] { "one", "two", "three", "four" };
            ObservableList <string>            collection = new ObservableList <string>((IEnumerable <string>)anArray);
            CollectionAndPropertyChangedTester helper     = new CollectionAndPropertyChangedTester();

            helper.ReplaceItemTest(collection, 1, "seven");
            helper.ReplaceItemTest(collection, 3, "zero");
        }
        public static void ClearTest()
        {
            string[] anArray            = { "one", "two", "three", "four" };
            ObservableList <string> col = new ObservableList <string>(anArray);

            col.Clear();
            Assert.Equal(0, col.Count);
            Assert.Empty(col);

            AssertExtensions.Throws <ArgumentOutOfRangeException>("index", () => col[1]);

            //tests that the collectionChanged events are fired.
            CollectionAndPropertyChangedTester helper = new CollectionAndPropertyChangedTester();

            col = new ObservableList <string>(anArray);
            helper.ClearTest(col);
        }
        public static void RemoveTest()
        {
            // trying to remove item in collection.
            string[] anArray = { "one", "two", "three", "four" };
            ObservableList <string>            col    = new ObservableList <string>(anArray);
            CollectionAndPropertyChangedTester helper = new CollectionAndPropertyChangedTester();

            helper.RemoveItemTest(col, 2, "three", true, hasDuplicates: false);

            // trying to remove item not in collection.
            anArray = new string[] { "one", "two", "three", "four" };
            col     = new ObservableList <string>(anArray);
            helper  = new CollectionAndPropertyChangedTester();
            helper.RemoveItemTest(col, -1, "three2", false, hasDuplicates: false);

            // removing null
            anArray = new string[] { "one", "two", "three", "four" };
            col     = new ObservableList <string>(anArray);
            helper  = new CollectionAndPropertyChangedTester();
            helper.RemoveItemTest(col, -1, null, false, hasDuplicates: false);

            // trying to remove item in collection that has duplicates.
            anArray = new string[] { "one", "three", "two", "three", "four" };
            col     = new ObservableList <string>(anArray);
            helper  = new CollectionAndPropertyChangedTester();
            helper.RemoveItemTest(col, 1, "three", true, hasDuplicates: true);
            // want to ensure that there is one "three" left in collection and not both were removed.
            int occurrencesThree = 0;

            foreach (var item in col)
            {
                if (item.Equals("three"))
                {
                    occurrencesThree++;
                }
            }
            Assert.Equal(1, occurrencesThree);
        }
        public static void RemoveAtTest()
        {
            Guid[] anArray             = { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() };
            ObservableList <Guid> col0 = new ObservableList <Guid>((IEnumerable <Guid>)anArray);
            ObservableList <Guid> col1 = new ObservableList <Guid>((IEnumerable <Guid>)anArray);
            ObservableList <Guid> col2 = new ObservableList <Guid>((IEnumerable <Guid>)anArray);

            col0.RemoveAt(0);
            string collectionString = "";

            foreach (var item in col1)
            {
                collectionString += item + ", ";
            }
            Assert.False(col0.Contains(anArray[0]), "Collection0 should no longer contain the item: " + anArray[0] + " Collection: " + collectionString);

            col1.RemoveAt(1);
            collectionString = "";
            foreach (var item in col1)
            {
                collectionString += item + ", ";
            }
            Assert.False(col1.Contains(anArray[1]), "Collection1 should no longer contain the item: " + anArray[1] + " Collection: " + collectionString);

            col2.RemoveAt(2);
            collectionString = "";
            foreach (var item in col2)
            {
                collectionString += item + ", ";
            }
            Assert.False(col2.Contains(anArray[2]), "Collection2 should no longer contain the item: " + anArray[2] + " Collection: " + collectionString);

            string[] anArrayString = { "one", "two", "three", "four" };
            ObservableList <string>            col    = new ObservableList <string>(anArrayString);
            CollectionAndPropertyChangedTester helper = new CollectionAndPropertyChangedTester();

            helper.RemoveItemAtTest(col, 1);
        }