コード例 #1
0
        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);
        }
コード例 #2
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();
        }
コード例 #3
0
        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);
        }
コード例 #4
0
 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);
 }
コード例 #5
0
        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();
        }
コード例 #6
0
 /// <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;
 }
コード例 #7
0
ファイル: SensorHistoryVm.cs プロジェクト: m0j0/Thermometer
        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>();
        }
コード例 #8
0
        /// <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);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        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();
        }
コード例 #11
0
        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);
        }
コード例 #12
0
        /// <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));
        }
コード例 #13
0
 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;
 }
コード例 #14
0
        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;
        }
コード例 #15
0
 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);
 }
コード例 #16
0
        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);
        }
コード例 #17
0
        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;
        }
コード例 #18
0
        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();
        }
コード例 #19
0
        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();
        }
コード例 #20
0
        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);
        }
コード例 #21
0
 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);
 }
コード例 #22
0
 /// <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));
 }
コード例 #23
0
 protected override void AssertObject(SynchronizedNotifiableCollection <string> deserializedObj)
 {
     deserializedObj.SequenceEqual(TestExtensions.TestStrings).ShouldBeTrue();
     deserializedObj.IsNotificationsSuspended.ShouldBeFalse();
 }
コード例 #24
0
 public TreeNodeModel(TreeNodeModel parent = null)
 {
     Parent = parent;
     Nodes  = new SynchronizedNotifiableCollection <TreeNodeModel>();
 }
コード例 #25
0
 public TreeNodeModel(TreeNodeModel parent = null)
 {
     Parent = parent;
     Nodes = new SynchronizedNotifiableCollection<TreeNodeModel>();
 }