public void WhereManyShouldWork() { var a = new CompositeSourceList <CompositeSourceList <int> >(); // Note that clist.Any(v => v>10) returns IObservable<bool> var b = from clist in a where clist.Any(v => v > 10) select clist; using (var s = b.Subscribe()) { var x = new CompositeSourceList <int>(); var y = new CompositeSourceList <int>(); a.Add(x); a.Add(y); s.Items.Count.Should().Be(0); x.Add(9); s.Items.Count.Should().Be(0); x.Add(11); s.Items.Count.Should().Be(1); y.Add(12); s.Items.Count.Should().Be(2); x.Remove(11); s.Items.Count.Should().Be(1); x.Remove(9); s.Items.Count.Should().Be(1); y.Remove(12); s.Items.Count.Should().Be(0); } }
public void ShouldWork() { var source0 = new CompositeSourceList <int>(); var source1 = new CompositeSourceList <int>(); var target = source0.Concat(source1); using (var observableCollection = target.CreateObservableCollection(EqualityComparer <int> .Default)) { observableCollection.Count.Should().Be(0); source0.Add(0); source1.Add(5); observableCollection.Should().Equal(0, 5); source0.Add(1); source1.Add(6); observableCollection.Should().Equal(0, 1, 5, 6); source0.Remove(1); observableCollection.Should().Equal(0, 5, 6); source1.Remove(5); observableCollection.Should().Equal(0, 6); source0.ReplaceAt(0, 10); observableCollection.Should().Equal(10, 6); } }
public void WhereShouldBePerformant() { var a = new CompositeSourceList <CompositeSourceList <CompositeSourceList <int> > >(); // Note that clist.Any(v => v>10) returns IObservable<bool> var b = from clist in a from t in clist where t.Any(v => v > 10) select t.Select(v => v + 1); using (var s = b.Subscribe()) { var x = new CompositeSourceList <CompositeSourceList <int> >(); var y = new CompositeSourceList <CompositeSourceList <int> >(); a.Add(x); a.Add(y); var xx = new CompositeSourceList <int>(); var yy = new CompositeSourceList <int>(); x.Add(xx); y.Add(yy); for (int i = 0; i < 100000; i++) { xx.Add(i); yy.Add(i + 1); } s.Items.Count.Should().BeGreaterThan(0); } }
public void ShouldWork() { var source0 = new CompositeSourceList<int>(); var source1 = new CompositeSourceList<int>(); var target = source0.Concat(source1); using (var observableCollection = target.CreateObservableCollection(EqualityComparer<int>.Default)) { observableCollection.Count.Should().Be(0); source0.Add(0); source1.Add(5); observableCollection.Should().Equal(0, 5); source0.Add(1); source1.Add(6); observableCollection.Should().Equal(0, 1, 5, 6); source0.Remove(1); observableCollection.Should().Equal(0, 5, 6); source1.Remove(5); observableCollection.Should().Equal(0, 6); source0.ReplaceAt(0, 10); observableCollection.Should().Equal(10, 6); } }
public void DynamicFilterShouldWork() { var data = new CompositeSourceList <int>(); var filters = new CompositeSourceList <Func <int, bool> >(); // Compose a dynamic filtering system by using a CompositeSourceList // to hold a filter. var target = from fn in filters from s in data where fn(s) select s; data.AddRange(new [] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); // Convert to an observable collection for testing purposes using (var oc = target.CreateObservableCollection(EqualityComparer <int> .Default)) { // Set the filter to be everything greater than 5 filters.Add(v => v > 5); oc.Should().Equal(6, 7, 8, 9, 10); // Set the filter to be everything less than 5 filters.ReplaceAt(0, v => v < 5); oc.Should().Equal(0, 1, 2, 3, 4); } }
public void ShouldWorkWithRangeOperators() { var source0 = new CompositeSourceList<int>(); var source1 = new CompositeSourceList<int>(); var target = source0.Concat(source1); using (var observableCollection = target.CreateObservableCollection(EqualityComparer<int>.Default)) { observableCollection.Count.Should().Be(0); source0.AddRange(new [] {0,1,2}); observableCollection.Should().Equal(0, 1,2); source0.Add(1); source1.Add(6); observableCollection.Should().Equal(0, 1, 2, 1, 6); source1.AddRange(new [] {3,4,5}); observableCollection.Should().Equal(0, 1, 2, 1, 6, 3, 4, 5); source0.InsertRangeAt(1, new [] {6,7}); observableCollection.Should().Equal(0, 6, 7, 1, 2, 1, 6, 3, 4, 5); source1.InsertRangeAt(1, new [] {6,7}); observableCollection.Should().Equal(0, 6, 7, 1, 2, 1, 6, 6, 7, 3, 4, 5); source0.Source.Should().Equal(0, 6, 7, 1, 2,1); source0.Replace(1,99); observableCollection.Should().Equal(0, 6, 7, 99, 2, 1, 6, 6, 7, 3, 4, 5); } }
public void WhereShouldBePerformant() { var a = new CompositeSourceList<CompositeSourceList<CompositeSourceList<int>>>(); // Note that clist.Any(v => v>10) returns IObservable<bool> var b = from clist in a from t in clist where t.Any(v => v > 10) select t.Select(v=>v+1); using (var s = b.Subscribe()) { var x = new CompositeSourceList<CompositeSourceList<int>>(); var y = new CompositeSourceList<CompositeSourceList<int>>(); a.Add(x); a.Add(y); var xx = new CompositeSourceList<int>(); var yy = new CompositeSourceList<int>(); x.Add(xx); y.Add(yy); for (int i = 0; i < 100000; i++) { xx.Add(i); yy.Add(i+1); } s.Items.Count.Should().BeGreaterThan(0); } }
public void WhereManyShouldWork() { var a = new CompositeSourceList<CompositeSourceList<int>>(); // Note that clist.Any(v => v>10) returns IObservable<bool> var b = from clist in a where clist.Any(v => v > 10) select clist; using (var s = b.Subscribe()) { var x = new CompositeSourceList<int>(); var y = new CompositeSourceList<int>(); a.Add(x); a.Add(y); s.Items.Count.Should().Be(0); x.Add(9); s.Items.Count.Should().Be(0); x.Add(11); s.Items.Count.Should().Be(1); y.Add(12); s.Items.Count.Should().Be(2); x.Remove(11); s.Items.Count.Should().Be(1); x.Remove(9); s.Items.Count.Should().Be(1); y.Remove(12); s.Items.Count.Should().Be(0); } }