public void CollectionShouldBeUpdated(int section, params int[] newItems)
            {
                Setup();

                var items = new MvxObservableCollection <MvxObservableCollection <int> >
                {
                    new MvxObservableCollection <int>
                    {
                        1, 2
                    },
                    new MvxObservableCollection <int>
                    {
                        3
                    }
                };

                var flatIndex = GetFlatItemIndex(items, section, items[section].Count);
                var flatCount = GetFlatItems(items).Count() + newItems.Length;

                var sut = new FlatObservableCollection <int>(items);

                items[section].AddRange(newItems);

                Assert.AreEqual(flatCount, sut.Count);
                Assert.AreEqual(newItems, sut.Take(flatIndex, newItems.Length));
            }
            public void CollectionShouldBeUpdated(int section, int start, int count)
            {
                Setup();

                var items = new MvxObservableCollection <MvxObservableCollection <int> >
                {
                    new MvxObservableCollection <int>
                    {
                        1, 2
                    },
                    new MvxObservableCollection <int>
                    {
                        3, 4, 5, 6
                    }
                };

                var flatCount = GetFlatItems(items).Count() - count;
                var oldItems  = items[section].Take(start, count).ToArray();

                var sut = new FlatObservableCollection <int>(items);

                items[section].RemoveRange(start, count);

                Assert.AreEqual(flatCount, sut.Count);
                CollectionAssert.IsNotSubsetOf(oldItems, sut);
            }
            public void CollectionShouldBeUpdated(int section, params int[] newItems)
            {
                Setup();

                var items = new MvxObservableCollection <MvxObservableCollection <int> >
                {
                    new MvxObservableCollection <int>
                    {
                        1, 2
                    },
                    new MvxObservableCollection <int>
                    {
                        3, 4, 5, 6
                    }
                };

                var sut = new FlatObservableCollection <int>(items);

                items[section].ReplaceWith(newItems);

                var flatItems = GetFlatItems(items).ToArray();
                var flatCount = flatItems.Length;

                Assert.AreEqual(flatCount, sut.Count);
                Assert.AreEqual(flatItems, sut);
            }
            public void CollectionShouldBeUpdated(int section, int oldIndex, int newIndex)
            {
                Setup();

                var items = new MvxObservableCollection <MvxObservableCollection <int> >
                {
                    new MvxObservableCollection <int>
                    {
                        1, 2
                    },
                    new MvxObservableCollection <int>
                    {
                        3, 4, 5, 6
                    }
                };

                var flatOldItems = GetFlatItems(items).ToArray();
                var flatOldCount = flatOldItems.Length;

                var sut = new FlatObservableCollection <int>(items);

                items[section].Move(oldIndex, newIndex);

                var flatNewItems = GetFlatItems(items).ToArray();
                var flatNewCount = flatNewItems.Length;

                Assert.AreEqual(flatOldCount, sut.Count);
                Assert.AreEqual(flatNewCount, sut.Count);
                Assert.AreEqual(flatNewItems, sut);
            }
            public void AddEventShouldBeRaised(int section, params int[] newItems)
            {
                Setup();

                var events = new List <NotifyCollectionChangedEventArgs>();

                var items = new MvxObservableCollection <MvxObservableCollection <int> >
                {
                    new MvxObservableCollection <int>
                    {
                        1, 2
                    },
                    new MvxObservableCollection <int>
                    {
                        3
                    }
                };

                var flatIndex = GetFlatItemIndex(items, section, items[section].Count);

                var sut = new FlatObservableCollection <int>(items);

                sut.CollectionChanged += (_, args) => events.Add(args);

                items[section].AddRange(newItems);

                Assert.AreEqual(1, events.Count);
                Assert.AreEqual(NotifyCollectionChangedAction.Add, events[0].Action);
                Assert.AreEqual(flatIndex, events[0].NewStartingIndex);
                Assert.AreEqual(newItems, events[0].NewItems);
            }
            public void ResetEventShouldBeRaised(int section, params int[] newItems)
            {
                Setup();

                var events = new List <NotifyCollectionChangedEventArgs>();

                var items = new MvxObservableCollection <MvxObservableCollection <int> >
                {
                    new MvxObservableCollection <int>
                    {
                        1, 2
                    },
                    new MvxObservableCollection <int>
                    {
                        3, 4, 5, 6
                    }
                };

                var sut = new FlatObservableCollection <int>(items);

                sut.CollectionChanged += (_, args) => events.Add(args);

                items[section].ReplaceWith(newItems);

                Assert.AreEqual(1, events.Count);
                Assert.AreEqual(NotifyCollectionChangedAction.Reset, events[0].Action);
            }
            public void RemoveEventShouldBeRaised(int section, int start, int count)
            {
                Setup();

                var events = new List <NotifyCollectionChangedEventArgs>();

                var items = new MvxObservableCollection <MvxObservableCollection <int> >
                {
                    new MvxObservableCollection <int>
                    {
                        1, 2
                    },
                    new MvxObservableCollection <int>
                    {
                        3, 4, 5, 6
                    }
                };

                var flatIndex = GetFlatItemIndex(items, section, start);
                var oldItems  = items[section].Take(start, count).ToArray();

                var sut = new FlatObservableCollection <int>(items);

                sut.CollectionChanged += (_, args) => events.Add(args);

                items[section].RemoveRange(start, count);

                Assert.AreEqual(1, events.Count);
                Assert.AreEqual(NotifyCollectionChangedAction.Remove, events[0].Action);
                Assert.AreEqual(flatIndex, events[0].OldStartingIndex);
                Assert.AreEqual(oldItems, events[0].OldItems);
            }
            public void InitialItemsShouldBeInProvidedOrder()
            {
                var items = new[] { new[] { 1, 2 }, new[] { 3 } };

                var sut = new FlatObservableCollection <int>(items);

                Assert.AreEqual(0, sut.IndexOf(1));
                Assert.AreEqual(1, sut.IndexOf(2));
                Assert.AreEqual(2, sut.IndexOf(3));
            }
            public void ShouldContainInitialItems()
            {
                var items = new[] { new[] { 1, 2 }, new[] { 3 } };

                var sut = new FlatObservableCollection <int>(items);

                Assert.AreEqual(3, sut.Count);
                Assert.IsTrue(sut.Contains(1));
                Assert.IsTrue(sut.Contains(2));
                Assert.IsTrue(sut.Contains(3));
            }
            public void CollectionShouldBeUpdated(params int[][] newItems)
            {
                Setup();

                var items     = new MvxObservableCollection <int[]>(new[] { new[] { 1, 2 }, new[] { 3 }, new[] { 4, 5, 6 } });
                var flatItems = GetFlatItems(newItems).ToArray();
                var flatCount = flatItems.Length;

                var sut = new FlatObservableCollection <int>(items);

                items.ReplaceWith(newItems);

                Assert.AreEqual(flatCount, sut.Count);
                Assert.AreEqual(flatItems, sut);
            }
            public void CollectionShouldBeUpdated(int index, int count)
            {
                Setup();

                var items     = new MvxObservableCollection <int[]>(new[] { new[] { 1, 2 }, new[] { 3 }, new[] { 4, 5, 6 } });
                var flatItems = GetFlatItems(items.Take(index, count)).ToArray();
                var flatCount = GetFlatItems(items).Count() - flatItems.Length;

                var sut = new FlatObservableCollection <int>(items);

                items.RemoveRange(index, count);

                Assert.AreEqual(flatCount, sut.Count);
                CollectionAssert.IsNotSubsetOf(flatItems, sut);
            }
            public void CollectionShouldBeUpdated(params int[][] newItems)
            {
                Setup();

                var items     = new MvxObservableCollection <int[]>(new[] { new[] { 1, 2 }, new[] { 3 } });
                var flatItems = GetFlatItems(newItems);
                var flatCount = GetFlatItems(items).Count() + flatItems.Count();

                var sut = new FlatObservableCollection <int>(items);

                items.AddRange(newItems);

                Assert.AreEqual(flatCount, sut.Count);
                Assert.AreEqual(flatItems, sut.TakeLast(newItems.Length));
            }
            public void CollectionShouldBeUpdated(int index, int[] newItem)
            {
                Setup();

                var items     = new ObservableCollection <int[]>(new[] { new[] { 1, 2 }, new[] { 3 } });
                var flatIndex = GetFlatSectionIndex(items, index);
                var flatItems = GetFlatItems(new[] { newItem });
                var flatCount = GetFlatItems(items).Count() + flatItems.Count();

                var sut = new FlatObservableCollection <int>(items);

                items.Insert(index, newItem);

                Assert.AreEqual(flatCount, sut.Count);
                Assert.AreEqual(flatItems, sut.Take(flatIndex, newItem.Length));
            }
                public void EventShouldNotBeRaised()
                {
                    Setup();

                    var events = new List <NotifyCollectionChangedEventArgs>();
                    var items  = new MvxObservableCollection <int[]>(new[] { new[] { 1, 2 }, new[] { 3 } });

                    var sut = new FlatObservableCollection <int>(items);

                    sut.CollectionChanged += (_, args) => events.Add(args);

                    sut.Dispose();

                    items.Add(new[] { 1 });
                    items.Remove(new[] { 1 });

                    Assert.AreEqual(0, events.Count);
                }
            public void RemoveEventShouldBeRaised(int index, int count)
            {
                Setup();

                var events    = new List <NotifyCollectionChangedEventArgs>();
                var items     = new MvxObservableCollection <int[]>(new[] { new[] { 1, 2 }, new[] { 3 }, new[] { 4, 5, 6 } });
                var flatIndex = GetFlatSectionIndex(items, index);
                var flatItems = GetFlatItems(items.Take(index, count));

                var sut = new FlatObservableCollection <int>(items);

                sut.CollectionChanged += (_, args) => events.Add(args);

                items.RemoveRange(index, count);

                Assert.AreEqual(1, events.Count);
                Assert.AreEqual(NotifyCollectionChangedAction.Remove, events[0].Action);
                Assert.AreEqual(flatIndex, events[0].OldStartingIndex);
                Assert.AreEqual(flatItems, events[0].OldItems);
            }
            public void AddEventShouldBeRaised(int index, int[] newItem)
            {
                Setup();

                var events    = new List <NotifyCollectionChangedEventArgs>();
                var items     = new ObservableCollection <int[]>(new[] { new[] { 1, 2 }, new[] { 3 } });
                var flatIndex = GetFlatSectionIndex(items, index);
                var flatItems = GetFlatItems(new[] { newItem });

                var sut = new FlatObservableCollection <int>(items);

                sut.CollectionChanged += (_, args) => events.Add(args);

                items.Insert(index, newItem);

                Assert.AreEqual(1, events.Count);
                Assert.AreEqual(NotifyCollectionChangedAction.Add, events[0].Action);
                Assert.AreEqual(flatIndex, events[0].NewStartingIndex);
                Assert.AreEqual(flatItems, events[0].NewItems);
            }
            public void OutputCollectionShouldBeCorrect()
            {
                Setup();

                var items = new MvxObservableCollection <MvxObservableCollection <int> >
                {
                    new MvxObservableCollection <int> {
                        1, 2
                    }
                };

                var sut = new FlatObservableCollection <int>(items);

                items.Add(new MvxObservableCollection <int> {
                    3, 4, 5, 6
                });
                items[0].ReplaceWith(new[] { 1, 2, 0 });
                items[1].Add(8);
                items[0].Move(2, 0);
                items[1][4] = 7;

                Assert.AreEqual(Enumerable.Range(0, 8), sut);
            }