コード例 #1
0
        public void ClearAndAddRangeOnlyRaisesOneRemoveCollectionChangedEventAtTheEndIfNoItemsAreAddedAndSomeAreCleared()
        {
            var oc = new ObservableCollectionEx <string>
            {
                "Foo",
                "Bar"
            };

            var toAdd = new List <string>();

            var            itemCount    = 0;
            var            eventCount   = 0;
            var            action       = NotifyCollectionChangedAction.Add;
            IList <string> removedItems = null;

            oc.CollectionChanged += (sender, args) =>
            {
                ++eventCount;
                itemCount    = oc.Count;
                action       = args.Action;
                removedItems = args.OldItems.OfType <string>().ToList();
            };

            oc.ClearAndAddRange(toAdd);

            itemCount.Should().Be(0);
            eventCount.Should().Be(1);
            action.Should().Be(NotifyCollectionChangedAction.Remove);
            removedItems.ShouldBeEquivalentTo(new List <string>
            {
                "Foo",
                "Bar"
            });
        }
コード例 #2
0
        private async Task RefreshSessionAsync()
        {
            IList <Video>  videos;
            IList <Server> clients;

            try
            {
                videos = await GetNowPlayingAsync();
            }
            catch
            {
                videos = new List <Video>();
            }

            try
            {
                clients = await GetClientsAsync();
            }
            catch
            {
                clients = new List <Server>();
            }

            foreach (var video in videos)
            {
                var client = clients.FirstOrDefault(c => c.Key == video.Player.Key);
                if (client != null)
                {
                    video.Player.Client = client;
                }
            }

            _clients.ClearAndAddRange(clients);
            _nowPlaying.ClearAndAddRange(videos);
        }
コード例 #3
0
        public void ClearAndAddRangeOnlyRaisesOneResetCollectionChangedEventAtTheEndIfItemsAreClearedAndAdded()
        {
            var oc = new ObservableCollectionEx <string>
            {
                "Existing",
                "Items"
            };

            var toAdd = new List <string>
            {
                "Foo",
                "Bar"
            };

            var itemCount  = 0;
            var eventCount = 0;
            var action     = NotifyCollectionChangedAction.Add;

            oc.CollectionChanged += (sender, args) =>
            {
                ++eventCount;
                itemCount = oc.Count;
                action    = args.Action;
            };

            oc.ClearAndAddRange(toAdd);

            itemCount.Should().Be(2);
            eventCount.Should().Be(1);
            action.Should().Be(NotifyCollectionChangedAction.Reset);
        }
コード例 #4
0
        public void ClearAddRangeDoesntRaiseAnEventIfNothingIsAddedOrCleared()
        {
            var oc = new ObservableCollectionEx <string>();

            var toAdd = new List <string>();

            oc.MonitorEvents();
            oc.ClearAndAddRange(toAdd);
            oc.ShouldNotRaise("CollectionChanged");
        }
コード例 #5
0
        public void ClearAndAddRangeClearsTheCollectionThenAddsAllTheItems()
        {
            var oc = new ObservableCollectionEx <string>
            {
                "Existing",
                "Items"
            };

            var toAdd = new List <string>
            {
                "Foo",
                "Bar"
            };

            oc.ClearAndAddRange(toAdd);

            oc.Should().ContainInOrder(toAdd);
            oc.Should().OnlyContain(s => toAdd.Contains(s));
            oc.Count.Should().Be(2);
        }
コード例 #6
0
        public void ClearAndAddRangeWithANullCollectionThrows()
        {
            var oc = new ObservableCollectionEx <string>();

            oc.ClearAndAddRange(null);
        }
コード例 #7
0
        public void ClearAddRangeDoesntRaiseAnEventIfNothingIsAddedOrCleared()
        {
            var oc = new ObservableCollectionEx<string>();

            var toAdd = new List<string>();

            oc.MonitorEvents();
            oc.ClearAndAddRange(toAdd);
            oc.ShouldNotRaise("CollectionChanged");
        }
コード例 #8
0
 public void ClearAndAddRangeWithANullCollectionThrows()
 {
     var oc = new ObservableCollectionEx<string>();
     oc.ClearAndAddRange(null);
 }
コード例 #9
0
        public void ClearAndAddRangeOnlyRaisesOneResetCollectionChangedEventAtTheEndIfItemsAreClearedAndAdded()
        {
            var oc = new ObservableCollectionEx<string>
            {
                "Existing",
                "Items"
            };

            var toAdd = new List<string>
            {
                "Foo",
                "Bar"
            };

            var itemCount = 0;
            var eventCount = 0;
            var action = NotifyCollectionChangedAction.Add;

            oc.CollectionChanged += (sender, args) =>
            {
                ++eventCount;
                itemCount = oc.Count;
                action = args.Action;
            };

            oc.ClearAndAddRange(toAdd);

            itemCount.Should().Be(2);
            eventCount.Should().Be(1);
            action.Should().Be(NotifyCollectionChangedAction.Reset);
        }
コード例 #10
0
        public void ClearAndAddRangeOnlyRaisesOneRemoveCollectionChangedEventAtTheEndIfNoItemsAreAddedAndSomeAreCleared()
        {
            var oc = new ObservableCollectionEx<string>
            {
                "Foo",
                "Bar"
            };

            var toAdd = new List<string>();

            var itemCount = 0;
            var eventCount = 0;
            var action = NotifyCollectionChangedAction.Add;
            IList<string> removedItems = null;

            oc.CollectionChanged += (sender, args) =>
            {
                ++eventCount;
                itemCount = oc.Count;
                action = args.Action;
                removedItems = args.OldItems.OfType<string>().ToList();
            };

            oc.ClearAndAddRange(toAdd);

            itemCount.Should().Be(0);
            eventCount.Should().Be(1);
            action.Should().Be(NotifyCollectionChangedAction.Remove);
            removedItems.ShouldBeEquivalentTo(new List<string>
            {
                "Foo",
                "Bar"
            });
        }
コード例 #11
0
        public void ClearAndAddRangeClearsTheCollectionThenAddsAllTheItems()
        {
            var oc = new ObservableCollectionEx<string>
            {
                "Existing",
                "Items"
            };

            var toAdd = new List<string>
            {
                "Foo",
                "Bar"
            };

            oc.ClearAndAddRange(toAdd);

            oc.Should().ContainInOrder(toAdd);
            oc.Should().OnlyContain(s => toAdd.Contains(s));
            oc.Count.Should().Be(2);
        }