Пример #1
0
        /// <summary>
        /// Gets a <see cref="DomainDataSourceView"/> that uses a mocked <see cref="PagedEntityList"/>
        /// as its source, configured to support the operations specified, and using the specified
        /// <paramref name="refreshCallback"/> as the <see cref="Action"/> to invoke when a
        /// <see cref="DomainDataSourceView.Refresh"/> is triggered.
        /// </summary>
        /// <param name="operationsSupported">The operations to be supported on the mock <see cref="EntitySet"/>.</param>
        /// <param name="refreshCallback">The <see cref="Action"/> to call when a refresh occurs.</param>
        /// <returns>The configured <see cref="DomainDataSourceView"/> that uses mocks.</returns>
        private static DomainDataSourceView GetConfigurableView(EntitySetOperations operationsSupported, Action refreshCallback)
        {
            MockEntityContainer ec = new MockEntityContainer();

            ec.CreateSet <City>(operationsSupported);

            IPagedEntityList          pagedList = new MockPagedEntityList(ec.GetEntitySet <City>(), null);
            PagedEntityCollectionView ecv       = new PagedEntityCollectionView(pagedList, refreshCallback);

            return(new DomainDataSourceView(ecv));
        }
        public void RemoveEventRelayed()
        {
            Product first = new Product();
            Product second = new Product();
            NotifyingCollection<Product> source = new NotifyingCollection<Product>() { first, second };
            PagedEntityCollectionView<Product> view = new PagedEntityCollectionView<Product>(source);

            this.AssertCollectionChanged(
                () => source.Remove(first),
                view,
                new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, first, 0),
                "when removing the first item.");
        }
        public void AddEventRelayed()
        {
            Product first = new Product();
            Product second = new Product();
            NotifyingCollection<Product> source = new NotifyingCollection<Product>() { first, second };
            PagedEntityCollectionView<Product> view = new PagedEntityCollectionView<Product>(source);

            Product third = new Product();

            this.AssertCollectionChanged(
                () => source.Add(third),
                view,
                new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, third, 2),
                "when adding the third item.");
        }
        public void RemoveEventRelayed()
        {
            Product first  = new Product();
            Product second = new Product();
            NotifyingCollection <Product> source = new NotifyingCollection <Product>()
            {
                first, second
            };
            PagedEntityCollectionView <Product> view = new PagedEntityCollectionView <Product>(source);

            this.AssertCollectionChanged(
                () => source.Remove(first),
                view,
                new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, first, 0),
                "when removing the first item.");
        }
        public void ResetEventRelayed()
        {
            Product first = new Product();
            Product second = new Product();
            NotifyingCollection<Product> source = new NotifyingCollection<Product>() { first, second };
            PagedEntityCollectionView<Product> view = new PagedEntityCollectionView<Product>(source);

            this.AssertCollectionChanged(
                () => source.Reset(),
                view,
                new NotifyCollectionChangedEventArgs[]
                {
                    new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset),
                    new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset), // Bug 706239
                },
                "when resetting the collection.");
        }
Пример #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DomainDataSourceView"/> class.
        /// </summary>
        /// <param name="entityCollectionView">The <see cref="OpenRiaServices.Controls.PagedEntityCollectionView"/> to wrap</param>
        internal DomainDataSourceView(PagedEntityCollectionView entityCollectionView)
        {
            Debug.Assert(entityCollectionView != null, "EntityCollectionView cannot be null.");

            this._pagedEntityCollectionView = entityCollectionView;

            // ICollectionView
            this._pagedEntityCollectionView.CollectionChanged += this.OnCollectionViewCollectionChanged;
            this._pagedEntityCollectionView.CurrentChanged    += this.OnCollectionViewCurrentChanged;
            this._pagedEntityCollectionView.CurrentChanging   += this.OnCollectionViewCurrentChanging;

            // IPagedCollectionView
            this._pagedEntityCollectionView.PageChanged  += this.OnPagedCollectionViewPageChanged;
            this._pagedEntityCollectionView.PageChanging += this.OnPagedCollectionViewPageChanging;

            this._pagedEntityCollectionView.PropertyChanged += this.OnPagedEntityCollectionViewPropertyChanged;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DomainDataSourceView"/> class.
        /// </summary>
        /// <param name="entityCollectionView">The <see cref="OpenRiaServices.Controls.PagedEntityCollectionView"/> to wrap</param>
        internal DomainDataSourceView(PagedEntityCollectionView entityCollectionView)
        {
            Debug.Assert(entityCollectionView != null, "EntityCollectionView cannot be null.");

            this._pagedEntityCollectionView = entityCollectionView;

            // ICollectionView
            this._pagedEntityCollectionView.CollectionChanged += this.OnCollectionViewCollectionChanged;
            this._pagedEntityCollectionView.CurrentChanged += this.OnCollectionViewCurrentChanged;
            this._pagedEntityCollectionView.CurrentChanging += this.OnCollectionViewCurrentChanging;

            // IPagedCollectionView
            this._pagedEntityCollectionView.PageChanged += this.OnPagedCollectionViewPageChanged;
            this._pagedEntityCollectionView.PageChanging += this.OnPagedCollectionViewPageChanging;

            this._pagedEntityCollectionView.PropertyChanged += this.OnPagedEntityCollectionViewPropertyChanged;
        }
        public void AddEventRelayed()
        {
            Product first  = new Product();
            Product second = new Product();
            NotifyingCollection <Product> source = new NotifyingCollection <Product>()
            {
                first, second
            };
            PagedEntityCollectionView <Product> view = new PagedEntityCollectionView <Product>(source);

            Product third = new Product();

            this.AssertCollectionChanged(
                () => source.Add(third),
                view,
                new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, third, 2),
                "when adding the third item.");
        }
        public void ResetEventRelayed()
        {
            Product first  = new Product();
            Product second = new Product();
            NotifyingCollection <Product> source = new NotifyingCollection <Product>()
            {
                first, second
            };
            PagedEntityCollectionView <Product> view = new PagedEntityCollectionView <Product>(source);

            this.AssertCollectionChanged(
                () => source.Reset(),
                view,
                new NotifyCollectionChangedEventArgs[]
            {
                new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset),
                new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset),     // Bug 706239
            },
                "when resetting the collection.");
        }
        public void CancelingCurrencyChangeIsRespectedOnCommitEdit()
        {
            City first = new City {
                Name = "1"
            };
            City second = new City {
                Name = "2"
            };
            MockEntityContainer ec = new MockEntityContainer();

            ec.CreateSet <City>(EntitySetOperations.All);

            IPagedEntityList          pagedList = new MockPagedEntityList(ec.GetEntitySet <City>(), null);
            PagedEntityCollectionView view      = new PagedEntityCollectionView(pagedList, () => { });

            view.Add(first);
            view.Add(second);

            bool canChangeCurrency = true;
            CurrentChangingEventHandler changingHandler = (sender, e) =>
            {
                if (!canChangeCurrency)
                {
                    Assert.IsTrue(e.IsCancelable,
                                  "Event should be cancelable when commiting an edit.");
                    e.Cancel = true;
                }
            };
            EventHandler changedHandler = (sender, e) =>
            {
                if (!canChangeCurrency)
                {
                    Assert.Fail("Currency changes should only occur when canChangeCurrency is true.");
                }
            };

            view.CurrentChanging += changingHandler;
            view.CurrentChanged  += changedHandler;

            view.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));

            Assert.IsTrue(view.MoveCurrentTo(second),
                          "We should be able to move current to the second item.");

            // Commit an edit but do not allow the currency to change
            canChangeCurrency = false;
            view.EditItem(second);
            second.Name = "0";
            view.CommitEdit();

            Assert.AreEqual(view[1], second,
                            "The edited item should not have moved.");

            // Commit an edit and this time allow the currency to change
            canChangeCurrency = true;
            view.EditItem(second);
            second.Name = "00";
            view.CommitEdit();

            Assert.AreEqual(view[0], second,
                            "The edited item should have moved to the first position in the view.");
        }
        public void CancelingCurrencyChangeIsRespectedOnCommitEdit()
        {
            City first = new City { Name = "1" };
            City second = new City { Name = "2" };
            MockEntityContainer ec = new MockEntityContainer();
            ec.CreateSet<City>(EntitySetOperations.All);

            IPagedEntityList pagedList = new MockPagedEntityList(ec.GetEntitySet<City>(), null);
            PagedEntityCollectionView view = new PagedEntityCollectionView(pagedList, () => { });

            view.Add(first);
            view.Add(second);

            bool canChangeCurrency = true;
            CurrentChangingEventHandler changingHandler = (sender, e) =>
            {
                if (!canChangeCurrency)
                {
                    Assert.IsTrue(e.IsCancelable,
                        "Event should be cancelable when commiting an edit.");
                    e.Cancel = true;
                }
            };
            EventHandler changedHandler = (sender, e) =>
            {
                if (!canChangeCurrency)
                {
                    Assert.Fail("Currency changes should only occur when canChangeCurrency is true.");
                }
            };
            view.CurrentChanging += changingHandler;
            view.CurrentChanged += changedHandler;

            view.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));

            Assert.IsTrue(view.MoveCurrentTo(second),
                "We should be able to move current to the second item.");

            // Commit an edit but do not allow the currency to change
            canChangeCurrency = false;
            view.EditItem(second);
            second.Name = "0";
            view.CommitEdit();

            Assert.AreEqual(view[1], second,
                "The edited item should not have moved.");

            // Commit an edit and this time allow the currency to change
            canChangeCurrency = true;
            view.EditItem(second);
            second.Name = "00";
            view.CommitEdit();

            Assert.AreEqual(view[0], second,
                "The edited item should have moved to the first position in the view.");
        }
        /// <summary>
        /// Gets a <see cref="DomainDataSourceView"/> that uses a mocked <see cref="PagedEntityList"/>
        /// as its source, configured to support the operations specified, and using the specified
        /// <paramref name="refreshCallback"/> as the <see cref="Action"/> to invoke when a
        /// <see cref="DomainDataSourceView.Refresh"/> is triggered.
        /// </summary>
        /// <param name="operationsSupported">The operations to be supported on the mock <see cref="EntitySet"/>.</param>
        /// <param name="refreshCallback">The <see cref="Action"/> to call when a refresh occurs.</param>
        /// <returns>The configured <see cref="DomainDataSourceView"/> that uses mocks.</returns>
        private static DomainDataSourceView GetConfigurableView(EntitySetOperations operationsSupported, Action refreshCallback)
        {
            MockEntityContainer ec = new MockEntityContainer();
            ec.CreateSet<City>(operationsSupported);

            IPagedEntityList pagedList = new MockPagedEntityList(ec.GetEntitySet<City>(), null);
            PagedEntityCollectionView ecv = new PagedEntityCollectionView(pagedList, refreshCallback);

            return new DomainDataSourceView(ecv);
        }