/// <summary> /// Cancels an edit. /// </summary> public void CancelEdit() { if (this.oldDataClass != null) { this.boolProperty = this.oldDataClass.boolProperty; this.dateTimeProperty = this.oldDataClass.dateTimeProperty; this.intProperty = this.oldDataClass.intProperty; this.intPropertyWithoutAutoGenerateField = this.oldDataClass.intPropertyWithoutAutoGenerateField; this.nonGeneratedIntProperty = this.oldDataClass.nonGeneratedIntProperty; this.stringProperty = this.oldDataClass.stringProperty; this.oldDataClass = null; } }
/// <summary> /// Begins an edit. /// </summary> public void BeginEdit() { if (this.oldDataClass == null) { this.oldDataClass = new DataClassWithValidation(); this.oldDataClass.boolProperty = this.boolProperty; this.oldDataClass.dateTimeProperty = this.dateTimeProperty; this.oldDataClass.intProperty = this.intProperty; this.oldDataClass.intPropertyWithoutAutoGenerateField = this.intPropertyWithoutAutoGenerateField; this.oldDataClass.nonGeneratedIntProperty = this.nonGeneratedIntProperty; this.oldDataClass.stringProperty = this.stringProperty; } }
/// <summary> /// Initializes the unchanged data class used in IRevertableChangeTracking. /// </summary> private void EnsureUnchangedDataClass() { if (this.unchangedDataClass == null) { this.unchangedDataClass = new DataClassWithValidation(); this.unchangedDataClass.boolProperty = this.boolProperty; this.unchangedDataClass.dateTimeProperty = this.dateTimeProperty; this.unchangedDataClass.intProperty = this.intProperty; this.unchangedDataClass.intPropertyWithoutAutoGenerateField = this.intPropertyWithoutAutoGenerateField; this.unchangedDataClass.nonGeneratedIntProperty = this.nonGeneratedIntProperty; this.unchangedDataClass.stringProperty = this.stringProperty; } }
public static ValidationResult IsDataClassWithValidationValid(object value, ValidationContext context) { DataClassWithValidation dataClassWithValidation = value as DataClassWithValidation; if (dataClassWithValidation == null) { return(new ValidationResult(null)); } if (dataClassWithValidation.IntProperty.ToString(CultureInfo.InvariantCulture) == dataClassWithValidation.StringProperty) { return(new ValidationResult("IntProperty cannot be equal to StringProperty.")); } return(ValidationResult.Success); }
public void TestObjectLevelValidationFromExternalChanges() { ValidationSummary validationSummary = null; this.AddToPanelAndWaitForLoad(); this.EnqueueCallback(() => { validationSummary = this.GetTemplatePart <ValidationSummary>("ValidationSummary"); Assert.IsTrue(this.DataForm.IsItemValid); this.ExpectContentLoaded(); this.DataForm.BeginEdit(); }); this.WaitForContentLoaded(); this.EnqueueCallback(() => { this.GetInputControls(); SetValue(this.textBox, "1"); this.CommitAllFields(); Assert.IsTrue(this.DataForm.IsItemValid); Assert.AreEqual(0, validationSummary.Errors.Count); this.ExpectEditEnded(); this.DataForm.CommitEdit(true /* exitEditingMode */); Assert.IsTrue(this.DataForm.IsEditing); Assert.IsFalse(this.DataForm.IsItemValid); Assert.AreEqual(1, validationSummary.Errors.Count); Assert.AreEqual(this.comboBox, validationSummary.Errors[0].Sources[0].Control); Assert.AreEqual(this.textBox, validationSummary.Errors[0].Sources[1].Control); Assert.AreEqual("IntProperty cannot be equal to StringProperty.", validationSummary.Errors[0].Message); DataClassWithValidation dataClass = this.DataForm.CurrentItem as DataClassWithValidation; dataClass.StringProperty = "test string 1"; Assert.IsTrue(this.DataForm.IsItemValid); Assert.AreEqual(0, validationSummary.Errors.Count); }); this.EnqueueTestComplete(); }
public void EnsureExceptionThrownWhenCurrencyChangesWithValidationError() { DataFormApp_Fields dataFormApp = new DataFormApp_Fields(); DataClassWithValidation dataClass = new DataClassWithValidation() { StringProperty = "test string 0" }; dataFormApp.dataForm.CurrentItem = dataClass; this.EnqueueCallback(() => { this.DataFormAppBase = dataFormApp; }); this.AddToPanelAndWaitForLoad(); this.EnqueueCallback(() => { this.ExpectContentLoaded(); dataFormApp.dataForm.BeginEdit(); }); this.WaitForContentLoaded(); this.EnqueueCallback(() => { TextBox textBox = this.DataFormInputControls[2] as TextBox; textBox.Text = string.Empty; dataFormApp.dataForm.CommitEdit(true /* exitEditingMode */); Assert.IsFalse(dataFormApp.dataForm.IsItemValid); bool changingCurrentItemSucceeded = false; try { dataFormApp.dataForm.CurrentItem = new DataClass(); changingCurrentItemSucceeded = true; } catch (InvalidOperationException) { } Assert.IsFalse(changingCurrentItemSucceeded); Assert.AreEqual(dataClass, dataFormApp.dataForm.CurrentItem); }); this.EnqueueTestComplete(); }
public void EnsureExceptionThrownWhenCurrencyChangesWhenEditingWithAutoCommitFalse() { DataFormApp_Fields dataFormApp = new DataFormApp_Fields(); dataFormApp.dataForm.AutoCommit = false; DataClassWithValidation dataClass = new DataClassWithValidation() { StringProperty = "test string 0" }; dataFormApp.dataForm.CurrentItem = dataClass; this.EnqueueCallback(() => { this.DataFormAppBase = dataFormApp; }); this.AddToPanelAndWaitForLoad(); this.EnqueueCallback(() => { this.ExpectContentLoaded(); dataFormApp.dataForm.BeginEdit(); }); this.WaitForContentLoaded(); this.EnqueueCallback(() => { TextBox textBox = this.DataFormInputControls[2] as TextBox; textBox.Text = "new string"; BindingExpression bindingExpression = textBox.GetBindingExpression(TextBox.TextProperty); Assert.IsNotNull(bindingExpression); bindingExpression.UpdateSource(); bool changingCurrentItemSucceeded = false; try { dataFormApp.dataForm.CurrentItem = new DataClass(); changingCurrentItemSucceeded = true; } catch (InvalidOperationException) { } Assert.IsFalse(changingCurrentItemSucceeded); Assert.AreEqual(dataClass, dataFormApp.dataForm.CurrentItem); }); this.EnqueueTestComplete(); }
/// <summary> /// Ends an edit. /// </summary> public void EndEdit() { this.oldDataClass = null; }
/// <summary> /// Cancels an edit. /// </summary> public void CancelEdit() { if (this.oldDataClass != null) { this.BoolProperty = this.oldDataClass.boolProperty; this.DateTimeProperty = this.oldDataClass.dateTimeProperty; this.IntProperty = this.oldDataClass.intProperty; this.IntPropertyWithoutAutoGenerateField = this.oldDataClass.intPropertyWithoutAutoGenerateField; this.NonGeneratedIntProperty = this.oldDataClass.nonGeneratedIntProperty; this.StringProperty = this.oldDataClass.stringProperty; this.oldDataClass = null; } }
/// <summary> /// Begins an edit. /// </summary> public void BeginEdit() { if (this.oldDataClass == null) { this.oldDataClass = new DataClassWithValidation(); this.oldDataClass.boolProperty = this.boolProperty; this.oldDataClass.dateTimeProperty = this.dateTimeProperty; this.oldDataClass.intProperty = this.intProperty; this.oldDataClass.intPropertyWithoutAutoGenerateField = this.intPropertyWithoutAutoGenerateField; this.oldDataClass.nonGeneratedIntProperty = this.nonGeneratedIntProperty; this.oldDataClass.stringProperty = this.stringProperty; } }
/// <summary> /// Initializes the unchanged data class used in IRevertableChangeTracking. /// </summary> private void EnsureUnchangedDataClass() { if (this.unchangedDataClass == null) { this.unchangedDataClass = new DataClassWithValidation(); this.unchangedDataClass.boolProperty = this.boolProperty; this.unchangedDataClass.dateTimeProperty = this.dateTimeProperty; this.unchangedDataClass.intProperty = this.intProperty; this.unchangedDataClass.intPropertyWithoutAutoGenerateField = this.intPropertyWithoutAutoGenerateField; this.unchangedDataClass.nonGeneratedIntProperty = this.nonGeneratedIntProperty; this.unchangedDataClass.stringProperty = this.stringProperty; } }
/// <summary> /// Ends an edit. /// </summary> public void EndEdit() { this.oldDataClass = null; }