public void EachItemChangeInokesTheCallback() { var messages = new List <ItemChange <Person> >(); var messageWriter = _source .Connect() .ForEachItemChange(messages.Add) .Subscribe(); _source.AddRange(new RandomPersonGenerator().Take(100)); Assert.AreEqual(100, messages.Count); messageWriter.Dispose(); }
public void ChangeFilter() { var people = Enumerable.Range(1, 100).Select(i => new Person("P" + i, i)).ToList(); _source.AddRange(people); Assert.AreEqual(80, _results.Data.Count, "Should be 80 people in the cache"); _filter.Change(p => p.Age <= 50); Assert.AreEqual(50, _results.Data.Count, "Should be 50 people in the cache"); Assert.AreEqual(2, _results.Messages.Count, "Should be 2 update messages"); // Assert.AreEqual(50, _results.Messages[1].Removes, "Should be 50 removes in the second message"); // Assert.AreEqual(20, _results.Messages[1].Adds, "Should be 20 adds in the second message"); Assert.IsTrue(_results.Data.Items.All(p => p.Age <= 50)); }
public async Task BatchOfUniqueUpdates() { var people = Enumerable.Range(1, 100).Select(i => new Person("Name" + i, i)).ToArray(); _source.AddRange(people); Assert.AreEqual(1, _results.Messages.Count, "Should be 1 updates"); Assert.AreEqual(100, _results.Messages[0].Adds, "Should return 100 adds"); var tasks = people.Select(_transformFactory); var result = await Task.WhenAll(tasks); var transformed = result.OrderBy(p => p.Age).ToArray(); CollectionAssert.AreEqual(transformed, _results.Data.Items.OrderBy(p => p.Age), "Incorrect transform result"); }
public void AddAndRemoveLists() { _source1.AddRange(Enumerable.Range(1, 5)); _source2.AddRange(Enumerable.Range(6, 5)); _source3.AddRange(Enumerable.Range(1, 5)); _source.Add(_source1.Connect()); _source.Add(_source2.Connect()); _source.Add(_source3.Connect()); var result = Enumerable.Range(6, 5); _results.Data.Count.Should().Be(5); _results.Data.Items.ShouldAllBeEquivalentTo(result); _source.RemoveAt(0); result = Enumerable.Range(1, 5).Union(Enumerable.Range(6, 5)); _results.Data.Count.Should().Be(10); _results.Data.Items.ShouldAllBeEquivalentTo(result); _source.Add(_source1.Connect()); result = Enumerable.Range(6, 5); _results.Data.Count.Should().Be(5); _results.Data.Items.ShouldAllBeEquivalentTo(result); }
public void CanHandleABatchOfUpdates() { var remover = _source.ExpireAfter(p => TimeSpan.FromMilliseconds(100), _scheduler).Subscribe(); const int size = 100; Person[] items = Enumerable.Range(1, size).Select(i => new Person($"Name.{i}", i)).ToArray(); _source.AddRange(items); _scheduler.AdvanceBy(TimeSpan.FromMilliseconds(200).Ticks); remover.Dispose(); _results.Data.Count.Should().Be(0, "Should be no data in the cache"); _results.Messages.Count.Should().Be(2, "Should be 2 updates"); _results.Messages[0].Adds.Should().Be(100, "Should be 100 adds in the first message"); _results.Messages[1].Removes.Should().Be(100, "Should be 100 removes in the second message"); }
public void AddAndRemoveLists() { _source1.AddRange(Enumerable.Range(1, 5)); _source2.AddRange(Enumerable.Range(6, 5)); _source3.AddRange(Enumerable.Range(1, 5)); _source.Add(_source1.Connect()); _source.Add(_source2.Connect()); _source.Add(_source3.Connect()); var result = Enumerable.Range(6, 5); Assert.AreEqual(5, _results.Data.Count); CollectionAssert.AreEquivalent(result, _results.Data.Items); _source.RemoveAt(0); result = Enumerable.Range(1, 5).Union(Enumerable.Range(6, 5)); Assert.AreEqual(10, _results.Data.Count); CollectionAssert.AreEquivalent(result, _results.Data.Items); _source.Add(_source1.Connect()); result = Enumerable.Range(6, 5); Assert.AreEqual(5, _results.Data.Count); CollectionAssert.AreEquivalent(result, _results.Data.Items); }
public void CanCast() { _source.AddRange(Enumerable.Range(1, 10)); Assert.AreEqual(10, _results.Data.Count); _source.Clear(); Assert.AreEqual(0, _results.Data.Count); }
public void CanCast() { _source.AddRange(Enumerable.Range(1, 10)); _results.Data.Count.Should().Be(10); _source.Clear(); _results.Data.Count.Should().Be(0); }
public override void Select(IEnumerable <Tag> tags) { if (!PermitNewTags) { tags = tags.Intersect(Tagpool.Items); } selection.AddRange(tags); }
/// <summary> /// Initializes a new instance of the <see cref="RecyclerViewAdapter{TViewModel}"/> class. /// </summary> /// <param name="backingList">The backing list.</param> protected RecyclerViewAdapter(IEnumerable <TViewModel> backingList) { _list = new SourceList <TViewModel>(); _list.AddRange(backingList); _inner = _list .Connect() .Subscribe(); }
public void BigList() { var generator = new RandomPersonGenerator(); var people = generator.Take(10000).ToArray(); _source.AddRange(people); Console.WriteLine(); }
public void VirtualiseInitial() { var people = _generator.Take(100).ToArray(); _source.AddRange(people); var expected = people.Take(25).ToArray(); _results.Data.Items.ShouldAllBeEquivalentTo(expected); }
public void VirtualiseInitial() { var people = _generator.Take(100).ToArray(); _source.AddRange(people); var expected = people.Take(25).ToArray(); CollectionAssert.AreEqual(expected, _results.Data.Items); }
public void AddAndRemoveLists() { _source1.AddRange(Enumerable.Range(1, 5)); _source2.AddRange(Enumerable.Range(6, 5)); _source3.AddRange(Enumerable.Range(100, 5)); _source.Add(_source1.Connect()); _source.Add(_source2.Connect()); _source.Add(_source3.Connect()); var result = Enumerable.Range(1, 5); _results.Data.Count.Should().Be(5); _results.Data.Items.Should().BeEquivalentTo(result); _source2.Edit( innerList => { innerList.Clear(); innerList.AddRange(Enumerable.Range(3, 5)); }); result = Enumerable.Range(1, 2); _results.Data.Count.Should().Be(2); _results.Data.Items.Should().BeEquivalentTo(result); _source.RemoveAt(1); result = Enumerable.Range(1, 5); _results.Data.Count.Should().Be(5); _results.Data.Items.Should().BeEquivalentTo(result); _source.Add(_source2.Connect()); result = Enumerable.Range(1, 2); _results.Data.Count.Should().Be(2); _results.Data.Items.Should().BeEquivalentTo(result); //remove root except _source.RemoveAt(0); result = Enumerable.Range(100, 5); _results.Data.Count.Should().Be(5); _results.Data.Items.Should().BeEquivalentTo(result); }
public void EverythingIsUnsubscribedWhenStreamIsDisposed() { _source.AddRange(Enumerable.Range(1, 10).Select(i => new SubscribeableObject(i))); _source.Clear(); Assert.AreEqual(2, _results.Messages.Count, "Should be 2 updates"); var items = _results.Messages[0].SelectMany(x => x.Range); Assert.IsTrue(items.All(d => !d.IsSubscribed)); }
public void AddRange() { var itemstoadd = Enumerable.Range(1, 100).Select(i => new Person("P" + i, i)).ToList(); _source.AddRange(itemstoadd); _results.Messages.Count.Should().Be(1, "Should be 1 updates"); _results.Messages[0].First().Reason.Should().Be(ListChangeReason.AddRange, "Should be 1 updates"); _results.Data.Count.Should().Be(80, "Should be 50 item in the cache"); }
public void ReplaceWithMatch() { var itemstoadd = Enumerable.Range(1, 100).Select(i => new Person("P" + i, i)).ToList(); _source.AddRange(itemstoadd); _source.ReplaceAt(0, new Person("Adult1", 50)); _results.Data.Count.Should().Be(81); }
public void ClearsForNewSource() { var inital = Enumerable.Range(1, 100).ToArray(); _source.AddRange(inital); _results.Data.Count.Should().Be(100); var newSource = new SourceList <int>(); _switchable.OnNext(newSource); _results.Data.Count.Should().Be(0); newSource.AddRange(inital); _results.Data.Count.Should().Be(100); var nextUpdates = Enumerable.Range(100, 100).ToArray(); newSource.AddRange(nextUpdates); _results.Data.Count.Should().Be(200); }
public void AddRange() { var frientofchild1 = new PersonWithRelations("Friend1", 10); var child1 = new PersonWithRelations("Child1", 10, new[] { frientofchild1 }); var child2 = new PersonWithRelations("Child2", 8); var child3 = new PersonWithRelations("Child3", 8); var mother = new PersonWithRelations("Mother", 35, new[] { child1, child2, child3 }); _source.Add(mother); var child4 = new PersonWithRelations("Child4", 1); var child5 = new PersonWithRelations("Child5", 2); var anotherRelative1 = new PersonWithRelations("Another1", 2, new[] { child4, child5 }); var child6 = new PersonWithRelations("Child6", 1); var child7 = new PersonWithRelations("Child7", 2); var anotherRelative2 = new PersonWithRelations("Another2", 2, new[] { child6, child7 }); _source.AddRange(new[] { anotherRelative1, anotherRelative2 }); _results.Data.Count.Should().Be(8); _results.Data.Items.ShouldAllBeEquivalentTo(new[] { child1, child2, child3, frientofchild1, child4, child5, child6, child7 }); }
public void SortInitialBatch() { var people = _generator.Take(100).ToArray(); _source.AddRange(people); Assert.AreEqual(100, _results.Data.Count, "Should be 100 people in the cache"); var expectedResult = people.OrderBy(p => p, _comparer); var actualResult = _results.Data.Items; CollectionAssert.AreEquivalent(expectedResult, actualResult); }
public void SortInitialBatch() { var people = _generator.Take(100).ToArray(); _source.AddRange(people); _results.Data.Count.Should().Be(100, "Should be 100 people in the cache"); var expectedResult = people.OrderBy(p => p, _comparer); var actualResult = _results.Data.Items; actualResult.ShouldAllBeEquivalentTo(expectedResult); }
public void LoadFrom(string path, ISourceList <DataComponent> to) { _lastCollection = to; _last = path; var targetPath = GetFullPath(path); if (!File.Exists(targetPath)) { return; } try { JObject obj; try { obj = JObject.Parse(File.ReadAllText(targetPath)); } catch { obj = JObject.Parse(File.ReadAllText(targetPath + 1)); } to.AddRange(from property in obj.Properties() let blue = _blueprintDescriptors.FirstOrDefault(bd => bd.Category == property.Name) ?? _blueprintDescriptors.First(bd => bd.Category == "general") let jValue = (JArray)property.Value from entry in jValue select blue.Create(entry.Value <string>("Category"), entry.Value <string>("Value"))); } catch { try { File.Delete(targetPath); } catch (IOException) { } } finally { _eventSystem.Publish(new DataLoadedEvent()); } }
public IconProvider(IDefaultIconSelector defaultIconSelector) { DefaultIconSelector = defaultIconSelector; Icons = _icons.AsObservableList(); var icons = Enum.GetNames(typeof(PackIconKind)) .Select(str => { var value = (PackIconKind)Enum.Parse(typeof(PackIconKind), str); return(new IconDescription(value, str)); }); _icons.AddRange(icons); _cleanUp = new CompositeDisposable(Icons, _icons); }
public void BatchOfUniqueUpdates() { var people = Enumerable.Range(1, 100).Select(i => new Person("Name" + i, i)).ToArray(); _source.AddRange(people); _results.Messages.Count.Should().Be(1, "Should be 1 updates"); _results.Messages[0].Adds.Should().Be(80, "Should return 80 adds"); var filtered = people.Where(p => p.Age > 20).OrderBy(p => p.Age).ToArray(); _results.Data.Items.OrderBy(p => p.Age).Should().BeEquivalentTo(filtered, "Incorrect Filter result"); }
public void ChangeFilter() { var people = Enumerable.Range(1, 100).Select(i => new Person("P" + i, i)).ToList(); _source.AddRange(people); _results.Data.Count.Should().Be(80, "Should be 80 people in the cache"); _filter.OnNext(p => p.Age <= 50); _results.Data.Count.Should().Be(50, "Should be 50 people in the cache"); _results.Messages.Count.Should().Be(2, "Should be 2 update messages"); _results.Data.Items.All(p => p.Age <= 50).Should().BeTrue(); }
public void RemoveRandomSorts() { //seems an odd test but believe me it catches exceptions when sorting on primitives var items = Enumerable.Range(1, 100).OrderBy(_ => Guid.NewGuid()).ToArray(); _source.AddRange(items); _results.Data.Count.Should().Be(100); var expectedResult = items.OrderBy(p => p, _comparer); var actualResult = _results.Data.Items; actualResult.Should().BeEquivalentTo(expectedResult); for (int i = 0; i < 50; i++) { _source.Remove(i); } }
public void AddAndRemoveLists() { _source1.AddRange(Enumerable.Range(1, 5)); _source2.AddRange(Enumerable.Range(6, 5)); _source3.AddRange(Enumerable.Range(100, 5)); _source.Add(_source1.Connect()); _source.Add(_source2.Connect()); _source.Add(_source3.Connect()); var result = Enumerable.Range(1, 5); Assert.AreEqual(5, _results.Data.Count); CollectionAssert.AreEquivalent(result, _results.Data.Items); _source2.Edit(innerList => { innerList.Clear(); innerList.AddRange(Enumerable.Range(3, 5)); }); result = Enumerable.Range(1, 2); Assert.AreEqual(2, _results.Data.Count); CollectionAssert.AreEquivalent(result, _results.Data.Items); _source.RemoveAt(1); result = Enumerable.Range(1, 5); Assert.AreEqual(5, _results.Data.Count); CollectionAssert.AreEquivalent(result, _results.Data.Items); _source.Add(_source2.Connect()); result = Enumerable.Range(1, 2); Assert.AreEqual(2, _results.Data.Count); CollectionAssert.AreEquivalent(result, _results.Data.Items); //remove root except _source.RemoveAt(0); result = Enumerable.Range(100, 5); Assert.AreEqual(5, _results.Data.Count); CollectionAssert.AreEquivalent(result, _results.Data.Items); }
public void FormNewListFromChanges() { _source.Clear(); _source.AddRange(Enumerable.Range(1, 100)); // Collect preview messages about even numbers only var aggregator = _source.Preview(i => i % 2 == 0).AsAggregator(); _source.RemoveAt(10); _source.RemoveRange(10, 5); // Trigger changes _source.Add(1); _source.Add(2); Assert.True(aggregator.Messages.Count == 1); Assert.True(aggregator.Messages[0].Count == 1); Assert.True(aggregator.Messages[0].First().Item.Current == 2); Assert.True(aggregator.Messages[0].First().Reason == ListChangeReason.Add); // Cleanup aggregator.Dispose(); }
public PrismModuleStatusViewModel( IModuleCatalog moduleCatalog, IModuleManager moduleManager) { IsVisible = AppArguments.Instance.IsDebugMode; this.moduleManager = moduleManager; moduleList .Connect() .Bind(out var modules) .Subscribe() .AddTo(Anchors); Modules = modules; Observable.FromEventPattern<EventHandler<LoadModuleCompletedEventArgs>, LoadModuleCompletedEventArgs>( h => moduleManager.LoadModuleCompleted += h, h => moduleManager.LoadModuleCompleted -= h) .StartWithDefault() .Select(() => moduleCatalog.Modules.Select(x => new PrismModuleStatus(x)).ToArray()) .DistinctUntilChanged() .Subscribe( items => { moduleList.Clear(); moduleList.AddRange(items); }) .AddTo(Anchors); allModulesLoaded = modules.ToObservableChangeSet() .Select(() => modules.Any() && modules.All(x => x.IsLoaded)) .ToPropertyHelper(this, x => x.AllModulesLoaded) .AddTo(Anchors); LoadModuleCommand = CommandWrapper.Create<PrismModuleStatus>(LoadModuleCommandExecuted, LoadModuleCommandCanExecute); }
public void AddRange() { _source.AddRange(Enumerable.Range(1, 5)); _results.Data.Items.ShouldAllBeEquivalentTo(new[] { 5, 4, 3, 2, 1 }); }