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" }); }
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); }
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); }
public void ClearAddRangeDoesntRaiseAnEventIfNothingIsAddedOrCleared() { var oc = new ObservableCollectionEx <string>(); var toAdd = new List <string>(); oc.MonitorEvents(); oc.ClearAndAddRange(toAdd); oc.ShouldNotRaise("CollectionChanged"); }
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); }
public void ClearAndAddRangeWithANullCollectionThrows() { var oc = new ObservableCollectionEx <string>(); oc.ClearAndAddRange(null); }
public void ClearAddRangeDoesntRaiseAnEventIfNothingIsAddedOrCleared() { var oc = new ObservableCollectionEx<string>(); var toAdd = new List<string>(); oc.MonitorEvents(); oc.ClearAndAddRange(toAdd); oc.ShouldNotRaise("CollectionChanged"); }
public void ClearAndAddRangeWithANullCollectionThrows() { var oc = new ObservableCollectionEx<string>(); oc.ClearAndAddRange(null); }
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); }
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" }); }
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); }