Exemplo n.º 1
0
        public void When_value_is_Default_for_type_validator_should_fail_int()
        {
            var validator = new NotEmptyValidator(default(int));
            var result = validator.Validate(new PropertyValidatorContext(null, new object(), x => 0));
            result.IsValid().ShouldBeFalse();

            var result1 = validator.Validate(new PropertyValidatorContext(null, new object(), x => 1));
            result1.IsValid().ShouldBeTrue();
        }
Exemplo n.º 2
0
 public void When_value_is_Default_for_type_validator_should_fail_datetime()
 {
     var defaultValue = default(DateTime);
     var validator = new NotEmptyValidator(defaultValue);
     var result = validator.Validate(new PropertyValidatorContext(null, new object(), x => defaultValue));
     result.IsValid().ShouldBeFalse();
 }
        public void Uses_custom_resouces()
        {
            ValidatorOptions.ResourceProviderType = typeof(MyResources);

            var validator = new NotEmptyValidator(null);
            var result = validator.Validate(new PropertyValidatorContext("name", null, x => null));
            result.Single().ErrorMessage.ShouldEqual("foo");

            ValidatorOptions.ResourceProviderType = null;
        }
        public void Correctly_assigns_default_localized_error_message()
        {
            var originalCulture = Thread.CurrentThread.CurrentUICulture;
            try {
                var validator = new NotEmptyValidator(null);

                foreach (var culture in new[] {"en", "de", "fr"}) {
                    Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);
                    var message = Messages.ResourceManager.GetString("notempty_error");
                    var errorMessage = new MessageFormatter().AppendPropertyName("name").BuildMessage(message);
                    Debug.WriteLine(errorMessage);
                    var result = validator.Validate(new PropertyValidatorContext("name", null, x => null));
                    result.Single().ErrorMessage.ShouldEqual(errorMessage);
                }
            }
            finally {
                // Always reset the culture.
                Thread.CurrentThread.CurrentUICulture = originalCulture;
            }
        }
Exemplo n.º 5
0
 public void When_value_is_null_validator_should_fail()
 {
     var validator = new NotEmptyValidator(default(string));
     var result = validator.Validate(new PropertyValidatorContext(null, new object(), x => null));
     result.IsValid().ShouldBeFalse();
 }
Exemplo n.º 6
0
 public void When_validation_fails_error_should_be_set()
 {
     var validator = new NotEmptyValidator(default(string));
     var result = validator.Validate(new PropertyValidatorContext("name", null, x => null));
     result.Single().ErrorMessage.ShouldEqual("'name' should not be empty.");
 }
Exemplo n.º 7
0
 public void When_there_is_a_value_then_the_validator_should_pass()
 {
     var validator = new NotEmptyValidator(default(string));
     var result = validator.Validate(new PropertyValidatorContext(null, new object(), x => "Farf"));
     result.IsValid().ShouldBeTrue();
 }