public void TransformingConstructorTest() { var currentMethodName = this.GetCurrentMethodName(); var sourceCollection = new VirtualizingObservableCollection <Item>(new VirtualizingObservableCollectionSource <Item>()); var collectionSource = new VirtualizingObservableCollectionTransformingPagedSource <ItemTransformed, Item>(sourceCollection, sItem => new ItemTransformed(sItem), itemTransformed => itemTransformed.Item); var collection = new VirtualizingObservableCollection <ItemTransformed>(new PaginationManager <ItemTransformed>(collectionSource)); collection.CollectionChanged += this.collection_CollectionChanged; collection.PropertyChanged += this.collection_PropertyChanged; var iterations = 3; this._testStopwatch.Start($"{currentMethodName} "); for (var i = 0; i < iterations; i++) { sourceCollection.Add(_data[i]); } this._testStopwatch.Stop(); Assert.AreEqual(iterations, ItemTransformed.ObjectsConstructed); }
public void VirtualizingObservableCollectionTransformingPagedSourceConcurrencyTest() { var currentMethodName = this.GetCurrentMethodName(); var sourceCollection = new VirtualizingObservableCollection <Item>(new VirtualizingObservableCollectionSource <Item>()); var collectionSource = new VirtualizingObservableCollectionTransformingPagedSource <Item, Item>(sourceCollection, sItem => new Item(sItem.I), sItem => new Item(sItem.I)); var collection = new VirtualizingObservableCollection <Item>(collectionSource); collection.CollectionChanged += this.collection_CollectionChanged; collection.PropertyChanged += this.collection_PropertyChanged; this._testStopwatch.Start($"{currentMethodName} iterative add with notifications"); for (var i = 0; i < Iterations; i++) { sourceCollection.Add(_data[i]); } this._testStopwatch.Stop(); //this.CheckDataConsistency(collection); this.CheckDataConsistency(sourceCollection); Assert.AreEqual(Iterations, this.RemovedObjects.Count - collection.Count()); sourceCollection.Clear(); this._testStopwatch.Start($"{currentMethodName} parallel add with notifications"); Parallel.ForEach(_data, item => { sourceCollection.Add(item); }); this._testStopwatch.Stop(); //this.CheckDataConsistency(collection); this.CheckDataConsistency(sourceCollection); Assert.AreEqual(Iterations, this.RemovedObjects.Count - collection.Count()); sourceCollection.Clear(); collection.Clear(); this._testStopwatch.Start($"{currentMethodName} parallel add int without interlocked"); Parallel.ForEach(_data, item => { sourceCollection.Add(item); }); this._testStopwatch.Stop(); //this.CheckDataConsistency(collection); this.CheckDataConsistency(sourceCollection); Assert.AreEqual(Iterations, this.RemovedObjects.Count - collection.Count()); sourceCollection.Clear(); this._testStopwatch.Start($"{currentMethodName} Iterative add with parallel read"); Parallel.Invoke(() => this.Add(sourceCollection), () => this.Iteration(collection)); this._testStopwatch.Stop(); //this.CheckDataConsistency(collection); this.CheckDataConsistency(sourceCollection); Assert.AreEqual(Iterations, this.RemovedObjects.Count - collection.Count()); sourceCollection.Clear(); this._testStopwatch.Start($"{currentMethodName} Iterative add with parallel read and remove"); var task = Task.Factory.StartNew(() => this.RemoveRandom(sourceCollection)); Parallel.Invoke(() => this.Add(sourceCollection), () => this.Iteration(collection)); this._testStopwatch.Stop(); this.IsRandomCanceled = true; task.Wait(); //this.CheckDataConsistency(collection); this.CheckDataConsistency(sourceCollection); Assert.AreEqual(Iterations, this.RemovedObjects.Count - collection.Count()); this.RemovedObjects.Clear(); sourceCollection.Clear(); this._testStopwatch.Start($"{currentMethodName} Iterative add with parallel long read and remove"); task = Task.Factory.StartNew(() => this.RemoveRandom(sourceCollection)); Parallel.Invoke(() => this.Add(sourceCollection), () => this.IterationLong(collection)); this._testStopwatch.Stop(); this.IsRandomCanceled = true; task.Wait(); //this.CheckDataConsistency(collection); this.CheckDataConsistency(sourceCollection); Assert.AreEqual(Iterations, this.RemovedObjects.Count - collection.Count()); this.RemovedObjects.Clear(); sourceCollection.Clear(); }