public void ReplaceRange_Always_CallsNotifyCollectionChangedOnlyOnce() { int timesCalled = 0; IEnumerable <Person> people = GetPeople(); _target.AddRange(people); _target.CollectionChanged += (sender, e) => timesCalled++; var peopleAgeFive = GetPeopleWithAge(5); _target.ReplaceRange(0, peopleAgeFive); Assert.AreEqual(1, timesCalled); }
public void ReplaceRangeOnSecond_FirstContainsNewItems_RaisesNotifyCollectionChangedWithOneAddAndRemoveActionsForEachItemReplacedRemoved2() { var people = new List <Person> { new Person(), new Person() }; _first = new ObservableCollection <Person> { _person1, _person2, people[0], people[1] }; var continuousSecondCollection = new ContinuousCollection <Person> { _person1, _person2 }; _target = new ExceptReadOnlyContinuousCollection <Person>(_first, continuousSecondCollection); var eventArgsList = TestUtilities.GetCollectionChangedEventArgsList(_target); continuousSecondCollection.ReplaceRange(0, people); Assert.AreEqual(3, eventArgsList.Count); TestUtilities.AssertAdd(eventArgsList[0], 2, _person1, _person2); TestUtilities.AssertRemove(eventArgsList[1], 0, people[0]); TestUtilities.AssertRemove(eventArgsList[2], 0, people[1]); }
public void ReplaceRangeOnSecond_Always_RaisesNotifyCollectionChangedWithReplaceAction() { var continuousSecondCollection = new ContinuousCollection <Person>(_first.ToList()); _target = new ConcatReadOnlyContinuousCollection <Person>(_first, continuousSecondCollection); var people = new List <Person> { new Person(), new Person() }; var eventArgsList = TestUtilities.GetCollectionChangedEventArgsList(_target); continuousSecondCollection.ReplaceRange(0, people); Assert.AreEqual(1, eventArgsList.Count); TestUtilities.AssertReplace(eventArgsList[0], 2, people.ToArray(), new[] { _person1, _person2 }); }
public void ReplaceRangeOnFirst_Always_RaisesNotifyCollectionChangedWithRemoveActionsForEachItemReplacedAndOneAdd() { var continuousFirstCollection = new ContinuousCollection <Person>(_first.ToList()); _target = new ExceptReadOnlyContinuousCollection <Person>(continuousFirstCollection, _second); var people = new List <Person> { new Person(), new Person() }; var eventArgsList = TestUtilities.GetCollectionChangedEventArgsList(_target); continuousFirstCollection.ReplaceRange(0, people); Assert.AreEqual(3, eventArgsList.Count); TestUtilities.AssertRemove(eventArgsList[0], 0, _person1); TestUtilities.AssertRemove(eventArgsList[1], 0, _person2); TestUtilities.AssertAdd(eventArgsList[2], 0, people.ToArray()); }
public void ReplaceRangeOnSecond_FirstContainsNewItems_RaisesNotifyCollectionChangedWithOneAddAndRemoveActionsForEachItemReplacedRemoved2() { var people = new List<Person> { new Person(), new Person() }; _first = new ObservableCollection<Person> { _person1, _person2, people[0], people[1] }; var continuousSecondCollection = new ContinuousCollection<Person> { _person1, _person2 }; _target = new ExceptReadOnlyContinuousCollection<Person>(_first, continuousSecondCollection); var eventArgsList = TestUtilities.GetCollectionChangedEventArgsList(_target); continuousSecondCollection.ReplaceRange(0, people); Assert.AreEqual(3, eventArgsList.Count); TestUtilities.AssertAdd(eventArgsList[0], 2, _person1, _person2); TestUtilities.AssertRemove(eventArgsList[1], 0, people[0]); TestUtilities.AssertRemove(eventArgsList[2], 0, people[1]); }
public void ReplaceRangeOnFirst_Always_RaisesNotifyCollectionChangedWithRemoveActionsForEachItemReplacedAndOneAdd() { var continuousFirstCollection = new ContinuousCollection<Person>(_first.ToList()); _target = new ExceptReadOnlyContinuousCollection<Person>(continuousFirstCollection, _second); var people = new List<Person> { new Person(), new Person() }; var eventArgsList = TestUtilities.GetCollectionChangedEventArgsList(_target); continuousFirstCollection.ReplaceRange(0, people); Assert.AreEqual(3, eventArgsList.Count); TestUtilities.AssertRemove(eventArgsList[0], 0, _person1); TestUtilities.AssertRemove(eventArgsList[1], 0, _person2); TestUtilities.AssertAdd(eventArgsList[2], 0, people.ToArray()); }