public void CannotSortTest()
        {
            List <TestClass> intList = new List <TestClass>()
            {
                new TestClass()
            };
            PagedCollectionView pcv = new PagedCollectionView(intList);

            // we are not allowed to sort during an edit operation
            pcv.EditItem(pcv[0]);
            PagedCollectionViewTest.AssertExpectedException(
                new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, PagedCollectionViewResources.OperationNotAllowedDuringAddOrEdit, "Sorting")),
                delegate
            {
                pcv.SortDescriptions.Clear();
            });
            pcv.CommitEdit();

            // we are not allowed to sort during an add new operation
            pcv.AddNew();
            PagedCollectionViewTest.AssertExpectedException(
                new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, PagedCollectionViewResources.OperationNotAllowedDuringAddOrEdit, "Sorting")),
                delegate
            {
                pcv.SortDescriptions.Clear();
            });
        }
        public void CannotRefreshTest()
        {
            ObservableCollection <TestClass> collection = new ObservableCollection <TestClass>()
            {
                new TestClass()
            };
            PagedCollectionView pcv = new PagedCollectionView(collection);

            // show that we will throw an exception if we try to change the PageSize while adding
            pcv.AddNew();
            PagedCollectionViewTest.AssertExpectedException(
                new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, PagedCollectionViewResources.OperationNotAllowedDuringAddOrEdit, "Refresh")),
                delegate
            {
                pcv.Refresh();
            });
            pcv.CancelNew();

            // show that we will throw an exception if we try to change the PageSize while editing
            pcv.EditItem(pcv[0]);
            PagedCollectionViewTest.AssertExpectedException(
                new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, PagedCollectionViewResources.OperationNotAllowedDuringAddOrEdit, "Refresh")),
                delegate
            {
                pcv.Refresh();
            });
        }
        public void CannotChangePageSize()
        {
            ObservableCollection <TestClass> collection = new ObservableCollection <TestClass>()
            {
                new TestClass()
            };
            PagedCollectionView pcv = new PagedCollectionView(collection);

            // show that we will throw an exception if we try to change the PageSize while adding
            pcv.AddNew();
            PagedCollectionViewTest.AssertExpectedException(
                new InvalidOperationException(PagedCollectionViewResources.ChangingPageSizeNotAllowedDuringAddOrEdit),
                delegate
            {
                pcv.PageSize = 10;
            });
            pcv.CancelNew();

            // show that we will throw an exception if we try to change the PageSize while editing
            pcv.EditItem(pcv[0]);
            PagedCollectionViewTest.AssertExpectedException(
                new InvalidOperationException(PagedCollectionViewResources.ChangingPageSizeNotAllowedDuringAddOrEdit),
                delegate
            {
                pcv.PageSize = 10;
            });
        }
예제 #4
0
        public void MoveCurrencyToInvalidPosition()
        {
            // when setting to a value < -1, we should throw
            PagedCollectionViewTest.AssertExpectedException(
                new ArgumentOutOfRangeException("position"),
                delegate
            {
                CollectionView.MoveCurrentToPosition(-2);
            });

            // when setting to a value > count, we should throw
            PagedCollectionViewTest.AssertExpectedException(
                new ArgumentOutOfRangeException("position"),
                delegate
            {
                CollectionView.MoveCurrentToPosition(26);
            });
        }
        public void CannotAddNewTest()
        {
            // if the size of the collection is fixed, we are not allowed to add items to it.
            FixedSizeCollection <TestClass> fixedSizeCollection = new FixedSizeCollection <TestClass>();
            PagedCollectionView             pcv1 = new PagedCollectionView(fixedSizeCollection);

            Assert.IsFalse(pcv1.CanAddNew);

            // if the item type does not have a constructor, we are not allowed to call AddNew.
            List <int>          intList = new List <int>();
            PagedCollectionView pcv2    = new PagedCollectionView(intList);

            Assert.IsFalse(pcv2.CanAddNew);

            PagedCollectionViewTest.AssertExpectedException(
                new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, PagedCollectionViewResources.OperationNotAllowedForView, "AddNew")),
                delegate
            {
                pcv2.AddNew();
            });
        }
        public void CannotChangeNewItemPlaceholderPositionTests()
        {
            List <TestClass> intList = new List <TestClass>()
            {
                new TestClass()
            };
            PagedCollectionView pcv = new PagedCollectionView(intList);

            Assert.AreEqual(NewItemPlaceholderPosition.None, pcv.NewItemPlaceholderPosition);

            PagedCollectionViewTest.AssertExpectedException(
                new ArgumentException(
                    string.Format(CultureInfo.InvariantCulture,
                                  PagedCollectionViewResources.InvalidEnumArgument,
                                  "value",
                                  "123",
                                  typeof(NewItemPlaceholderPosition).Name)),
                delegate
            {
                pcv.NewItemPlaceholderPosition = (NewItemPlaceholderPosition)123;
            });
        }
        public void CultureTest()
        {
            // verify that Culture is set to null initially
            PagedCollectionView pcv = new PagedCollectionView(new List <int>());

            Assert.IsNull(pcv.Culture);

            // validate setting and retrieving the property
            pcv.Culture = CultureInfo.InvariantCulture;
            Assert.AreEqual(CultureInfo.InvariantCulture, pcv.Culture);

            pcv.Culture = CultureInfo.CurrentUICulture;
            Assert.AreEqual(CultureInfo.CurrentUICulture, pcv.Culture);

            // verify that if we try to set the value to null after it
            // has been set, we get an exception
            PagedCollectionViewTest.AssertExpectedException(
                new ArgumentNullException("value"),
                delegate
            {
                pcv.Culture = null;
            });
        }
        public void CancelCurrentChangingDuringPageSizeUpdate()
        {
            // if we don't implement IList, we cannot run the rest of
            // the test as we cannot add/remove items
            if (this.ImplementsIList)
            {
                CollectionView.CurrentChanging += new CurrentChangingEventHandler(CancelCurrentChanging);

                // add a new item
                TestClass newItem = CollectionView.AddNew() as TestClass;
                Assert.IsTrue(CollectionView.IsAddingNew);

                // verify that because the currency change is cancelled, we do not continue and throw
                PagedCollectionViewTest.AssertExpectedException(
                    new InvalidOperationException(PagedCollectionViewResources.ChangingPageSizeNotAllowedDuringAddOrEdit),
                    delegate
                {
                    CollectionView.PageSize = 10;
                });


                // now edit an item
                CollectionView.EditItem(CollectionView[0]);
                Assert.IsTrue(CollectionView.IsEditingItem);

                // verify that because the currency change is cancelled, we do not continue and throw
                PagedCollectionViewTest.AssertExpectedException(
                    new InvalidOperationException(PagedCollectionViewResources.ChangingPageSizeNotAllowedDuringAddOrEdit),
                    delegate
                {
                    CollectionView.PageSize = 10;
                });

                CollectionView.CurrentChanging -= new CurrentChangingEventHandler(CancelCurrentChanging);
            }
        }