public void CurrentAddItemTest() { // verify that the property is null when we are not adding Assert.IsNull(CollectionView.CurrentAddItem); // add a new item and verify that the property is set object newItem = CollectionView.AddNew(); Assert.AreEqual(newItem, CollectionView.CurrentAddItem); // verify that once we are done adding, the property will revert to null CollectionView.CancelNew(); Assert.IsNull(CollectionView.CurrentAddItem); }
public void AddNewOnFilteredCollection() { // add a filter to the collection CollectionView.Filter = FilterOutOnes; // now add an item and verify that it is added as the last item object addItem = CollectionView.AddNew(); Assert.AreEqual(CollectionView.Count - 1, CollectionView.IndexOf(addItem)); CollectionView.CancelNew(); // verify that this holds for paging as well CollectionView.PageSize = 10; addItem = CollectionView.AddNew(); Assert.AreEqual(CollectionView.Count - 1, CollectionView.IndexOf(addItem)); }
public void CancelNewTest() { // assert that the count is updated when we add a new item // and that the item is within the view. Assert.AreEqual(25, CollectionView.Count); TestClass addItem = CollectionView.AddNew() as TestClass; Assert.AreEqual(26, CollectionView.Count); Assert.IsTrue(CollectionView.IndexOf(addItem) >= 0); // now verify that when we cancel teh add, the item no longer // appears in the view and the count is decremented. CollectionView.CancelNew(); Assert.AreEqual(25, CollectionView.Count); Assert.IsFalse(CollectionView.IndexOf(addItem) >= 0); }
public void IEditableObject() { // we only want to run this test for items that implement IEditableObject // and where the source collection won't handle the editing first EditableTestClass editItem = CollectionView[0] as EditableTestClass; if (editItem == null) { return; } // check that the debug string has not been set Assert.IsNull(editItem.DebugString); // verify that BeginEdit was called on the IEditable interface CollectionView.EditItem(editItem); Assert.AreEqual("BeginEdit", editItem.DebugString); // verify that CancelEdit was called on the IEditable interface CollectionView.CancelEdit(); Assert.AreEqual("CancelEdit", editItem.DebugString); // verify that EndEdit was called on the IEditable interface CollectionView.EditItem(editItem); CollectionView.CommitEdit(); Assert.AreEqual("EndEdit", editItem.DebugString); // if we don't implement IList, we cannot run the rest of // the test as we cannot add/remove items if (this.ImplementsIList) { // verify that when adding a new item, it will call BeginEdit on it editItem = CollectionView.AddNew() as EditableTestClass; Assert.AreEqual("BeginEdit", editItem.DebugString); // verify that when canceling the new item, it will call CancelEdit on it. CollectionView.CancelNew(); Assert.AreEqual("CancelEdit", editItem.DebugString); // verify that when committing a new item, it will call EndEdit on it. editItem = CollectionView.AddNew() as EditableTestClass; CollectionView.CommitNew(); Assert.AreEqual("EndEdit", editItem.DebugString); } }
public void IsAddingNewTest() { // verify that the property is false when we are not adding Assert.IsFalse(CollectionView.IsAddingNew); // add a new item and verify that the property is set CollectionView.AddNew(); Assert.IsTrue(CollectionView.IsAddingNew); // verify that once we are cancel adding, the property will revert to false CollectionView.CancelNew(); Assert.IsFalse(CollectionView.IsAddingNew); // add an item again CollectionView.AddNew(); Assert.IsTrue(CollectionView.IsAddingNew); // verify that once we are commit the add, the property will revert to false CollectionView.CommitNew(); Assert.IsFalse(CollectionView.IsAddingNew); }
public void AddNewTest() { // verify the the count gets updated when we add items Assert.AreEqual(25, CollectionView.Count); CollectionView.AddNew(); Assert.AreEqual(26, CollectionView.Count); CollectionView.CommitNew(); Assert.AreEqual(26, CollectionView.Count); // verify that we can call an AddNew, when there is already // an add in progress (it will commit the previous add and // start a new add). object addItem = CollectionView.AddNew(); CollectionView.AddNew(); Assert.AreNotEqual(addItem, CollectionView.CurrentAddItem); CollectionView.CommitNew(); Assert.AreEqual(28, CollectionView.Count); // also the same applies for when we edit items. by calling // AddNew, we will commit the edit and start a new add operation CollectionView.EditItem(CollectionView[0]); Assert.IsTrue(CollectionView.IsEditingItem); addItem = CollectionView.AddNew(); Assert.IsFalse(CollectionView.IsEditingItem); Assert.AreEqual(addItem, CollectionView.CurrentAddItem); CollectionView.CancelNew(); // verify that AddNew succeeds even on empty collections that // implement IEnumerable<T> Assert.IsTrue(CollectionView.CanRemove); while (CollectionView.Count > 0) { CollectionView.RemoveAt(0); } addItem = CollectionView.AddNew(); Assert.IsNotNull(addItem); CollectionView.CancelNew(); }
public void CannotCommitOrCancelNewDuringEdit() { // verify that we cannot commit new during an edit CollectionView.EditItem(CollectionView[0]); AssertExpectedException( new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, PagedCollectionViewResources.OperationNotAllowedDuringTransaction, "CommitNew", "EditItem")), delegate { CollectionView.CommitNew(); }); // verify that we cannot cancel new during an edit CollectionView.EditItem(CollectionView[0]); AssertExpectedException( new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, PagedCollectionViewResources.OperationNotAllowedDuringTransaction, "CancelNew", "EditItem")), delegate { CollectionView.CancelNew(); }); }