예제 #1
0
        public void ValidatingHandler(object sender, CancelEventArgs e)
        {
            System.Type entityType = vvtor.GetEntityType((Control) sender);

            ClassValidator vtor = new ClassValidator(entityType);

            IControlValuable controlValuable = vvtor.Resolver.GetControlValuable(sender);

            IEnumerable<InvalidValue> errors = vtor.GetPotentialInvalidValues(GetPropertyName((Control) sender),controlValuable.GetValue((Control)sender));
            int i = 0;

            foreach (InvalidValue error in errors)
            {
                errorProvider.SetError((TextBox)sender, error.Message);
                i++;
            }

            if (i == 0)
                errorProvider.SetError((TextBox) sender, string.Empty);
        }
 public void WhenTagIsSpecified_ValidatePotentialValueForGivenTags()
 {
     IClassValidator cv = new ClassValidator(typeof(EntityForPotential));
     cv.GetPotentialInvalidValues("Value", "123", typeof(Warning)).Should().Have.Count.EqualTo(1);
     cv.GetPotentialInvalidValues("Value", "", typeof(Warning)).Should().Have.Count.EqualTo(2);
     cv.GetPotentialInvalidValues("Value", "", typeof(Error), typeof(Warning)).Should().Have.Count.EqualTo(2);
     cv.GetPotentialInvalidValues("Value", "123", typeof(Error)).Should().Be.Empty();
     cv.GetPotentialInvalidValues("Value", "", typeof(Error)).Should().Have.Count.EqualTo(1);
 }