public void CollectionShouldReturnCountUsingMode() { SynchronizedNotifiableCollection <Item> collection = CreateNotifiableCollection <Item>(ExecutionMode.AsynchronousOnUiThread, ThreadManagerMock); IList list = collection; IList <Item> genericList = collection; collection.Add(new Item()); collection.NotificationMode = NotificationCollectionMode.None; list.Count.ShouldEqual(1); genericList.Count.ShouldEqual(1); collection.Count.ShouldEqual(1); collection.NotificationCount.ShouldEqual(0); collection.NotificationMode = NotificationCollectionMode.CollectionIntefaceUseNotificationValue; list.Count.ShouldEqual(0); genericList.Count.ShouldEqual(1); collection.Count.ShouldEqual(1); collection.NotificationCount.ShouldEqual(0); collection.NotificationMode = NotificationCollectionMode.GenericCollectionInterfaceUseNotificationValue; list.Count.ShouldEqual(1); genericList.Count.ShouldEqual(0); collection.Count.ShouldEqual(1); collection.NotificationCount.ShouldEqual(0); collection.NotificationMode = NotificationCollectionMode.GenericCollectionInterfaceUseNotificationValue | NotificationCollectionMode.CollectionIntefaceUseNotificationValue; list.Count.ShouldEqual(0); genericList.Count.ShouldEqual(0); collection.Count.ShouldEqual(1); collection.NotificationCount.ShouldEqual(0); }
public void WhenOperationWasCanceledCollectionShouldNotBeChanged() { SynchronizedNotifiableCollection <Item> collection = CreateNotifiableCollection <Item>(ExecutionMode.None, ThreadManagerMock); collection.Add(new Item { Id = new Guid("0C32E17E-020C-4E05-9B90-AE247B8BE703") }); collection.CollectionChanging += (sender, args) => args.Cancel = true; var collectionTracker = new NotifiableCollectionTracker <Item>(collection); var item = new Item { Id = new Guid("3C39C0C0-DFBA-4683-8473-0950085478E9") }; collection.Add(item); collection.Remove(item); collection[0] = item; collection.Clear(); collection.Count.ShouldEqual(1); collection[0].ShouldNotEqual(item); collectionTracker.ChangedItems.SequenceEqual(collection).ShouldBeTrue(); collectionTracker.ChangingItems.SequenceEqual(collection).ShouldBeTrue(); }
public virtual void CollectionShouldTrackChangesCorrectBatchSize() { const int count = 10; SynchronizedNotifiableCollection <Item> collection = CreateNotifiableCollection <Item>(ExecutionMode.None, ThreadManagerMock); collection.BatchSize = 10; var collectionTracker = new NotifiableCollectionTracker <Item>(collection); using (collection.SuspendNotifications()) { var item = new Item(); var items = new[] { new Item(), new Item(), new Item() }; var items2 = new[] { new Item(), new Item(), new Item() }; for (int i = 0; i < count; i++) { collection.AddRange(items); collection.AddRange(items2); collection.RemoveRange(items); } for (int i = 0; i < collection.Count; i++) { collection[i] = item; } } ThreadManagerMock.InvokeOnUiThreadAsync(); collectionTracker.AssertEquals(); collection.Count.ShouldEqual(count * 3); }
public DataCollection() { tableOne = new SynchronizedNotifiableCollection <DataModelOne>(); tableOne.CollectionChanged += (s, e) => BaseCollectionChanged <DataModelOne>(s, e); tableTwo = new SynchronizedNotifiableCollection <DataModelTwo>(); tableTwo.CollectionChanged += (s, e) => BaseCollectionChanged <DataModelTwo>(s, e); }
public void WhenOperationWasCanceledCollectionShouldNotBeChanged() { SynchronizedNotifiableCollection <Item> collection = CreateNotifiableCollection <Item>(ExecutionMode.None, ThreadManagerMock); collection.Add(new Item { Id = -1 }); collection.CollectionChanging += (sender, args) => args.Cancel = true; var collectionTracker = new NotifiableCollectionTracker <Item>(collection, false); var item = new Item { Id = -2 }; collection.Add(item); collection.Remove(item); collection[0] = item; collection.Clear(); collection.Count.ShouldEqual(1); collection[0].ShouldNotEqual(item); collectionTracker.ChangedItems.SequenceEqual(collection).ShouldBeTrue(); collectionTracker.ChangingItems.SequenceEqual(collection).ShouldBeTrue(); }
/// <summary> /// Initializes a new instance of the <see cref="MultiViewModel" /> class. /// </summary> public MultiViewModel() { var collection = new SynchronizedNotifiableCollection<IViewModel>(); _itemsSource = ServiceProvider.TryDecorate(collection); collection.AfterCollectionChanged = OnViewModelsChanged; _weakEventHandler = ReflectionExtensions.CreateWeakDelegate<MultiViewModel, ViewModelClosedEventArgs, EventHandler<ICloseableViewModel, ViewModelClosedEventArgs>>(this, (model, o, arg3) => model.ItemsSource.Remove(arg3.ViewModel), UnsubscribeAction, handler => handler.Handle); _propertyChangedWeakEventHandler = ReflectionExtensions.MakeWeakPropertyChangedHandler(this, (model, o, arg3) => model.OnItemPropertyChanged(o, arg3)); DisposeViewModelOnRemove = true; }
public SensorHistoryVm(ICurrentWeatherDataProvider currentWeatherDataProvider, IToastPresenter toastPresenter, IMessagePresenter messagePresenter) { _currentWeatherDataProvider = currentWeatherDataProvider; _toastPresenter = toastPresenter; _messagePresenter = messagePresenter; RefreshCommand = new RelayCommand(Refresh); LoadMoreItemsCommand = new RelayCommand(LoadMoreItems); Items = new SynchronizedNotifiableCollection <SensorHistoryData>(); }
/// <summary> /// Initializes a new instance of the <see cref="NotifiableCollectionTracker{T}" /> class. /// </summary> public NotifiableCollectionTracker(SynchronizedNotifiableCollection <T> collection) { _collection = collection; collection.CollectionChanging += CollectionOnCollectionChanging; collection.CollectionChanged += CollectionOnCollectionChanged; collection.PropertyChanged += CollectionOnPropertyChanged; _changingItems = new List <T>(_collection); _changedItems = new List <T>(_collection); }
public void CollectionShouldNotRaiseEventsUsingThreadManagerIfModeNone() { SynchronizedNotifiableCollection <Item> collection = CreateNotifiableCollection <Item>(ExecutionMode.None, ThreadManagerMock); collection.Add(new Item()); var collectionTracker = new NotifiableCollectionTracker <Item>(collection); collectionTracker.AssertEquals(); collection.Count.ShouldEqual(1); }
public void CollectionShouldRaiseEventsUsingThreadManager() { SynchronizedNotifiableCollection <Item> collection = CreateNotifiableCollection <Item>(ExecutionMode.AsynchronousOnUiThread, ThreadManagerMock); collection.Add(new Item()); ThreadManagerMock.InvokeOnUiThreadAsync(); var collectionTracker = new NotifiableCollectionTracker <Item>(collection); collectionTracker.AssertEquals(); }
public virtual void GlobalSettingTest() { ApplicationSettings.SetDefaultValues(); //By default var syncronizedNotifiableCollection = new SynchronizedNotifiableCollection <Item>(); syncronizedNotifiableCollection.ExecutionMode.ShouldEqual(ExecutionMode.AsynchronousOnUiThread); ApplicationSettings.SynchronizedCollectionExecutionMode = ExecutionMode.None; syncronizedNotifiableCollection = new SynchronizedNotifiableCollection <Item>(); syncronizedNotifiableCollection.ExecutionMode.ShouldEqual(ExecutionMode.None); }
/// <summary> /// Initializes a new instance of the <see cref="MultiViewModel" /> class. /// </summary> public MultiViewModel() { _prevIndex = -1; DisposeViewModelOnRemove = true; var collection = new SynchronizedNotifiableCollection <IViewModel>(); _itemsSource = ServiceProvider.TryDecorate(collection); collection.CollectionChanged += OnViewModelsChanged; _weakEventHandler = ReflectionExtensions.CreateWeakDelegate <MultiViewModel, ViewModelClosedEventArgs, EventHandler <ICloseableViewModel, ViewModelClosedEventArgs> >(this, (model, o, arg3) => model.OnViewModelClosed(arg3), UnsubscribeAction, handler => handler.Handle); _propertyChangedWeakEventHandler = ReflectionExtensions.MakeWeakPropertyChangedHandler(this, (model, o, arg3) => model.OnItemPropertyChanged(o, arg3)); }
public MultiViewModel() { var collection = new SynchronizedNotifiableCollection<IViewModel>(); var list = ServiceProvider.TryDecorate(this, collection); Should.BeOfType<INotifiableCollection<IViewModel>>(list, "DecoratedItemsSource"); _itemsSource = (INotifiableCollection<IViewModel>)list; collection.AfterCollectionChanged = OnViewModelsChanged; _weakEventHandler = ReflectionExtensions.CreateWeakDelegate<MultiViewModel, ViewModelClosedEventArgs, EventHandler<ICloseableViewModel, ViewModelClosedEventArgs>>(this, (model, o, arg3) => model.ItemsSource.Remove(arg3.ViewModel), UnsubscribeAction, handler => handler.Handle); _propertyChangedWeakEventHandler = ReflectionExtensions.MakeWeakPropertyChangedHandler(this, (model, o, arg3) => model.OnItemPropertyChanged(o, arg3)); DisposeViewModelOnRemove = ApplicationSettings.MultiViewModelDisposeViewModelOnRemove; CloseViewModelsOnClose = ApplicationSettings.MultiViewModelCloseViewModelsOnClose; }
public MultiViewModel() { var collection = new SynchronizedNotifiableCollection <IViewModel>(); var list = ServiceProvider.TryDecorate(collection); Should.BeOfType <INotifiableCollection <IViewModel> >(list, "DecoratedItemsSource"); _itemsSource = (INotifiableCollection <IViewModel>)list; collection.AfterCollectionChanged = OnViewModelsChanged; _weakEventHandler = ReflectionExtensions.CreateWeakDelegate <MultiViewModel, ViewModelClosedEventArgs, EventHandler <ICloseableViewModel, ViewModelClosedEventArgs> >(this, (model, o, arg3) => model.ItemsSource.Remove(arg3.ViewModel), UnsubscribeAction, handler => handler.Handle); _propertyChangedWeakEventHandler = ReflectionExtensions.MakeWeakPropertyChangedHandler(this, (model, o, arg3) => model.OnItemPropertyChanged(o, arg3)); DisposeViewModelOnRemove = true; }
public TreeViewBindingViewModel() { Nodes = new SynchronizedNotifiableCollection<TreeNodeModel> { new TreeNodeModel {Name = "Node 1", IsValid = true}, new TreeNodeModel {Name = "Node 2", IsValid = true} }; Nodes[0].Nodes.Add(new TreeNodeModel(Nodes[0]) { Name = "Node 1.1" }); Nodes[1].Nodes.Add(new TreeNodeModel(Nodes[1]) { Name = "Node 2.1" }); Nodes.CollectionChanged += NodesOnCollectionChanged; AddNodeCommand = new RelayCommand(AddNode); RemoveNodeCommand = new RelayCommand(RemoveNode, CanRemoveNode, this); }
public NotifiableCollectionTracker(SynchronizedNotifiableCollection <T> collection, bool listenChangingEvent = true) { _collection = collection; if (listenChangingEvent) { collection.CollectionChanging += CollectionOnCollectionChanging; } collection.CollectionChanged += CollectionOnCollectionChanged; collection.PropertyChanged += CollectionOnPropertyChanged; _changingItems = new List <T>(_collection); _changedItems = new List <T>(_collection); }
public MultiViewModel() { var collection = new SynchronizedNotifiableCollection <TViewModel>(); var list = ServiceProvider.TryDecorate(this, collection); Should.BeOfType <INotifiableCollection <TViewModel> >(list, "DecoratedItemsSource"); _itemsSource = (INotifiableCollection <TViewModel>)list; collection.AfterCollectionChanged = OnViewModelsChanged; _propertyChangedWeakEventHandler = ReflectionExtensions.MakeWeakPropertyChangedHandler(this, (model, o, arg3) => model.OnItemPropertyChanged(o, arg3)); var weakReference = ToolkitExtensions.GetWeakReference(this); _closeViewModelWeakHandler = (dispatcher, vm, arg3) => { var self = (MultiViewModel <TViewModel>)weakReference.Target; return(self?.CloseViewModel(dispatcher, vm, arg3) ?? Empty.FalseTask); }; DisposeViewModelOnRemove = ApplicationSettings.MultiViewModelDisposeViewModelOnRemove; CloseViewModelsOnClose = ApplicationSettings.MultiViewModelCloseViewModelsOnClose; }
public void CollectionShouldChangeEventToClearIfUsingBatchSize() { bool isInvoked = false; SynchronizedNotifiableCollection <Item> collection = CreateNotifiableCollection <Item>(ExecutionMode.None, ThreadManagerMock); collection.CollectionChanged += (sender, args) => { args.Action.ShouldEqual(NotifyCollectionChangedAction.Reset); isInvoked = true; }; collection.BatchSize = 1; using (collection.SuspendNotifications()) { collection.Add(new Item()); collection.Add(new Item()); } isInvoked.ShouldBeTrue(); }
public void WhenNotificationSuspendedEventsShouldNotBeRaised() { SynchronizedNotifiableCollection <Item> collection = CreateNotifiableCollection <Item>(ExecutionMode.None, ThreadManagerMock); var collectionTracker = new NotifiableCollectionTracker <Item>(collection); using (collection.SuspendNotifications()) { for (int i = 0; i < 10; i++) { var item = new Item(); collection.Add(item); collection.Remove(item); } using (collection.SuspendNotifications()) { collection.Add(new Item()); } collectionTracker.ChangedItems.ShouldBeEmpty(); } ThreadManagerMock.InvokeOnUiThreadAsync(); collectionTracker.AssertEquals(); }
public override void CollectionShouldTrackChangesCorrect() { const int count = 10; SynchronizedNotifiableCollection <Item> collection = CreateNotifiableCollection <Item>(ExecutionMode.None, ThreadManagerMock); var collectionTracker = new NotifiableCollectionTracker <Item>(collection); collection.BatchSize = int.MaxValue; var items = new[] { new Item(), new Item(), new Item() }; var items2 = new[] { new Item(), new Item(), new Item() }; using (collection.SuspendNotifications()) { for (int i = 0; i < count; i++) { collection.AddRange(items); collection.AddRange(items2); collection.RemoveRange(items); } } collectionTracker.AssertEquals(); collection.Count.ShouldEqual(count * 3); }
public TreeViewBindingViewModel() { Nodes = new SynchronizedNotifiableCollection <TreeNodeModel> { new TreeNodeModel { Name = "Node 1", IsValid = true }, new TreeNodeModel { Name = "Node 2", IsValid = true } }; Nodes[0].Nodes.Add(new TreeNodeModel(Nodes[0]) { Name = "Node 1.1" }); Nodes[1].Nodes.Add(new TreeNodeModel(Nodes[1]) { Name = "Node 2.1" }); Nodes.CollectionChanged += NodesOnCollectionChanged; AddNodeCommand = new RelayCommand(AddNode); RemoveNodeCommand = new RelayCommand(RemoveNode, CanRemoveNode, this); }
/// <summary> /// Converts a collection to the <see cref="BindingListWrapper{T}" /> collection. /// </summary> /// <typeparam name="T">The type of collection.</typeparam> /// <param name="collection">The specified collection.</param> /// <returns>An instance of <see cref="BindingListWrapper{T}" />.</returns> public static BindingListWrapper <T> ToBindingList <T>(this SynchronizedNotifiableCollection <T> collection) { Should.NotBeNull(collection, "collection"); return(new BindingListWrapper <T>(collection)); }
protected override void AssertObject(SynchronizedNotifiableCollection <string> deserializedObj) { deserializedObj.SequenceEqual(TestExtensions.TestStrings).ShouldBeTrue(); deserializedObj.IsNotificationsSuspended.ShouldBeFalse(); }
public TreeNodeModel(TreeNodeModel parent = null) { Parent = parent; Nodes = new SynchronizedNotifiableCollection <TreeNodeModel>(); }
public TreeNodeModel(TreeNodeModel parent = null) { Parent = parent; Nodes = new SynchronizedNotifiableCollection<TreeNodeModel>(); }