public void TestCollections() { var numbers = new EditableCollection <int>(); var results = new EditableCollection <int>(); using (results.SyncWith(numbers, x => x)) { var viewableResults = results.AsViewableCollection(); // when doing more than one change: // use beginupdate/endupdate to reduce syncing events numbers.BeginUpdate(); try { numbers.Add(4); numbers.Add(7); } finally { numbers.EndUpdate(); } // Magically results (x) are already added to the Results list CollectionAssert.AreEqual(numbers, viewableResults); // You can't add a result to the public Results list // Results.Add(17); // again: change source collection: numbers.Add(8); // synced results collection is already updated. CollectionAssert.AreEqual(numbers, viewableResults); } }
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); }
public void TestRemove() { var characteristic1 = new Characteristic() { CharacteristicName = "test1" }; var characteristic2 = new Characteristic() { CharacteristicName = "test2" }; var characteristic3 = new Characteristic() { CharacteristicName = "test3" }; var characteristic4 = new Characteristic() { CharacteristicName = "test4" }; var characteristic5 = new Characteristic() { CharacteristicName = "test5" }; var characteristics = new EditableCollection <Characteristic>(); characteristics.Add(characteristic1); characteristics.Add(characteristic2); characteristics.Add(characteristic3); characteristics.Add(characteristic4); characteristics.Add(characteristic5); var wrappedCharacteristics = new WrappedEditableCollection <CharacteristicUsage, Characteristic>(characteristics); characteristics.Count.Should().Be(5); wrappedCharacteristics.Count.Should().Be(characteristics.Count); characteristics[0].Should().Be(characteristic1); characteristics[1].Should().Be(characteristic2); characteristics[2].Should().Be(characteristic3); characteristics[3].Should().Be(characteristic4); characteristics[4].Should().Be(characteristic5); CompareList(characteristics, wrappedCharacteristics); wrappedCharacteristics.RemoveAt(2); characteristics.Count.Should().Be(4); CompareList(characteristics, wrappedCharacteristics); characteristics.RemoveAt(2); wrappedCharacteristics.Count.Should().Be(3); CompareList(characteristics, wrappedCharacteristics); wrappedCharacteristics.RemoveFirst(); characteristics.Count.Should().Be(2); CompareList(characteristics, wrappedCharacteristics); characteristics.RemoveFirst(); wrappedCharacteristics.Count.Should().Be(1); CompareList(characteristics, wrappedCharacteristics); }
public void TestTrackedCollectionSpeed() { var foo = new EditableCollection <Company>(); for (int i = 0; i < 10000; i++) { foo.Add(new Company()); } }
private void MigrateBankFiles(ICollection <BankFile> oldBankFiles, EditableCollection <NewModels.BankFile> newBankFiles) { foreach (var oldBankFile in oldBankFiles) { newBankFiles.Add(new NewModels.BankFile { Path = oldBankFile.Path, BankName = oldBankFile.BankName, ProgramRange = oldBankFile.ProgramRange }); } }
public void TestInit() { var characteristics = new EditableCollection <Characteristic>(); characteristics.Add(new Characteristic()); var wrappedCharacteristics = new WrappedEditableCollection <CharacteristicUsage, Characteristic>(characteristics); wrappedCharacteristics.Count.Should().Be(characteristics.Count); wrappedCharacteristics.First().Characteristic.Should().Be(characteristics.First()); }
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); }
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); }