public static void SetSourceReset()
        {
            using var view   = new ReadOnlySerialView <int>(new[] { 1, 2, 3 });
            using var actual = view.SubscribeAll();
            var newSource1 = new[] { 4, 5 };

            view.SetSource(newSource1);
            CollectionAssert.AreEqual(newSource1, view);
            var expected = new List <EventArgs>
            {
                CachedEventArgs.CountPropertyChanged,
                CachedEventArgs.IndexerPropertyChanged,
                CachedEventArgs.NotifyCollectionReset,
                CachedEventArgs.GetOrCreatePropertyChangedEventArgs("Source"),
            };

            CollectionAssert.AreEqual(expected, actual, EventArgsComparer.Default);

            var newSource2 = new ObservableCollection <int> {
                6, 7
            };

            view.SetSource(newSource2);
            CollectionAssert.AreEqual(newSource2, view);
            expected.AddRange(new EventArgs[]
            {
                CachedEventArgs.CountPropertyChanged,
                CachedEventArgs.IndexerPropertyChanged,
                CachedEventArgs.NotifyCollectionReset,
                CachedEventArgs.GetOrCreatePropertyChangedEventArgs("Source"),
            });
            CollectionAssert.AreEqual(expected, actual, EventArgsComparer.Default);
        }
        public static void SetSourceReplace()
        {
            using var view   = new ReadOnlySerialView <int>(new[] { 1, 2, 3 });
            using var actual = view.SubscribeAll();
            var newSource = new[] { 1, 2, 4 };

            view.SetSource(newSource);
            CollectionAssert.AreEqual(newSource, view);
            var expected = new List <EventArgs>
            {
                CachedEventArgs.IndexerPropertyChanged,
                Diff.CreateReplaceEventArgs(4, 3, 2),
                CachedEventArgs.GetOrCreatePropertyChangedEventArgs("Source"),
            };

            CollectionAssert.AreEqual(expected, actual, EventArgsComparer.Default);

            newSource = new[] { 5, 2, 4 };
            view.SetSource(newSource);
            CollectionAssert.AreEqual(newSource, view);
            expected.AddRange(
                new EventArgs[]
            {
                CachedEventArgs.IndexerPropertyChanged,
                Diff.CreateReplaceEventArgs(5, 1, 0),
                CachedEventArgs.GetOrCreatePropertyChangedEventArgs("Source"),
            });
            CollectionAssert.AreEqual(expected, actual, EventArgsComparer.Default);
        }
Exemplo n.º 3
0
        public void Updates()
        {
            var source = new ObservableCollection <int> {
                1, 2, 3
            };

            using (var expected = source.SubscribeAll())
            {
                using (var view = new ReadOnlySerialView <int>(source))
                {
                    using (var actual = view.SubscribeAll())
                    {
                        source.Add(4);
                        CollectionAssert.AreEqual(source, view);
                        CollectionAssert.AreEqual(expected, actual, EventArgsComparer.Default);

                        source.RemoveAt(0);
                        CollectionAssert.AreEqual(source, view);
                        CollectionAssert.AreEqual(expected, actual, EventArgsComparer.Default);

                        source.Clear();
                        CollectionAssert.AreEqual(source, view);
                        CollectionAssert.AreEqual(expected, actual, EventArgsComparer.Default);
                    }
                }
            }
        }
Exemplo n.º 4
0
        public void SetSourceAdd()
        {
            using (var view = new ReadOnlySerialView <int>(new[] { 1, 2, 3 }))
            {
                using (var actual = view.SubscribeAll())
                {
                    var newSource1 = new[] { 1, 2, 3, 4 };
                    view.SetSource(newSource1);
                    CollectionAssert.AreEqual(newSource1, view);
                    var expected = new List <EventArgs>
                    {
                        CachedEventArgs.CountPropertyChanged,
                        CachedEventArgs.IndexerPropertyChanged,
                        Diff.CreateAddEventArgs(4, 3),
                        CachedEventArgs.GetOrCreatePropertyChangedEventArgs("Source"),
                    };
                    CollectionAssert.AreEqual(expected, actual, EventArgsComparer.Default);

                    var newSource2 = new ObservableCollection <int> {
                        1, 2, 3, 4, 5
                    };
                    view.SetSource(newSource2);
                    CollectionAssert.AreEqual(newSource2, view);
                    expected.AddRange(
                        new EventArgs[]
                    {
                        CachedEventArgs.CountPropertyChanged,
                        CachedEventArgs.IndexerPropertyChanged,
                        Diff.CreateAddEventArgs(5, 4),
                        CachedEventArgs.GetOrCreatePropertyChangedEventArgs("Source"),
                    });
                    CollectionAssert.AreEqual(expected, actual, EventArgsComparer.Default);
                }
            }
        }
        public void SetSourceMove()
        {
            using (var view = new ReadOnlySerialView <int>(new[] { 1, 2, 3 }))
            {
                using (var actual = view.SubscribeAll())
                {
                    var newSource = new[] { 1, 3, 2 };
                    view.SetSource(newSource);
                    CollectionAssert.AreEqual(newSource, view);
                    var expected = new List <EventArgs>
                    {
                        CachedEventArgs.IndexerPropertyChanged,
                        Diff.CreateMoveEventArgs(2, 2, 1),
                        CachedEventArgs.GetOrCreatePropertyChangedEventArgs("Source")
                    };
                    CollectionAssert.AreEqual(expected, actual, EventArgsComparer.Default);

                    newSource = new[] { 3, 1, 2 };
                    view.SetSource(newSource);
                    CollectionAssert.AreEqual(newSource, view);
                    expected.AddRange(
                        new EventArgs[]
                    {
                        CachedEventArgs.IndexerPropertyChanged,
                        Diff.CreateMoveEventArgs(1, 1, 0),
                        CachedEventArgs.GetOrCreatePropertyChangedEventArgs("Source")
                    });
                    CollectionAssert.AreEqual(expected, actual, EventArgsComparer.Default);
                }
            }
        }
        public static void SetSourceToEqual()
        {
            using var view   = new ReadOnlySerialView <int>(new[] { 1, 2, 3 });
            using var actual = view.SubscribeAll();
            view.SetSource(new[] { 1, 2, 3 });
            CollectionAssert.AreEqual(new[] { 1, 2, 3 }, view);
            var expected = new[] { CachedEventArgs.GetOrCreatePropertyChangedEventArgs("Source") };

            CollectionAssert.AreEqual(expected, actual, EventArgsComparer.Default);
        }
Exemplo n.º 7
0
        public void ClearSource()
        {
            var ints = new ObservableCollection <int>(new[] { 1, 2, 3 });
            var view = new ReadOnlySerialView <int>(ints);

            var changes = view.SubscribeAll();

            view.ClearSource();
            CollectionAssert.IsEmpty(view);
            CollectionAssert.AreEqual(Diff.ResetEventArgsCollection, changes, EventArgsComparer.Default);
        }
        public static void SetSourceNull()
        {
            using var view   = new ReadOnlySerialView <int>(new[] { 1, 2, 3 });
            using var actual = view.SubscribeAll();
            view.SetSource(null);
            CollectionAssert.IsEmpty(view);
            var expected = new EventArgs[]
            {
                CachedEventArgs.CountPropertyChanged,
                CachedEventArgs.IndexerPropertyChanged,
                CachedEventArgs.NotifyCollectionReset,
                CachedEventArgs.GetOrCreatePropertyChangedEventArgs("Source"),
            };

            CollectionAssert.AreEqual(expected, actual, EventArgsComparer.Default);
        }
Exemplo n.º 9
0
        public void Updates()
        {
            var ints            = new ObservableCollection <int>(new[] { 1, 2, 3 });
            var expectedChanges = ints.SubscribeAll();

            var view          = new ReadOnlySerialView <int>(ints);
            var actualChanges = view.SubscribeAll();

            ints.Add(4);
            CollectionAssert.AreEqual(ints, view);
            CollectionAssert.AreEqual(expectedChanges, actualChanges, EventArgsComparer.Default);

            ints.RemoveAt(0);
            CollectionAssert.AreEqual(ints, view);
            CollectionAssert.AreEqual(expectedChanges, actualChanges, EventArgsComparer.Default);

            ints.Clear();
            CollectionAssert.AreEqual(ints, view);
            CollectionAssert.AreEqual(expectedChanges, actualChanges, EventArgsComparer.Default);
        }
Exemplo n.º 10
0
        public void ClearSource()
        {
            var source = new ObservableCollection <int> {
                1, 2, 3
            };

            using (var view = new ReadOnlySerialView <int>(source))
            {
                using (var actual = view.SubscribeAll())
                {
                    view.ClearSource();
                    CollectionAssert.IsEmpty(view);
                    var expected = new EventArgs[]
                    {
                        CachedEventArgs.CountPropertyChanged,
                        CachedEventArgs.IndexerPropertyChanged,
                        CachedEventArgs.NotifyCollectionReset,
                        CachedEventArgs.GetOrCreatePropertyChangedEventArgs("Source"),
                    };
                    CollectionAssert.AreEqual(expected, actual, EventArgsComparer.Default);
                }
            }
        }