/// <summary>
        /// Creates an instance of the EditableTestClass, sets its properties
        /// based on the index it is provided with, and returns it.
        /// </summary>
        /// <param name="index">Index to use when calculating its properties</param>
        /// <returns>The EditableTestClass we generate</returns>
        private static EditableTestClass GetEditableTestClassInstance(int index)
        {
            EditableTestClass testClass = new EditableTestClass();

            testClass.IntProperty        = (index % 5) + 1;
            testClass.StringProperty     = (index % 2 == 0) ? "A" : "B";
            testClass.InnerClassProperty = new InnerClass()
            {
                InnerIntProperty = ((index % 2) + 1), InnerStringProperty = "InnerString"
            };

            return(testClass);
        }
示例#2
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);
            }
        }
        /// <summary>
        /// Creates an instance of the EditableTestClass, sets its properties
        /// based on the index it is provided with, and returns it.
        /// </summary>
        /// <param name="index">Index to use when calculating its properties</param>
        /// <returns>The EditableTestClass we generate</returns>
        private static EditableTestClass GetEditableTestClassInstance(int index)
        {
            EditableTestClass testClass = new EditableTestClass();
            testClass.IntProperty = (index % 5) + 1;
            testClass.StringProperty = (index % 2 == 0) ? "A" : "B";
            testClass.InnerClassProperty = new InnerClass() { InnerIntProperty = ((index % 2) + 1), InnerStringProperty = "InnerString" };

            return testClass;
        }