public void TestEventsFired() { bool eventFired = false; var sampleData = GenerateSampleData(10); IEditableCollection <int> sourceCollection = new EditableCollection <int>(); IEditableCollection <int> targetCollection = new EditableCollection <int>(); var syncer = targetCollection.SyncWith(sourceCollection, (itemB) => itemB); syncer.Synced += delegate(object sender, SyncEventArgs <int, int> args) { eventFired = true; }; sourceCollection.Add(sampleData[0]); Assert.AreEqual(true, eventFired); eventFired = false; sourceCollection.Remove(sampleData[0]); Assert.AreEqual(true, eventFired); eventFired = false; sourceCollection.BeginUpdate(); sourceCollection.Add(sampleData[0]); sourceCollection.Add(sampleData[1]); sourceCollection.EndUpdate(); Assert.AreEqual(true, eventFired); }
protected void ListItemsRemoveRange(List <TViewModel> list) { foreach (var item in list) { _listItems.Remove(item); } RaisePropertiesChanged(nameof(ListItems)); }
public void TestBatchUpdate() { var sampleData = GenerateSampleData(10); IEditableCollection <int> sourceCollection = new EditableCollection <int>(); IEditableCollection <int> targetCollection = new EditableCollection <int>(); var syncer = targetCollection.SyncWith(sourceCollection, (itemB) => itemB); sourceCollection.BeginUpdate(); sourceCollection.Add(sampleData[0]); sourceCollection.Add(sampleData[1]); sourceCollection.Add(sampleData[2]); CollectionAssert.AreNotEqual(sourceCollection, targetCollection); sourceCollection.Remove(sampleData[0]); sourceCollection.Remove(sampleData[2]); CollectionAssert.AreNotEqual(sourceCollection, targetCollection); sourceCollection.EndUpdate(); CollectionAssert.AreEqual(sourceCollection, targetCollection); }
public void TestEditableCollectionAndEditableCollection() { var sampleData = GenerateSampleData(10); var sourceCollection = new EditableCollection <int>(); IEditableCollection <int> targetCollection = new EditableCollection <int>(); var syncer = targetCollection.SyncWith(sourceCollection, (itemB) => itemB); sourceCollection.AddRange(sampleData); CollectionAssert.AreEqual(sourceCollection, targetCollection); sourceCollection.Remove(sampleData[0]); CollectionAssert.AreEqual(sourceCollection, targetCollection); sourceCollection.Clear(); CollectionAssert.AreEqual(sourceCollection, targetCollection); }
public void TestSyncerChain() { var sampleData = GenerateSampleData(10); IEditableCollection <int> sourceCollection = new EditableCollection <int>(); IEditableCollection <int> interCollection = new EditableCollection <int>(); IEditableCollection <int> targetCollection = new EditableCollection <int>(); var syncer1 = targetCollection.SyncWith(interCollection, (itemB) => itemB); var syncer2 = interCollection.SyncWith(sourceCollection, (itemB) => itemB); sourceCollection.BeginUpdate(); sourceCollection.Add(sampleData[0]); sourceCollection.Add(sampleData[1]); sourceCollection.Add(sampleData[2]); CollectionAssert.AreNotEqual(sourceCollection, targetCollection); sourceCollection.Remove(sampleData[0]); CollectionAssert.AreNotEqual(sourceCollection, targetCollection); bool eventFired = false; syncer1.Synced += delegate(object sender, SyncEventArgs <int, int> args) { eventFired = true; }; sourceCollection.EndUpdate(); Assert.AreEqual(true, eventFired); CollectionAssert.AreEqual(sourceCollection, targetCollection); sourceCollection.AddRange(sampleData); CollectionAssert.AreEqual(sourceCollection, targetCollection); sourceCollection.Clear(); CollectionAssert.AreEqual(sourceCollection, targetCollection); }