public void MergeManyShouldWork() { var a = new SourceList <int>(); var b = new SourceList <int>(); var c = new SourceList <int>(); var parent = new SourceList <SourceList <int> >(); parent.Add(a); parent.Add(b); parent.Add(c); var d = parent.Connect().MergeMany(e => e.Connect().RemoveIndex()).AsObservableList(); 0.Should().Be(d.Count); a.Add(1); 1.Should().Be(d.Count); a.Add(2); 2.Should().Be(d.Count); b.Add(3); 3.Should().Be(d.Count); b.Add(5); 4.Should().Be(d.Count); new[] { 1, 2, 3, 5 }.Should().BeEquivalentTo(d.Items); b.Clear(); // Fails below 2.Should().Be(d.Count); new[] { 1, 2 }.Should().BeEquivalentTo(d.Items); }
public FriendListViewModel(Tox tox) { var friends = new SourceList <uint>(); foreach (var friend in tox.Friends) { friends.Add(friend); tox.AddFriendNoRequest(tox.GetFriendPublicKey(friend, out _), out _); } this.Add = ReactiveCommand.Create <uint>(friendNumber => { friends.Add(friendNumber); }); ReadOnlyObservableCollection <FriendListEntryViewModel> entries; friends.Connect() .Transform(number => new FriendListEntryViewModel(tox, number)) .Bind(out entries) .Subscribe(); this.Friends = entries; this.Friends.ToObservableChangeSet() .MergeMany(x => x.Remove) .Subscribe(number => { if (tox.DeleteFriend(number, out _)) { friends.Remove(number); } }); }
public void SubscribeToPropertyChangeForAllItemsInList(bool notifyOnInitialValue) { var lastChange = new PropertyValue <Person, int>(null, -1); var source = new SourceList <Person>(); source.Connect().WhenPropertyChanged(p => p.Age, notifyOnInitialValue).Subscribe(c => lastChange = c); var person = new Person("Name", 10); var anotherPerson = new Person("AnotherName", 10); source.Add(person); source.Add(anotherPerson); if (notifyOnInitialValue) { anotherPerson.Should().Be(lastChange.Sender); 10.Should().Be(lastChange.Value); } else { lastChange.Sender.Should().BeNull(); (-1).Should().Be(lastChange.Value); } person.Age = 12; person.Should().Be(lastChange.Sender); 12.Should().Be(lastChange.Value); anotherPerson.Age = 13; anotherPerson.Should().Be(lastChange.Sender); 13.Should().Be(lastChange.Value); }
public MainPage() { this.InitializeComponent(); _components.Add(new ViewComponents(spButtonDemo, RadioDemo, SetupButtonClicks())); _components.Add(new ViewComponents(lvData, RadioPosition, SetupPointerMovedSample())); _components.Add(new ViewComponents(DynamicDataFiltering, RadioDDFiltering, SetupFilteringAnimals())); _components.Add(new ViewComponents(spMovingBlock, RadioMovingBlock, SetupMovingBlock())); // RxUI exposes all platform events this.Events().Loaded .Select (_ => _components .Connect() .DisposeMany() .MergeMany(x => x.CheckChanged.IsTrue().Select(__ => x.MyDemo)) .Switch() .TakeUntil(this.Events().Unloaded) ) .Switch() .Subscribe(); }
public void DynamicFilter() { var schedulerProvider = new TestSchedulerProvider(); using (var sourceList = new SourceList <Animal>()) using (var sut = new DynamicFilter(sourceList, schedulerProvider)) { //start the scheduler schedulerProvider.TestScheduler.Start(); //add items sourceList.AddRange(_items); sut.Filtered.Items.ShouldAllBeEquivalentTo(_items); sut.Filtered.Count.Should().Be(_items.Length); //set a filter sut.AnimalFilter = "Dog"; schedulerProvider.TestScheduler.Start(); sut.Filtered.Items.ShouldAllBeEquivalentTo(_items.Where(a => a.Type == "Dog")); sut.Filtered.Count.Should().Be(2); //add a new dog to show it is included in the result set sourceList.Add(new Animal("George", "Dog", AnimalFamily.Mammal)); sut.Filtered.Count.Should().Be(3); //add a new bird to show it is included in the result set sourceList.Add(new Animal("Peter", "Parrot", AnimalFamily.Bird)); sut.Filtered.Count.Should().Be(3); } }
public void BufferInitial() { var scheduler = new TestScheduler(); using (var cache = new SourceList <Person>()) using (var aggregator = cache.Connect().BufferInitial(TimeSpan.FromSeconds(1), scheduler).AsAggregator()) { foreach (var item in People) { cache.Add(item); } aggregator.Data.Count.Should().Be(0); aggregator.Messages.Count.Should().Be(0); scheduler.Start(); aggregator.Data.Count.Should().Be(10_000); aggregator.Messages.Count.Should().Be(1); cache.Add(new Person("_New", 1)); aggregator.Data.Count.Should().Be(10_001); aggregator.Messages.Count.Should().Be(2); } }
public CommandItem AddGlobalCommand(string menuName, string cmdName, string cmdFunc, IViewModel vm, bool addSeparator = false) { var root = CheckRoot(menuName); var exsts = Commands.Items .Where(x => x.Parent == root.Root && x.Name == cmdName) .Count(); if (exsts > 0) { throw new Exception("Command already exists"); } CommandItem ci = new CommandItem { MenuName = menuName, VM = vm, VMType = vm.GetType(), Name = cmdName, IsChecked = false, Type = CommandType.Global, CmdFunc = cmdFunc, Parent = root.Root, Separator = addSeparator, Visible = true }; Commands.Add(ci); return(ci); }
public void SubscribeToPropertyChangeForAllItemsInList([Values(true, false)] bool notifyOnInitialValue) { var lastChange = new PropertyValue <Person, int>(null, -1); var source = new SourceList <Person>(); source.Connect().WhenPropertyChanged(p => p.Age, notifyOnInitialValue).Subscribe(c => lastChange = c); var person = new Person("Name", 10); var anotherPerson = new Person("AnotherName", 10); source.Add(person); source.Add(anotherPerson); if (notifyOnInitialValue) { Assert.That(lastChange.Sender, Is.EqualTo(anotherPerson)); Assert.That(lastChange.Value, Is.EqualTo(10)); } else { Assert.That(lastChange.Sender, Is.Null); Assert.That(lastChange.Value, Is.EqualTo(-1)); } person.Age = 12; Assert.That(lastChange.Sender, Is.EqualTo(person)); Assert.That(lastChange.Value, Is.EqualTo(12)); anotherPerson.Age = 13; Assert.That(lastChange.Sender, Is.EqualTo(anotherPerson)); Assert.That(lastChange.Value, Is.EqualTo(13)); }
public CronCategory(int type) { expressionParts = new SourceList <CronCategoryPart>(); expressionParts.Add(new CronCategoryPart("*")); expressionParts.Connect() .Bind(out var parts) .WhenAnyPropertyChanged() .Subscribe(_ => { this.RaisePropertyChanged(); }); ExpressionParts = parts; DescriprionType = (TimeType)type; AddCategoryCommand = ReactiveCommand.Create(() => expressionParts.Add(new CronCategoryPart(""))); RemoveCategoryCommand = ReactiveCommand.Create <CronCategoryPart>( parseCategory => expressionParts.Remove(parseCategory)); }
public void AddToSourceAddsToDestination() { var person = new Person("Adult1", 50); _source.Add(person); Assert.AreEqual(1, _collection.Count, "Should be 1 item in the collection"); Assert.AreEqual(person, _collection.First(), "Should be same person"); }
public void AddToSourceAddsToDestination() { var person = new Person("Adult1", 50); _source.Add(person); _collection.Count.Should().Be(1, "Should be 1 item in the collection"); _collection.First().Should().Be(person, "Should be same person"); }
// Add the currently inFlight unit to the specified semester if it is legal to do so, otherwise return it to where it came from private void Schedule(Semester semester) { if (CanScheduleIn(semester)) { plan.Add(new UnitInPlan(inFlightUnitCode, inFlightStudyArea, semester)); } else if (oldPosition != null) { plan.Add(new UnitInPlan(inFlightUnitCode, inFlightStudyArea, oldPosition)); // put it back where it used to be } }
public TotalSummaryViewModel(IScreen hostScreen, ITotalSummaryService fundSummaryService, ITotalSummaryService equitySummaryService, ITotalSummaryService bondSummaryService) { var myList = new SourceList <SummaryTemplateViewModel>(); myList.Add(new SummaryTemplateViewModel("Equity", equitySummaryService)); myList.Add(new SummaryTemplateViewModel("Bond", bondSummaryService)); myList.Add(new SummaryTemplateViewModel("Fund", fundSummaryService)); Observable.ObserveOn(myList.Connect(), RxApp.MainThreadScheduler).Bind(out _data).DisposeMany().Subscribe(); HostScreen = hostScreen; }
public SearchPageViewModel(NavigationStateViewModel navigationState, WalletManagerViewModel walletManager, AddWalletPageViewModel addWalletPage, SettingsPageViewModel settingsPage, HomePageViewModel homePage) : base(navigationState) { Title = "Search"; _showSettings = true; _showWallets = false; var generalCategory = new SearchCategory("General", 0); var generalCategorySource = new SourceList <SearchItemViewModel>(); generalCategorySource.Add(CreateHomeSearchItem(generalCategory, 0, homePage)); generalCategorySource.Add(CreateSettingsSearchItem(generalCategory, 1, settingsPage)); generalCategorySource.Add(CreateAddWalletSearchItem(generalCategory, 2, addWalletPage)); var settingsCategory = new SearchCategory("Settings", 1); var settingsCategorySource = new SourceList <SearchItemViewModel>(); settingsCategorySource.AddRange(CreateSettingsSearchItems(settingsCategory, settingsPage)); var walletCategory = new SearchCategory("Wallets", 2); var wallets = walletManager.Items .ToObservableChangeSet() .Transform(x => CreateWalletSearchItem(walletCategory, 0, x)) .Sort(SortExpressionComparer <SearchItemViewModel> .Ascending(i => i.Title)); var searchItems = generalCategorySource.Connect(); if (_showSettings) { searchItems = searchItems.Merge(settingsCategorySource.Connect()); } if (_showWallets) { searchItems = searchItems.Merge(wallets); } var queryFilter = this.WhenValueChanged(t => t.SearchQuery) .Throttle(TimeSpan.FromMilliseconds(100)) .Select(SearchQueryFilter) .DistinctUntilChanged(); searchItems .Filter(queryFilter) .GroupWithImmutableState(x => x.Category) .Transform(grouping => new SearchResult(grouping.Key, grouping.Items.OrderBy(x => x.Order).ThenBy(x => x.Title))) .Sort(SortExpressionComparer <SearchResult> .Ascending(i => i.Category.Order).ThenByAscending(i => i.Category.Title)) .ObserveOn(RxApp.MainThreadScheduler) .Bind(out _searchResults) .AsObservableList(); }
public FriendConversationViewModel(Tox tox, uint friendNumber) { var messages = new SourceList <MessageViewModel>(); messages.Connect() .AutoRefresh(x => x.Read) .Filter(x => !x.Read) .AsObservableList() .CountChanged .ToPropertyEx(this, x => x.UnreadCount); this.SendMessage = ReactiveCommand.Create <string>(msg => { if (!string.IsNullOrWhiteSpace(msg)) { _ = tox.SendMessage(friendNumber, msg, ToxMessageType.Message, out _); messages.Add(new MessageViewModel("Me", msg, DateTime.Now.Ticks)); } }); ReadOnlyObservableCollection <MessageViewModel> msgs; messages.Connect() .Bind(out msgs) .Subscribe(); this.Messages = msgs; this.SendTypedMessage = ReactiveCommand.Create(() => { var msg = this.InputMessage; this.InputMessage = string.Empty; return(msg); }, this.WhenAnyValue(x => x.InputMessage, (string s) => !string.IsNullOrWhiteSpace(s))); this.WhenAnyValue(x => x.InputMessage) .Select(msg => !string.IsNullOrWhiteSpace(msg)) .Where(x => x) .Do(x => tox.SetTypingStatus(friendNumber, true, out _)) .Throttle(TimeSpan.FromMilliseconds(500)) .Subscribe(x => tox.SetTypingStatus(friendNumber, false, out _)); tox.Events().Friends .Message .Where(x => x.FriendNumber == friendNumber && x.MessageType == ToxMessageType.Message) .Select(x => x.Message) .Subscribe(msg => messages.Add(new MessageViewModel(tox.GetFriendName(friendNumber, out _), msg, DateTime.Now.Ticks))); this.WhenAnyObservable(x => x.SendTypedMessage) .InvokeCommand(this, x => x.SendMessage); }
public void ListPerformance(int n) { var list = new SourceList<int>(); int calculated = 0; var sw = Stopwatch.StartNew(); var summation = list.Connect() .Sum(i => i) .Subscribe(result => calculated = result); //1. this is very slow if there are loads of updates (each updates causes a new summation) for (int i = 1; i < n; i++) list.Add(i); //2. very fast doing this (whole range is 1 update and 1 calculation): //list.AddRange(Enumerable.Range(0, n)); sw.Stop(); summation.Dispose(); list.Dispose(); Console.WriteLine("Total items: {0}. Value = {1}", n, calculated); Console.WriteLine("List: {0} updates took {1} ms {2:F3} ms each. {3}", n, sw.ElapsedMilliseconds, sw.Elapsed.TotalMilliseconds / n, DateTime.Now.ToShortDateString()); }
private void GetImageFromStream(Stream stream, Enums.ImageType imageType, SourceList <BitmapSource> imageList, CancellationToken token) { using var memoryStream = new MemoryStream(); stream.CopyTo(memoryStream); memoryStream.Seek(0, SeekOrigin.Begin); token.ThrowIfCancellationRequested(); // start of expensive operation Bitmap bitmap; switch (imageType) { case Enums.ImageType.Default: bitmap = new Bitmap(memoryStream); break; case Enums.ImageType.WebP: byte[] b = memoryStream.ToArray(); using (WebP webp = new WebP()) bitmap = webp.Decode(b); break; default: throw new BadImageFormatException(); } var bitmapSource = ConvertStreamToSource(bitmap); bitmapSource.Freeze(); token.ThrowIfCancellationRequested(); // end imageList.Add(bitmapSource); bitmap.Dispose(); }
/// <summary> /// Initializes a new instance of the <see cref="NotificationHostViewModel" /> class. /// </summary> /// <param name="notificationListener">Object which is listening for occuring notifications.</param> public NotificationHostViewModel(INotificationListener notificationListener = null) { _notificationListener = notificationListener ?? Locator.Current.GetService <INotificationListener>(); var notificationSource = new SourceList <Notification>(); var notificationChanges = notificationSource.Connect(); this.WhenActivated(d => { _notificationListener.Notifications .ObserveOn(RxApp.TaskpoolScheduler) .Subscribe(x => notificationSource.Add(x)) .DisposeWith(d); // Add new received notifications as viewmodels to our internal collection. notificationChanges .Transform(x => new NotificationViewModel(x)) .ObserveOn(RxApp.MainThreadScheduler) .Bind(out _notifications) .Subscribe() .DisposeWith(d); // Listen for notification close requests. notificationChanges .Throttle(TimeSpan.FromMilliseconds(100), RxApp.TaskpoolScheduler) .Select(_ => Notifications.Select(x => x.Close).Merge()) .Switch() .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(x => notificationSource.Remove(x.Notification)) .DisposeWith(d); }); }
internal LogViewerViewModel(UavcanInstance uavcan, TableFilterSetViewModel filter) { _serializer = uavcan.Serializer; ResolveTypes(uavcan.TypeResolver); var messageReceived = Observable.FromEventPattern <EventHandler <TransferReceivedArgs>, TransferReceivedArgs>( handler => uavcan.MessageReceived += handler, handler => uavcan.MessageReceived -= handler); var logItemsFiller = messageReceived .Select(x => GetLogMessage(x)) .Where(x => x != null) .Subscribe(m => _logItemsSource.Add(m)); var filterObservable = filter.WhenValueChanged(t => t.Filter) .Select(BuildFilter); var sourceBuilder = _logItemsSource .Connect() .Filter(filterObservable) .ObserveOn(RxApp.MainThreadScheduler) .Bind(out _logItems) .Subscribe(); AddFilter = ReactiveCommand.Create(() => filter.AddFilter()); _cleanUp = new CompositeDisposable(logItemsFiller, sourceBuilder, filter); }
public static void AddOnce <T>(this SourceList <T> sourceList, T item) { if (!sourceList.Items.Contains(item)) { sourceList.Add(item); } }
/// <summary> /// Set name after added to name correct index /// </summary> /// <typeparam name="T"></typeparam> /// <param name="vm"></param> /// <param name="namePrefix"></param> /// <param name="sourceList"></param> internal static void AddAndSetName <T>(this T vm, string namePrefix, SourceList <T> sourceList) where T : INamable { sourceList.Add(vm); vm.SetName(namePrefix, sourceList); }
private void AddLanguage(SourceList <LanguageViewModel> list) { list.Add(new LanguageViewModel(this) { Code = LanguageUtilities.GetDefaultLanguageCode(list.Items.Select(l => l.Code).ToList()) }); }
public void InitializeSession() { _acceleration.Clear(); _acceleration.Add(new Acceleration(0, 0, 0, 0)); _batteryLevel.Clear(); _batteryLevel.Add(new BatteryLevel(0, 0)); _bvp.Clear(); _bvp.Add(new Bvp(0, 0)); _gsr.Clear(); _gsr.Add(new Gsr(0, 0)); _hr.Clear(); _hr.Add(new Hr(0, 0, 0)); _ibi.Clear(); _ibi.Add(new Ibi(0, 0)); _tag.Clear(); _tag.Add(new Tag(0)); _temperature.Clear(); _temperature.Add(new Temperature(0, 0)); }
public override PluginInfo Init(PluginInitContext context) { var types = Assembly.GetExecutingAssembly().GetTypes().Where(x => { return(x.Namespace == @"CozyLauncher.Plugin.Program.ProgramSource" && x.GetInterface("ISource") != null); }); foreach (var type in types) { ISource inst = null; try { inst = (ISource)Activator.CreateInstance(type); } catch { continue; } if (inst != null) { SourceList.Add(inst); } } Update(); context_ = context; var info = new PluginInfo(); info.Keyword = "*"; return(info); }
public BoardViewModel(int wordsize, AudioPlaybackEngine audioPlaybackEngine) { _audioPlaybackEngine = audioPlaybackEngine; _correctSound = new CachedSound(@"Resources\Sounds\WordGame\correct.wav"); _incorrectSound = new CachedSound(@"Resources\Sounds\WordGame\incorrect.wav"); _incorrectLocationSound = new CachedSound(@"Resources\Sounds\WordGame\incorrect_location.wav"); _newRowAppears = new CachedSound(@"Resources\Sounds\WordGame\additional_row_appears.wav"); for (int i = 0; i < wordsize; i++) { _wordGameRows.Add(new WordGameRowViewModel(wordsize)); } _wordGameRows.Connect().Bind(out var rows).Subscribe(); Rows = rows; }
public void Aggregations() { using (var dataSource = new SourceList <int>()) using (var sut = new Aggregations(dataSource)) { //check StartWithEmpty() has taken effect sut.Min.Should().NotBeNull(); sut.Max.Should().NotBeNull(); sut.Avg.Should().NotBeNull(); dataSource.AddRange(Enumerable.Range(1, 10)); sut.Min.Should().Be(1); sut.Max.Should().Be(10); sut.Avg.Should().Be(5.5); dataSource.RemoveRange(0, 9); dataSource.Add(100); //items in list = [10,100] sut.Min.Should().Be(10); sut.Max.Should().Be(100); sut.Avg.Should().Be(55); } }
public void AutoRefresh() { var items = Enumerable.Range(1, 100).Select(i => new Person("Person" + i, 1)).ToArray(); //result should only be true when all items are set to true using var list = new SourceList <Person>(); using var results = list.Connect().AutoRefresh(p => p.Age).AsAggregator(); list.AddRange(items); results.Data.Count.Should().Be(100); results.Messages.Count.Should().Be(1); items[0].Age = 10; results.Data.Count.Should().Be(100); results.Messages.Count.Should().Be(2); results.Messages[1].First().Reason.Should().Be(ListChangeReason.Refresh); //remove an item and check no change is fired var toRemove = items[1]; list.Remove(toRemove); results.Data.Count.Should().Be(99); results.Messages.Count.Should().Be(3); toRemove.Age = 100; results.Messages.Count.Should().Be(3); //add it back in and check it updates list.Add(toRemove); results.Messages.Count.Should().Be(4); toRemove.Age = 101; results.Messages.Count.Should().Be(5); results.Messages.Last().First().Reason.Should().Be(ListChangeReason.Refresh); }
public void ListPerformance(int n) { var list = new SourceList <int>(); double runningSum = 0; var sw = Stopwatch.StartNew(); var summation = list.Connect() .Minimum(i => i) .Subscribe(result => runningSum = result); //1. this is very slow if there are loads of updates (each updates causes a new summation) for (int i = 0; i < n; i++) { list.Add(i); } //2. very fast doing this (whole range is 1 update and 1 calculation): //list.AddRange(Enumerable.Range(0, n)); sw.Stop(); summation.Dispose(); list.Dispose(); Console.WriteLine("Total items: {0}. Sum = {1}", n, runningSum); Console.WriteLine("List: {0} updates took {1} ms {2:F3} ms each. {3}", n, sw.ElapsedMilliseconds, sw.Elapsed.TotalMilliseconds / n, DateTime.Now.ToShortDateString()); }
private async Task OpenFile() { OpenFileDialog ofd = new OpenFileDialog { AllowMultiple = true }; ofd.Filters.Add(new FileDialogFilter { Name = "GMD Text File", Extensions = new List <string> { "gmd" } }); var files = await ofd.ShowAsync(window); foreach (var file in files) { var fileInfo = new FileInfo(file); var vm = TryCreateViewModelForFile(fileInfo); if (vm != null) { openFilesList.Add(vm); } } }
public void SwitchOnTest() { SourceList <int> one = new SourceList <int>(); SourceList <int> other = new SourceList <int>(); one.AddRange(new[] { 1, 3 }); other.AddRange(new[] { 2, 4 }); using (var switcher = new BehaviorSubject <Unit>(Unit.Default)) using (var aggregate = switcher.Scan(other, (agg, cur) => agg == one ? other : one).Switch().AsAggregator()) { CollectionAssert.AreEqual(new [] { 1, 3 }, aggregate.Data.Items); switcher.OnNext(Unit.Default); CollectionAssert.AreEqual(new [] { 2, 4 }, aggregate.Data.Items); one.Add(5); CollectionAssert.AreEqual(new [] { 2, 4 }, aggregate.Data.Items); switcher.OnNext(Unit.Default); CollectionAssert.AreEqual(new [] { 1, 3, 5 }, aggregate.Data.Items); other.Remove(4); CollectionAssert.AreEqual(new [] { 1, 3, 5 }, aggregate.Data.Items); one.Remove(3); CollectionAssert.AreEqual(new [] { 1, 5 }, aggregate.Data.Items); } }
public void MakeSelectMagicWorkWithObservable() { var initialItem = new IntHolder() { Value = 1, Description = "Initial Description" }; var sourceList = new SourceList <IntHolder>(); sourceList.Add(initialItem); var descriptionStream = sourceList .Connect() .AutoRefresh(intHolder => intHolder.Description) .Transform(intHolder => intHolder.Description, true) .Do(x => { }) // <--- Add break point here to check the overload fixes it .Bind(out ReadOnlyObservableCollection <string> resultCollection); using (descriptionStream.Subscribe()) { var newDescription = "New Description"; initialItem.Description = newDescription; newDescription.Should().Be(resultCollection[0]); //Assert.AreEqual(newDescription, resultCollection[0]); } }
public void SkipInitialDoesNotReturnTheFirstBatchOfData() { bool updateReceived = false; var cache = new SourceList<Person>(); var deferStream = cache.Connect().SkipInitial() .Subscribe(changes => updateReceived = true); Assert.IsFalse(updateReceived, "No update should be received"); cache.Add(new Person("P1", 1)); Assert.IsFalse(updateReceived, "No update should be received for initial batch of changes"); cache.Add(new Person("P2", 2)); Assert.IsTrue(updateReceived, "Replace should be received"); deferStream.Dispose(); }
public void MergeManyShouldWork() { var a = new SourceList<int>(); var b = new SourceList<int>(); var c = new SourceList<int>(); var parent = new SourceList<SourceList<int>>(); parent.Add(a); parent.Add(b); parent.Add(c); var d = parent.Connect() .MergeMany(e => e.Connect().RemoveIndex()) .AsObservableList(); Assert.AreEqual(d.Count,0); a.Add(1); Assert.AreEqual(d.Count, 1); a.Add(2); Assert.AreEqual(d.Count, 2); b.Add(3); Assert.AreEqual(d.Count, 3); b.Add(5); Assert.AreEqual(d.Count, 4); CollectionAssert.AreEquivalent(d.Items, new[] { 1, 2, 3, 5 }); b.Clear(); // Fails below Assert.AreEqual(d.Count,2); CollectionAssert.AreEquivalent(d.Items, new[] { 1, 2}); }
public void DeferUntilLoadedDoesNothingUntilDataHasBeenReceived() { bool updateReceived = false; IChangeSet<Person> result = null; var cache = new SourceList<Person>(); var deferStream = cache.Connect().DeferUntilLoaded() .Subscribe(changes => { updateReceived = true; result = changes; }); Assert.IsFalse(updateReceived,"No update should be received"); cache.Add(new Person("Test",1)); Assert.IsTrue(updateReceived,"Replace should be received"); Assert.AreEqual(1,result.Adds); Assert.AreEqual(new Person("Test",1), result.First().Item.Current); deferStream.Dispose(); }