public void RemoveGroupInSource_ShoudRemoveGroup() { NotifyCollectionChangedEventArgs collectionChangedEventArgs = null; var collectionChangedEventsCount = 0; var isCountPropertyChangedEventRaised = false; var aItemsList = new[] { 1, 2, 3 }; var bItemsList = new[] { 2, 4, 6 }; var groups = new List <IGrouping <string, int> > { new IntGroup("A", aItemsList), new IntGroup("B", bItemsList), }; var source = new ObservableGroupedCollection <string, int>(groups); var readOnlyGroup = new ReadOnlyObservableGroupedCollection <string, int>(source); ((INotifyCollectionChanged)readOnlyGroup).CollectionChanged += (s, e) => { collectionChangedEventArgs = e; collectionChangedEventsCount++; }; ((INotifyPropertyChanged)readOnlyGroup).PropertyChanged += (s, e) => isCountPropertyChangedEventRaised = isCountPropertyChangedEventRaised || e.PropertyName == nameof(readOnlyGroup.Count); source.RemoveAt(1); readOnlyGroup.Should().ContainSingle(); readOnlyGroup.Count.Should().Be(1); readOnlyGroup.ElementAt(0).Key.Should().Be("A"); readOnlyGroup.ElementAt(0).Should().BeEquivalentTo(aItemsList, o => o.WithoutStrictOrdering()); isCountPropertyChangedEventRaised.Should().BeTrue(); collectionChangedEventArgs.Should().NotBeNull(); collectionChangedEventsCount.Should().Be(1); IsRemoveEventValid(collectionChangedEventArgs, bItemsList, 1).Should().BeTrue(); }
public void InsertGroupInSource_ShouldAddGroup(int insertionIndex) { NotifyCollectionChangedEventArgs collectionChangedEventArgs = null; var collectionChangedEventsCount = 0; var isCountPropertyChangedEventRaised = false; var itemsList = new[] { 1, 2, 3 }; var source = new ObservableGroupedCollection <string, int> { new ObservableGroup <string, int>("Group0", new[] { 10, 20, 30 }), new ObservableGroup <string, int>("Group1", new[] { 40, 50, 60 }) }; var readOnlyGroup = new ReadOnlyObservableGroupedCollection <string, int>(source); ((INotifyCollectionChanged)readOnlyGroup).CollectionChanged += (s, e) => { collectionChangedEventArgs = e; collectionChangedEventsCount++; }; ((INotifyPropertyChanged)readOnlyGroup).PropertyChanged += (s, e) => isCountPropertyChangedEventRaised = isCountPropertyChangedEventRaised || e.PropertyName == nameof(readOnlyGroup.Count); source.Insert(insertionIndex, new ObservableGroup <string, int>("Add", itemsList)); readOnlyGroup.Should().HaveCount(3); readOnlyGroup.Count.Should().Be(3); readOnlyGroup.ElementAt(insertionIndex).Key.Should().Be("Add"); readOnlyGroup.ElementAt(insertionIndex).Should().BeEquivalentTo(itemsList, o => o.WithoutStrictOrdering()); isCountPropertyChangedEventRaised.Should().BeTrue(); collectionChangedEventArgs.Should().NotBeNull(); collectionChangedEventsCount.Should().Be(1); IsAddEventValid(collectionChangedEventArgs, itemsList, addIndex: insertionIndex).Should().BeTrue(); }
public void Ctor_WithListOfReadOnlyObservableGroupSource_ShoudInitializeObject() { var source = new List <ReadOnlyObservableGroup <string, int> > { new ReadOnlyObservableGroup <string, int>("A", new[] { 1, 3, 5 }), new ReadOnlyObservableGroup <string, int>("B", new[] { 2, 4, 6 }), }; var readOnlyGroup = new ReadOnlyObservableGroupedCollection <string, int>(source); readOnlyGroup.Should().HaveCount(2); readOnlyGroup.Count.Should().Be(2); readOnlyGroup.ElementAt(0).Key.Should().Be("A"); readOnlyGroup.ElementAt(0).Should().BeEquivalentTo(new[] { 1, 3, 5 }, o => o.WithoutStrictOrdering()); readOnlyGroup.ElementAt(1).Key.Should().Be("B"); readOnlyGroup.ElementAt(1).Should().BeEquivalentTo(new[] { 2, 4, 6 }, o => o.WithoutStrictOrdering()); }