Exemple #1
0
        public void TestCaseAssume()
        {
            var ocr = new ObservableCollectionRanged <string>();

            ocr.AddRange(names1);
            ocr.AddRange(names2);

            ocr.CollectionChanged += (sender, e) =>
            {
                Assert.IsTrue(e.Action == NotifyCollectionChangedAction.Replace);
                Assert.IsNotNull(e.NewItems);
                Assert.IsNotNull(e.OldItems);
                Assert.IsTrue(e.OldItems.Count == (names1.Count + names2.Count));
                Assert.IsTrue(e.NewItems.Count == names1.Count);
            };

            ocr.AssumeRange(names1);
        }
        public void TestCaseAddNull()
        {
            var ocr = new ObservableCollectionRanged <string>();

            ocr.CollectionChanged += (sender, e) =>
            {
                Assert.IsTrue(e.Action == NotifyCollectionChangedAction.Add);
                Assert.IsNull(e.NewItems);
                Assert.IsNull(e.OldItems);
            };

            Assert.Throws <ArgumentNullException>(() => ocr.AddRange(null));
        }
Exemple #3
0
        public void TestCaseAssumeGrouped()
        {
            var ocr = new ObservableCollectionRanged <IGrouping <int, string> >();

            var groupedList1 = names1.GroupBy(s => s.Length);

            ocr.AddRange(groupedList1);

            var groupedList2 = names2.GroupBy(s => s.Length);

            ocr.AddRange(groupedList2);

            ocr.CollectionChanged += (sender, e) =>
            {
                Assert.IsTrue(e.Action == NotifyCollectionChangedAction.Replace);
                Assert.IsNotNull(e.NewItems);
                Assert.IsNotNull(e.OldItems);
                Assert.IsTrue(e.OldItems.Count == (groupedList1.Count() + groupedList2.Count()));
                Assert.IsTrue(e.NewItems.Count == groupedList1.Count());
            };

            ocr.AssumeRange(groupedList1);
        }
Exemple #4
0
        public void TestCaseAdd()
        {
            var ocr = new ObservableCollectionRanged <string>();

            ocr.CollectionChanged += (sender, e) =>
            {
                Assert.IsTrue(e.Action == NotifyCollectionChangedAction.Add);
                Assert.IsNotNull(e.NewItems);
                Assert.IsNull(e.OldItems);
                Assert.IsTrue(e.NewItems.Count == names1.Count);
                Assert.IsTrue(e.NewStartingIndex == 0);
            };

            ocr.AddRange(names1);
        }
Exemple #5
0
        public void TestCaseAssumeNull()
        {
            var ocr = new ObservableCollectionRanged <string>();

            ocr.AddRange(names1);

            ocr.CollectionChanged += (sender, e) =>
            {
                Assert.IsTrue(e.Action == NotifyCollectionChangedAction.Reset);
                Assert.IsNull(e.NewItems);
                Assert.IsNull(e.OldItems);
            };

            ocr.AssumeRange(null);
        }
Exemple #6
0
        public void TestCaseAddGrouped()
        {
            var ocr         = new ObservableCollectionRanged <IGrouping <int, string> >();
            var groupedList = names1.GroupBy(s => s.Length);

            ocr.CollectionChanged += (sender, e) =>
            {
                Assert.IsTrue(e.Action == NotifyCollectionChangedAction.Add);
                Assert.IsNotNull(e.NewItems);
                Assert.IsNull(e.OldItems);
                Assert.IsTrue(e.NewItems.Count == groupedList.Count());
                Assert.IsTrue(e.NewStartingIndex == 0);
            };

            ocr.AddRange(groupedList);
        }
Exemple #7
0
        public void TestCaseInsert()
        {
            var ocr = new ObservableCollectionRanged <string>();

            int index = 0;

            ocr.AddRange(names1);

            ocr.CollectionChanged += (sender, e) =>
            {
                Assert.IsTrue(e.Action == NotifyCollectionChangedAction.Add);
                Assert.IsNotNull(e.NewItems);
                Assert.IsNull(e.OldItems);
                Assert.IsTrue(e.NewItems.Count == names2.Count);
                Assert.AreEqual(index, e.NewStartingIndex);
            };

            ocr.InsertRange(index, names2);
        }
        public void TestCaseReplaceRange()
        {
            var ocr = new ObservableCollectionRanged <string>();

            ocr.AddRange(names1);
            int indexToRemove = 1;
            int countToRemove = names1.Count - 1;

            ocr.CollectionChanged += (sender, e) =>
            {
                Assert.IsTrue(e.Action == NotifyCollectionChangedAction.Replace);
                Assert.IsNotNull(e.NewItems);
                Assert.IsNotNull(e.OldItems);
                Assert.IsTrue(e.OldItems.Count == countToRemove);
                Assert.IsTrue(e.NewItems.Count == names2.Count);
                Assert.IsTrue(ocr.Count == indexToRemove + names2.Count);
            };

            ocr.ReplaceRange(indexToRemove, countToRemove, names2);
        }
Exemple #9
0
        public void TestCaseInsertGrouped()
        {
            var ocr = new ObservableCollectionRanged <IGrouping <int, string> >();

            int index = 0;

            var groupedList1 = names1.GroupBy(s => s.Length);

            ocr.AddRange(groupedList1);

            var groupedList2 = names2.GroupBy(s => s.Length);

            ocr.CollectionChanged += (sender, e) =>
            {
                Assert.IsTrue(e.Action == NotifyCollectionChangedAction.Add);
                Assert.IsNotNull(e.NewItems);
                Assert.IsNull(e.OldItems);
                Assert.IsTrue(e.NewItems.Count == groupedList2.Count());
                Assert.AreEqual(index, e.NewStartingIndex);
            };

            ocr.InsertRange(index, groupedList2);
        }