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 ValidateShouldReturnResult() { ValidationTestModel model = new ValidationTestModel(); var results = model.Validate(); Assert.That(results.Count(), Is.GreaterThan(0)); Assert.That(results.Count(r => r.MemberNames.Contains("Title")), Is.GreaterThan(0)); Assert.That(results.Count(r => r.MemberNames.Contains("Name")), Is.GreaterThan(0)); }
public void ValidatePropertyShouldReturnResultForProperty() { ValidationTestModel model = new ValidationTestModel(); var results = model.ValidateProperty(() => model.Title); Assert.That(results.Count(), Is.GreaterThan(0)); Assert.That(results.Count(r => r.MemberNames.Contains("Title")), Is.GreaterThan(0)); Assert.That(results.Count(r => r.MemberNames.Contains("Name")), Is.EqualTo(0)); }
public ActionResult Index(ValidationTestModel user) { if (ModelState.IsValid) { // Do whatever posting needs to be done here ModelState.Clear(); return(View(new ValidationTestModel())); } return(View()); }
public void Non_Validated_Property_Does_Not_Receive_BindingNotifications() { var source = new ValidationTestModel { MustBePositive = 5 }; var target = new TestControl { DataContext = source, [!TestControl.NonValidatedProperty] = new Binding(nameof(source.MustBePositive)), }; Assert.Empty(target.Notifications); }
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); }