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 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.º 6
0
        public void SetSourceNull()
        {
            var ints = new ObservableCollection <int>(new[] { 1, 2, 3 });
            var view = new ReadOnlySerialView <int>(ints);

            var changes = view.SubscribeAll();

            view.SetSource(null);
            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);
        }