public void Entity_EndEditValidatesRequiredProperties()
        {
            // Start with an entity that doesn't have its required properties
            // satisfied (Name is required)
            Cities.City     city         = new Cities.City();
            IEditableObject editableCity = (IEditableObject)city;

            RequiredAttribute template           = new RequiredAttribute();
            string            expectedMemberName = "CityName";
            string            expectedError      = template.FormatErrorMessage(expectedMemberName);

            // Begin the edit transaction
            editableCity.BeginEdit();

#if SILVERLIGHT
            string expectedMember = "Name";

            // End the edit transaction, which performs property and entity-level validation
            editableCity.EndEdit();
            Assert.AreEqual <int>(1, city.ValidationErrors.Count, "After EndEdit");
            Assert.AreEqual <int>(1, city.ValidationErrors.Single().MemberNames.Count(), "MemberNames count after EndEdit");
            Assert.AreEqual <string>(expectedMember, city.ValidationErrors.Single().MemberNames.Single(), "Member name after EndEdit");
            Assert.AreEqual <string>(expectedError, city.ValidationErrors.Single().ErrorMessage, "ErrorMessage after EndEdit");
#else
            ExceptionHelper.ExpectException <ValidationException>(delegate
            {
                ((IEditableObject)city).EndEdit();
            }, expectedError);
#endif
        }
        public void Entity_EndEditValidatesPropertyValues()
        {
            // Start with an entity that has required properties satisfied, but has
            // an invalid property value (for StateName)
            Cities.City city = new Cities.City("This is an invalid state name")
            {
                Name = "Redmond"
            };
            IEditableObject editableCity = (IEditableObject)city;

            StringLengthAttribute template = new StringLengthAttribute(2);
            string expectedMember          = "StateName";
            string expectedError           = template.FormatErrorMessage(expectedMember);

            // Begin the edit transaction
            editableCity.BeginEdit();

#if SILVERLIGHT
            // End the edit transaction, which performs property and entity-level validation
            editableCity.EndEdit();
            Assert.AreEqual <int>(1, city.ValidationErrors.Count, "After EndEdit");
            Assert.AreEqual <int>(1, city.ValidationErrors.Single().MemberNames.Count(), "MemberNames count after EndEdit");
            Assert.AreEqual <string>(expectedMember, city.ValidationErrors.Single().MemberNames.Single(), "Member name after EndEdit");
            Assert.AreEqual <string>(expectedError, city.ValidationErrors.Single().ErrorMessage, "ErrorMessage after EndEdit");
#else
            ExceptionHelper.ExpectException <ValidationException>(delegate
            {
                ((IEditableObject)city).EndEdit();
            }, expectedError);
#endif
        }
Beispiel #3
0
        public void UpdateItemViaListSavedEvent()
        {
            UnitTestContext context = GetContext();

            DataPortal.ProxyTypeName = typeof(SynchronizedWcfProxy).AssemblyQualifiedName;
            WcfProxy.DefaultUrl      = cslalighttest.Properties.Resources.RemotePortalUrl;
            ApplicationContext.GlobalContext.Clear();

            RootSingleItemsList.GetRootSingleItemsList(1, 2, (o, e) =>
            {
                context.Assert.Try(() =>
                {
                    context.Assert.IsNotNull(e.Object);
                    RootSingleItemsList list = e.Object;
                    context.Assert.AreEqual(2, list.Count, "Count should be 2");
                    list.Saved += (o1, e1) =>
                    {
                        context.Assert.IsNull(e1.Error);
                        context.Assert.AreEqual(2, list.Count, "Incorrect count after remove");
                        context.Assert.AreEqual("DataPortal_Update", ((SingleItem)e1.NewObject).MethodCalled, "Object should have been updated");
                        context.Assert.IsFalse(list[0].IsDirty, "Object should not be dirty");
                        context.Assert.Success();
                    };

                    // simulate grid edit
                    SingleItem item     = list[0];
                    IEditableObject obj = (IEditableObject)item;
                    obj.BeginEdit();
                    item.Name = "test";
                    obj.EndEdit();
                });
            });
            context.Complete();
        }
        /// <summary>
        /// Puts the entity into editing mode if possible
        /// </summary>
        /// <param name="dataItem">The entity to edit</param>
        /// <returns>True if editing was started</returns>
        public bool BeginEdit(object dataItem)
        {
            if (dataItem == null)
            {
                return(false);
            }

            IEditableCollectionView editableCollectionView = this.EditableCollectionView;

            if (editableCollectionView != null)
            {
                if (editableCollectionView.IsEditingItem && (dataItem == editableCollectionView.CurrentEditItem))
                {
                    return(true);
                }
                else
                {
                    editableCollectionView.EditItem(dataItem);
                    return(editableCollectionView.IsEditingItem);
                }
            }

            IEditableObject editableDataItem = dataItem as IEditableObject;

            if (editableDataItem != null)
            {
                editableDataItem.BeginEdit();
                return(true);
            }

            return(true);
        }
Beispiel #5
0
        protected override void BeginEditCore()
        {
            var dataGridContext = DataGridControl.GetDataGridContext(this);

            var dataGridCollectionViewBase = dataGridContext == null ? null : dataGridContext.ItemsSourceCollection as DataGridCollectionViewBase;

            if (dataGridCollectionViewBase != null)
            {
                // We do not want to call EditItem when the item is the one in the insertionrow
                if (dataGridCollectionViewBase.CurrentAddItem != this.DataContext)
                {
                    dataGridCollectionViewBase.EditItem(this.DataContext);
                }
            }
            else
            {
                IEditableObject editableObject = this.EditableObject;

                // editableObject can be equal to this when the datarow is directly inserted as Item in the DataGridControl.
                if ((editableObject != null) && (editableObject != this))
                {
                    editableObject.BeginEdit();
                }
            }

            base.BeginEditCore();
        }
Beispiel #6
0
        private void DXWindow_Loaded(object sender, RoutedEventArgs e)
        {
            WizardDataModel.EndEditing += WizardDialog_EndEditing;
            IEditableObject editableObject = WizardDataModel;

            editableObject.BeginEdit();
        }
Beispiel #7
0
        /// <summary>
        /// Puts the entity into editing mode if possible
        /// </summary>
        /// <param name="dataItem">The entity to edit</param>
        /// <returns>True if editing was started</returns>
        public bool BeginEdit(object dataItem)
        {
            if (dataItem == null)
            {
                return(false);
            }

#if FEATURE_IEDITABLECOLLECTIONVIEW
            IEditableCollectionView editableCollectionView = this.EditableCollectionView;
            if (editableCollectionView != null)
            {
                if ((editableCollectionView.IsEditingItem && (dataItem == editableCollectionView.CurrentEditItem)) ||
                    (editableCollectionView.IsAddingNew && (dataItem == editableCollectionView.CurrentAddItem)))
                {
                    return(true);
                }
                else
                {
                    editableCollectionView.EditItem(dataItem);
                    return(editableCollectionView.IsEditingItem);
                }
            }
#endif

            IEditableObject editableDataItem = dataItem as IEditableObject;
            if (editableDataItem != null)
            {
                editableDataItem.BeginEdit();
                return(true);
            }

            return(true);
        }
        public void BeginEdit()
        {
            IEditableObject wrappedObject = _wrappedObject as IEditableObject;

            if (wrappedObject != null)
            {
                wrappedObject.BeginEdit();
            }
        }
Beispiel #9
0
        protected override void EndEditCore()
        {
            DataGridContext dataGridContext = DataGridControl.GetDataGridContext(this);

            base.EndEditCore();

            DataGridCollectionViewBase dataGridCollectionViewBase =
                (dataGridContext == null) ? null : dataGridContext.ItemsSourceCollection as DataGridCollectionViewBase;

            try
            {
                if (dataGridCollectionViewBase != null)
                {
                    if (dataGridCollectionViewBase.CurrentEditItem == this.DataContext)
                    {
                        dataGridCollectionViewBase.CommitEdit();
                    }
                }
                else
                {
                    IEditableObject editableObject = this.EditableObject;

                    // editableObject can be equal to this when the datarow is directly inserted as Items in the DataGridControl.
                    if ((editableObject != null) && (editableObject != this))
                    {
                        editableObject.EndEdit();
                    }
                }
            }
            catch (Exception exception)
            {
                // Note that we do not update the created cell's Content from the source in case the IEditableObject EndEdit implementation
                // throwed an exception.  This is mainly due because we want to make sure that we do not lose all of the edited cells values.
                // This way, the end user will have the chance to correct the mistakes without loosing everything he typed.

                // If EndEdit throwed, call BeginEdit on the IEditableObject to make sure that it stays in edit mode.
                // We don't have to do this when bound to a DataGridCollectionView since it will take care of it.
                if (dataGridCollectionViewBase == null)
                {
                    IEditableObject editableObject = this.EditableObject;

                    // editableObject can be equal to this when the datarow is directly inserted as Items in the DataGridControl.
                    if ((editableObject != null) && (editableObject != this))
                    {
                        editableObject.BeginEdit();
                    }
                }

                // This method will set a validation error on the row and throw back a DataGridValidationException so that
                // the row stays in edition.
                Row.SetRowValidationErrorOnException(this, exception);
            }

            // Update the created cell's Content from the source in case the IEditableObject EndEdit implementation rectified
            // some values.
            this.UpdateCellsContentBindingTarget();
        }
Beispiel #10
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            if (DataContext is IEditableObject)
            {
                _context = (IEditableObject)DataContext;
            }

            var edit = (Button)GetTemplateChild("EditButton");

            edit.Click += (s, e) =>
            {
                if (_context != null)
                {
                    _context.BeginEdit();
                }
                _hostContent.ContentTemplate = EditTemplate;
                VisualStateManager.GoToState(this, "Edit", true);
            };

            var cancelEdit = (Button)GetTemplateChild("CancelButton");

            cancelEdit.Click += (s, e) =>
            {
                if (_context != null)
                {
                    _context.CancelEdit();
                }
                _hostContent.ContentTemplate = ReadOnlyTemplate;
                VisualStateManager.GoToState(this, "ReadOnly", true);
            };

            var saveButton = (Button)GetTemplateChild("SaveButton");

            saveButton.Click += (s, e) =>
            {
                if (_context != null)
                {
                    if (_context is ICanSave)
                    {
                        if (((ICanSave)_context).CanSave())
                        {
                            _context.EndEdit();
                            _hostContent.ContentTemplate = ReadOnlyTemplate;
                            VisualStateManager.GoToState(this, "ReadOnly", true);
                        }
                    }
                }
            };

            _hostContent                 = (ContentControl)GetTemplateChild("HostContent");
            _hostContent.Content         = DataContext;
            _hostContent.ContentTemplate = ReadOnlyTemplate;
        }
        protected internal virtual void SetColumnValueAtRow(CurrencyManager source, int rowNum, object value)
        {
            CheckValidDataSource(source);

            IEditableObject editable = source [rowNum] as IEditableObject;

            if (editable != null)
            {
                editable.BeginEdit();
            }

            property_descriptor.SetValue(source [rowNum], value);
        }
Beispiel #12
0
        private static void CanCreateADynamicMultiMockFromTwoInterfacesCommon(MockRepository mocks, IDemo demo, IEditableObject editable)
        {
            Assert.NotNull(demo);
            Assert.NotNull(editable);

            // Set expectation on one member on each interface

            Expect.Call(demo.ReadOnly).Return("foo");
            editable.BeginEdit();

            mocks.ReplayAll();

            // Drive two members on each interface to check dynamic nature

            Assert.Equal("foo", demo.ReadOnly);
            demo.VoidNoArgs();

            editable.BeginEdit();
            editable.EndEdit();

            mocks.VerifyAll();
        }
Beispiel #13
0
    public void AsyncLoadManagerSerializationTest()
    {
      Csla.Test.Basic.Children list = Csla.Test.Basic.Children.NewChildren();
      list.Add("1");
      list.Add("2");
      IEditableObject item = list[1] as IEditableObject;
      int editLevel = (int)item.GetType().GetProperty("EditLevel", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.FlattenHierarchy).GetValue(item, null);
      object manager = item.GetType().GetProperty("LoadManager", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.FlattenHierarchy).GetValue(item, null);

      item.BeginEdit();
      int newEditLevel = (int)item.GetType().GetProperty("EditLevel", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.FlattenHierarchy).GetValue(item, null);
      Assert.AreEqual(editLevel + 1, newEditLevel, "Edit level incorrect after begin edit");
    }
Beispiel #14
0
 public void BeginEdit()
 {
     if (!beginEditCalled)
     {
         this.backupData = custData;
         beginEditCalled = true;
         Console.WriteLine("BeginEdit - " + this.backupData.lastName);
         if (ForwardEditableObject != null)
         {
             ForwardEditableObject.BeginEdit();
         }
         modified = false;
     }
 }
Beispiel #15
0
        /// <summary>
        /// Override this to provide the logic that undoes the action
        /// </summary>
        protected override void UnExecuteCore()
        {
            IEditableObject edit = ParentObject as IEditableObject;

            if (edit != null)
            {
                edit.BeginEdit();
            }
            Property.SetValue(ParentObject, OldValue, null);
            if (edit != null)
            {
                edit.EndEdit();
            }
        }
Beispiel #16
0
        protected void AddEditDependency(IEditableObject editDependency)
        {
            if (IsEditing)
            {
                if (editDependencies == null)
                {
                    editDependencies = new HashSet <IEditableObject>();
                }

                if (editDependencies.Add(editDependency))
                {
                    editDependency.BeginEdit();
                }
            }
        }
Beispiel #17
0
        void BeginEdit()
        {
            IEditableObject editable = Current as IEditableObject;

            if (editable != null)
            {
                try {
                    editable.BeginEdit();
                    editing = true;
                }
                catch {
                    /* swallow exceptions in IEditableObject.BeginEdit () */
                }
            }
        }
Beispiel #18
0
        private void SetSubPropertyValue(string propertyPath, object dataObject, object value)
        {
            PropertyDescriptor innerDescriptor = (PropertyDescriptor)null;
            object             innerObject     = (object)null;

            this.GetSubPropertyByPath(propertyPath, dataObject, out innerDescriptor, out innerObject);
            if (innerDescriptor == null)
            {
                return;
            }
            IEditableObject editableObject = innerObject as IEditableObject;

            editableObject?.BeginEdit();
            innerDescriptor.SetValue(innerObject, value);
            editableObject?.EndEdit();
        }
Beispiel #19
0
        public void EditDataSource()
        {
            DataSourceWrapper dsw            = SelectedDataSource;
            IEditableObject   editableObject = dsw;

            editableObject.BeginEdit();
            bool acceptChanges = OpenDataSourceEditor(dsw);

            if (acceptChanges)
            {
                dsw.DoEndEdit();
            }
            else
            {
                dsw.DoCancelEdit();
            }
        }
        public void CanCreateADynamicMultiMockFromTwoInterfacesGenericAndAssertWasCalled()
        {
            IDemo           demo     = MockRepository.GenerateMock <IDemo, IEditableObject>();
            IEditableObject editable = demo as IEditableObject;

            demo.ReturnIntNoArgs();
            editable.BeginEdit();
            editable.CancelEdit(); // we don't care about this
            editable.EndEdit();

            demo.AssertWasCalled(x => x.ReturnIntNoArgs());
            editable.AssertWasCalled(x => x.BeginEdit());
            editable.AssertWasCalled(x => x.EndEdit());

            // Double check all expectations were verified
            editable.VerifyAllExpectations();
        }
Beispiel #21
0
        public void EditQuery()
        {
            QueryWrapper    qw             = SelectedDataSource.SelectedQuery;
            IEditableObject editableObject = qw;

            editableObject.BeginEdit();
            bool acceptChanges = OpenQueryEditor(qw);

            if (acceptChanges)
            {
                qw.DoEndEdit();
                SelectedDataSource.SelectedQuery = qw;
            }
            else
            {
                qw.DoCancelEdit();
            }
        }
Beispiel #22
0
        public int Add(params object[] values)
        {
            if (this.owner.IsVirtualRows)
            {
                return(-1);
            }
            GridViewRowInfo gridViewRowInfo1 = values[0] as GridViewRowInfo;

            if (gridViewRowInfo1 != null)
            {
                this.Add(gridViewRowInfo1);
                return(gridViewRowInfo1.Index);
            }
            if (this.OnRowsChanging(new GridViewCollectionChangingEventArgs(this.owner, NotifyCollectionChangedAction.Add, (object)null, this.Count, -1)))
            {
                return(-1);
            }
            bool notifyUpdates = this.Count == 0;

            this.owner.ListSource.BeginUpdate();
            GridViewRowInfo gridViewRowInfo2 = this.owner.ListSource.AddNew();
            IEditableObject dataBoundItem    = gridViewRowInfo2.DataBoundItem as IEditableObject;

            dataBoundItem?.BeginEdit();
            int num = Math.Min(this.owner.Columns.Count, values.Length);

            for (int index = 0; index < num; ++index)
            {
                GridViewDataColumn column = this.owner.Columns[index];
                gridViewRowInfo2[(GridViewColumn)column] = RadDataConverter.Instance.Parse((IDataConversionInfoProvider)column, values[index]);
            }
            dataBoundItem?.EndEdit();
            this.owner.ListSource.EndUpdate(notifyUpdates);
            ((ICancelAddNew)this.owner.ListSource).EndNew(this.owner.ListSource.Count - 1);
            gridViewRowInfo2.Attach();
            if (this.owner.DataSource == null && this.owner.SortDescriptors.Count > 0)
            {
                this.owner.SortDescriptors.BeginUpdate();
                this.owner.SortDescriptors.EndUpdate(true);
            }
            return(gridViewRowInfo2.Index);
        }
Beispiel #23
0
        public void AddQuery()
        {
            var             qw             = QueryWrapper.Create();
            IEditableObject editableObject = qw;

            qw.OwnerDataSource = SelectedDataSource;
            editableObject.BeginEdit();
            bool acceptChanges = OpenQueryEditor(qw);

            if (acceptChanges)
            {
                qw.DoEndEdit();
                SelectedDataSource.Queries.Add(qw);
                SelectedDataSource.SelectedQuery = qw;
            }
            else
            {
                qw.DoCancelEdit();
            }
        }
Beispiel #24
0
        protected override bool OnBeginEdit()
        {
            IEditableObject dataBoundItem = this.DataBoundItem as IEditableObject;

            if (dataBoundItem != null)
            {
                try
                {
                    this.ViewTemplate.ListSource.BeginUpdate();
                    dataBoundItem.BeginEdit();
                }
                catch (Exception ex)
                {
                    this.ViewTemplate.SetError(new GridViewCellCancelEventArgs((GridViewRowInfo)this, (GridViewColumn)null, (IInputEditor)null), ex);
                }
                finally
                {
                    this.ViewTemplate.ListSource.EndUpdate(false);
                }
            }
            return(base.OnBeginEdit());
        }
Beispiel #25
0
        public bool BeginEdit(object dataItem)
        {
            if (dataItem == null)
            {
                return(false);
            }

            //



            IEditableObject editableDataItem = dataItem as IEditableObject;

            if (editableDataItem != null)
            {
                editableDataItem.BeginEdit();
                return(true);
            }

            //

            return(true);
        }
        protected void AddEditDependency(IEditableObject editDependency)
        {
            if (IsEditing)
            {
                if (editDependencies == null)
                {
#if SL3
                    editDependencies = new List <IEditableObject>();
#else
                    editDependencies = new HashSet <IEditableObject>();
#endif
                }

#if SL3
                if (AddDependency(editDependency))
#else
                if (editDependencies.Add(editDependency))
#endif
                {
                    editDependency.BeginEdit();
                }
            }
        }
Beispiel #27
0
        public void DeleteSelection()
        {
            if (MapControl.SelectTool.FeatureEditors.Count == 0)
            {
                return;
            }
            int featuresDeleted = 0;

            IEditableObject editableObject = MapControl.SelectTool.FeatureEditors[0].EditableObject;

            for (int i = 0; i < MapControl.SelectTool.FeatureEditors.Count; i++)
            {
                IFeatureEditor featureMutator = MapControl.SelectTool.FeatureEditors[i];
                if (!featureMutator.AllowDeletion())
                {
                    continue;
                }

                if (featuresDeleted == 0 && editableObject != null)
                {
                    editableObject.BeginEdit("Delete feature(s)");
                }

                featureMutator.Delete();
                featuresDeleted++;
            }
            if (featuresDeleted > 0)
            {
                // Better not to reset the selection if you haven't done anything.
                MapControl.SelectTool.Clear();

                if (editableObject != null)
                {
                    editableObject.EndEdit();
                }
            }
        }
Beispiel #28
0
        public void UncommitedEntityEdits()
        {
            Northwind ctxt = new Northwind(TestURIs.LTS_Northwind);
            Product   prod = new Product
            {
                ProductID   = 1,
                ProductName = "Cheezy Tots"
            };

            ctxt.EntityContainer.LoadEntities(new Entity[] { prod });

            // start an edit session and calculate
            // changes w/o ending the session
            IEditableObject eo = (IEditableObject)prod;

            eo.BeginEdit();
            prod.ProductName = "Chikn Crisps";
            Assert.IsTrue(prod.HasChanges);
            Assert.IsTrue(prod.IsEditing);
            EntityChangeSet cs = ctxt.EntityContainer.GetChanges();

            Assert.AreEqual(1, cs.ModifiedEntities.Count);

            // however, attempting to call submit will result in
            // an exception
            ExceptionHelper.ExpectInvalidOperationException(delegate
            {
                ctxt.SubmitChanges(TestHelperMethods.DefaultOperationAction, null);
            }, string.Format(Resource.Entity_UncommittedChanges, prod));

            // end the session
            eo.EndEdit();
            Assert.IsFalse(prod.IsEditing);
            cs = ctxt.EntityContainer.GetChanges();
            Assert.AreEqual(1, cs.ModifiedEntities.Count);
        }
        public void TestEditableObjectTextAndValue()
        {
            GenericParameterHelper para1 = new GenericParameterHelper(1);
            GenericParameterHelper para2 = new GenericParameterHelper(2);
            TextValuePair <GenericParameterHelper> target =
                new TextValuePair <GenericParameterHelper>("AA", para1);
            IEditableObject obj      = (IEditableObject)target;
            bool            changing = false;
            bool            changed  = false;
            bool            error    = false;

            target.PropertyChanging += (sender, e) =>
            {
                if (e.PropertyName == string.Empty)
                {
                    changing = true;
                    if (target.Text != "AA" || target.Value != para1)
                    {
                        error = true;
                    }
                }
            };
            target.PropertyChanged += (sender, e) =>
            {
                if (changing && e.PropertyName == string.Empty)
                {
                    changed = true;
                    if (target.Text != "BB" || target.Value != para2)
                    {
                        error = true;
                    }
                }
            };
            // Test Text And Value
            obj.BeginEdit();
            target.Text  = "BB";
            target.Value = para2;
            Assert.IsFalse(error);
            Assert.IsFalse(changing);
            Assert.IsFalse(changed);
            obj.CancelEdit();
            Assert.AreEqual(target.Text, "AA");
            Assert.AreEqual(target.Value, para1);
            Assert.IsFalse(error);
            Assert.IsFalse(changing);
            Assert.IsFalse(changed);
            obj.EndEdit();
            Assert.AreEqual(target.Text, "AA");
            Assert.AreEqual(target.Value, para1);
            Assert.IsFalse(error);
            Assert.IsFalse(changing);
            Assert.IsFalse(changed);
            obj.CancelEdit();
            Assert.AreEqual(target.Text, "AA");
            Assert.AreEqual(target.Value, para1);
            Assert.IsFalse(error);
            Assert.IsFalse(changing);
            Assert.IsFalse(changed);
            obj.BeginEdit();
            target.Text  = "BB";
            target.Value = para2;
            obj.EndEdit();
            Assert.AreEqual(target.Text, "BB");
            Assert.AreEqual(target.Value, para2);
            Assert.IsFalse(error);
            Assert.IsTrue(changing);
            Assert.IsTrue(changed);
            changing = false;
            changed  = false;
            obj.CancelEdit();
            Assert.AreEqual(target.Text, "BB");
            Assert.AreEqual(target.Value, para2);
            Assert.IsFalse(error);
            Assert.IsFalse(changing);
            Assert.IsFalse(changed);
            // Test Text And Value without change
            changing = changed = error = false;
            obj.BeginEdit();
            target.Text  = "BB";
            target.Value = para2;
            obj.EndEdit();
            Assert.IsFalse(error);
            Assert.IsFalse(changing);
            Assert.IsFalse(changed);
        }
        public void TestEditableObjectText()
        {
            TextValuePair <GenericParameterHelper> target =
                new TextValuePair <GenericParameterHelper>("AA", null);
            IEditableObject obj      = (IEditableObject)target;
            bool            changing = false;
            bool            changed  = false;
            bool            error    = false;

            target.PropertyChanging += (sender, e) =>
            {
                if (e.PropertyName == "Text")
                {
                    changing = true;
                    if (target.Text != "AA")
                    {
                        error = true;
                    }
                }
            };
            target.PropertyChanged += (sender, e) =>
            {
                if (changing && e.PropertyName == "Text")
                {
                    changed = true;
                    if (target.Text != "BB")
                    {
                        error = true;
                    }
                }
            };
            // Test Text
            obj.BeginEdit();
            target.Text = "BB";
            Assert.IsFalse(error);
            Assert.IsFalse(changing);
            Assert.IsFalse(changed);
            obj.CancelEdit();
            Assert.AreEqual(target.Text, "AA");
            Assert.IsFalse(error);
            Assert.IsFalse(changing);
            Assert.IsFalse(changed);
            obj.EndEdit();
            Assert.AreEqual(target.Text, "AA");
            Assert.IsFalse(error);
            Assert.IsFalse(changing);
            Assert.IsFalse(changed);
            obj.CancelEdit();
            Assert.AreEqual(target.Text, "AA");
            Assert.IsFalse(error);
            Assert.IsFalse(changing);
            Assert.IsFalse(changed);
            obj.BeginEdit();
            target.Text = "BB";
            obj.EndEdit();
            Assert.AreEqual(target.Text, "BB");
            Assert.IsFalse(error);
            Assert.IsTrue(changing);
            Assert.IsTrue(changed);
            changing = false;
            changed  = false;
            obj.CancelEdit();
            Assert.AreEqual(target.Text, "BB");
            Assert.IsFalse(error);
            Assert.IsFalse(changing);
            Assert.IsFalse(changed);
            // Test Text without change
            changing = changed = error = false;
            obj.BeginEdit();
            target.Text = "BB";
            obj.EndEdit();
            Assert.IsFalse(error);
            Assert.IsFalse(changing);
            Assert.IsFalse(changed);
        }
Beispiel #31
0
        private static void CanCreateADynamicMultiMockFromTwoInterfacesCommon(MockRepository mocks, IDemo demo, IEditableObject editable)
        {
            Assert.NotNull(demo);
            Assert.NotNull(editable);

            // Set expectation on one member on each interface

            Expect.Call(demo.ReadOnly).Return("foo");
            editable.BeginEdit();

            mocks.ReplayAll();

            // Drive two members on each interface to check dynamic nature

            Assert.Equal("foo", demo.ReadOnly);
            demo.VoidNoArgs();

            editable.BeginEdit();
            editable.EndEdit();

            mocks.VerifyAll();
        }
		protected void AddEditDependency(IEditableObject editDependency)
		{
			if (IsEditing)
			{
				if (editDependencies == null)
				{
					editDependencies = new HashSet<IEditableObject>();
				}

				if (editDependencies.Add(editDependency))
				{
					editDependency.BeginEdit();
				}
			}
		}
        private static void CanCreateADynamicMultiMockFromTwoInterfacesCommon(IDemo demo, IEditableObject editable)
        {
            Assert.IsNotNull(demo, "IDemo null");
              Assert.IsNotNull(editable, "IEditableObject null");

              // Set expectation on one member on each interface

              demo.Expect(x => demo.ReadOnly).Return("foo");
              editable.Expect(x => x.BeginEdit());

              // Drive two members on each interface to check dynamic nature

              Assert.AreEqual("foo", demo.ReadOnly);
              demo.VoidNoArgs();

              editable.BeginEdit();
              editable.EndEdit();

              demo.VerifyAllExpectations();
        }