public void Validated_Direct_Property_Receives_BindingNotifications() { var source = new ValidationTestModel { MustBePositive = 5 }; var target = new TestControl { DataContext = source, }; target.Bind( TestControl.ValidatedDirectProperty, new Binding(nameof(source.MustBePositive), BindingMode.TwoWay)); target.ValidatedDirect = 6; target.ValidatedDirect = -1; target.ValidatedDirect = 7; Assert.Equal( new[] { new BindingNotification(5), new BindingNotification(6), new BindingNotification(new ArgumentOutOfRangeException("value"), BindingErrorType.DataValidationError), new BindingNotification(7), }, target.Notifications.AsEnumerable()); }
public void TwoWay_Binding_Should_Be_Set_Up_GC_Collect() { var source = new WeakRefSource { Foo = null }; var target = new TestControl { DataContext = source }; var binding = new Binding { Path = "Foo", Mode = BindingMode.TwoWay }; target.Bind(TestControl.ValueProperty, binding); var ref1 = AssignValue(target, "ref1"); Assert.Equal(ref1.Target, source.Foo); GC.Collect(); GC.WaitForPendingFinalizers(); var ref2 = AssignValue(target, "ref2"); GC.Collect(); GC.WaitForPendingFinalizers(); target.Value = null; Assert.Null(source.Foo); }
public void Passed_Validation_Should_Not_Add_Invalid_Pseudo_Class() { var control = new TestControl(); var model = new ValidationTestModel { MustBePositive = 1 }; var binding = new Binding { Path = nameof(model.MustBePositive), Mode = BindingMode.TwoWay, EnableValidation = true, }; control.Bind(TestControl.ValidationTestProperty, binding); control.DataContext = model; Assert.DoesNotContain(control.Classes, x => x == ":invalid"); }
public void Enabled_Validation_Should_Trigger_Validation_Change_On_Exception() { var source = new ValidationTestModel { MustBePositive = 5 }; var target = new TestControl { DataContext = source }; var binding = new Binding { Path = nameof(source.MustBePositive), Mode = BindingMode.TwoWay, EnableValidation = true, }; target.Bind(TestControl.ValidationTestProperty, binding); target.ValidationTest = -5; Assert.False(target.ValidationStatus.IsValid); }