Ejemplo n.º 1
0
        public static void Validate_throws_for_invalid_values()
        {
            var attribute = new CreditCardAttribute();

            Assert.Throws<ValidationException>(() => attribute.Validate("0000000000000001", s_testValidationContext)); // Bad checksum
            Assert.Throws<ValidationException>(() => attribute.Validate(0, s_testValidationContext)); // Non-string
            Assert.Throws<ValidationException>(() => attribute.Validate("000%000000000001", s_testValidationContext)); // Non-digit
        }
        public static void Validate_throws_for_invalid_values()
        {
            var attribute = new CreditCardAttribute();

            Assert.Throws <ValidationException>(() => attribute.Validate("0000000000000001", s_testValidationContext)); // Bad checksum
            Assert.Throws <ValidationException>(() => attribute.Validate(0, s_testValidationContext));                  // Non-string
            Assert.Throws <ValidationException>(() => attribute.Validate("000%000000000001", s_testValidationContext)); // Non-digit
        }
        public static void Validate_successful_for_valid_values()
        {
            var attribute = new CreditCardAttribute();

            AssertEx.DoesNotThrow(() => attribute.Validate(null, s_testValidationContext));                  // Null is valid
            AssertEx.DoesNotThrow(() => attribute.Validate("0000000000000000", s_testValidationContext));    // Simplest valid value
            AssertEx.DoesNotThrow(() => attribute.Validate("1234567890123452", s_testValidationContext));    // Good checksum
            AssertEx.DoesNotThrow(() => attribute.Validate("1234-5678-9012-3452", s_testValidationContext)); // Good checksum, with dashes
            AssertEx.DoesNotThrow(() => attribute.Validate("1234 5678 9012 3452", s_testValidationContext)); // Good checksum, with spaces
        }
Ejemplo n.º 4
0
        public static void Validate_successful_for_valid_values()
        {
            var attribute = new CreditCardAttribute();

            AssertEx.DoesNotThrow(() => attribute.Validate(null, s_testValidationContext)); // Null is valid
            AssertEx.DoesNotThrow(() => attribute.Validate("0000000000000000", s_testValidationContext)); // Simplest valid value
            AssertEx.DoesNotThrow(() => attribute.Validate("1234567890123452", s_testValidationContext)); // Good checksum
            AssertEx.DoesNotThrow(() => attribute.Validate("1234-5678-9012-3452", s_testValidationContext)); // Good checksum, with dashes
            AssertEx.DoesNotThrow(() => attribute.Validate("1234 5678 9012 3452", s_testValidationContext)); // Good checksum, with spaces
        }
        public static void Validate_throws_InvalidOperationException_if_ErrorMessage_is_null()
        {
            var attribute = new CreditCardAttribute();

            attribute.ErrorMessage = null; // note: this overrides the default value
            Assert.Throws <InvalidOperationException>(() => attribute.Validate("0000000000000001", s_testValidationContext));
        }
Ejemplo n.º 6
0
 public static void Validate_throws_InvalidOperationException_if_ErrorMessage_and_ErrorMessageResourceName_are_set()
 {
     var attribute = new CreditCardAttribute();
     attribute.ErrorMessage = "SomeErrorMessage";
     attribute.ErrorMessageResourceName = "SomeErrorMessageResourceName";
     Assert.Throws<InvalidOperationException>(() => attribute.Validate("0000000000000001", s_testValidationContext));
 }
Ejemplo n.º 7
0
 public static void Validate_throws_InvalidOperationException_if_ErrorMessageResourceType_set_but_ErrorMessageResourceName_not_set()
 {
     var attribute = new CreditCardAttribute();
     attribute.ErrorMessageResourceName = null;
     attribute.ErrorMessageResourceType = typeof(ErrorMessageResources);
     Assert.Throws<InvalidOperationException>(() => attribute.Validate("0000000000000001", s_testValidationContext));
 }
        public static void Validate_throws_InvalidOperationException_if_ErrorMessage_and_ErrorMessageResourceName_are_set()
        {
            var attribute = new CreditCardAttribute();

            attribute.ErrorMessage             = "SomeErrorMessage";
            attribute.ErrorMessageResourceName = "SomeErrorMessageResourceName";
            Assert.Throws <InvalidOperationException>(() => attribute.Validate("0000000000000001", s_testValidationContext));
        }
        public static void Validate_throws_InvalidOperationException_if_ErrorMessageResourceType_set_but_ErrorMessageResourceName_not_set()
        {
            var attribute = new CreditCardAttribute();

            attribute.ErrorMessageResourceName = null;
            attribute.ErrorMessageResourceType = typeof(ErrorMessageResources);
            Assert.Throws <InvalidOperationException>(() => attribute.Validate("0000000000000001", s_testValidationContext));
        }
Ejemplo n.º 10
0
        public static void Validate_ErrorMessageResourceNameNotSet_ErrorMessageResourceTypeSet_ThrowsInvalidOperationException()
        {
            var attribute = new CreditCardAttribute()
            {
                ErrorMessageResourceName = null, ErrorMessageResourceType = typeof(ErrorMessageResources)
            };

            Assert.Throws <InvalidOperationException>(() => attribute.Validate("0000000000000001", s_testValidationContext));
        }
Ejemplo n.º 11
0
        public static void Validate_ErrorMessageNotSet_ThrowsInvalidOperationException()
        {
            var attribute = new CreditCardAttribute()
            {
                ErrorMessage = null
            };

            Assert.Throws <InvalidOperationException>(() => attribute.Validate("0000000000000001", s_testValidationContext));
        }
Ejemplo n.º 12
0
        public static void Validate_ErrorMessageSet_ErrorMessageResourceNameSet_ThrowsInvalidOperationException()
        {
            var attribute = new CreditCardAttribute()
            {
                ErrorMessage = "Some", ErrorMessageResourceName = "Some"
            };

            Assert.Throws <InvalidOperationException>(() => attribute.Validate("0000000000000001", s_testValidationContext));
        }
 public static void Validate_ValidValue_DoesNotThrow(string value)
 {
     var attribute = new CreditCardAttribute();
     attribute.Validate(value, s_testValidationContext);
 }
Ejemplo n.º 14
0
        public static void Validate_ValidValue_DoesNotThrow(string value)
        {
            var attribute = new CreditCardAttribute();

            attribute.Validate(value, s_testValidationContext);
        }
Ejemplo n.º 15
0
        public static void Validate_InvalidValue_ThrowsValidationException(object value)
        {
            var attribute = new CreditCardAttribute();

            Assert.Throws <ValidationException>(() => attribute.Validate(value, s_testValidationContext));
        }
 public static void Validate_ErrorMessageNotSet_ThrowsInvalidOperationException()
 {
     var attribute = new CreditCardAttribute() { ErrorMessage = null };
     Assert.Throws<InvalidOperationException>(() => attribute.Validate("0000000000000001", s_testValidationContext));
 }
 public static void Validate_ErrorMessageSet_ErrorMessageResourceNameSet_ThrowsInvalidOperationException()
 {
     var attribute = new CreditCardAttribute() { ErrorMessage = "Some", ErrorMessageResourceName = "Some" };
     Assert.Throws<InvalidOperationException>(() => attribute.Validate("0000000000000001", s_testValidationContext));
 }
Ejemplo n.º 18
0
 public static void Validate_throws_InvalidOperationException_if_ErrorMessage_is_null()
 {
     var attribute = new CreditCardAttribute();
     attribute.ErrorMessage = null; // note: this overrides the default value
     Assert.Throws<InvalidOperationException>(() => attribute.Validate("0000000000000001", s_testValidationContext));
 }
 public static void Validate_ErrorMessageResourceNameNotSet_ErrorMessageResourceTypeSet_ThrowsInvalidOperationException()
 {
     var attribute = new CreditCardAttribute() { ErrorMessageResourceName = null, ErrorMessageResourceType = typeof(ErrorMessageResources) };
     Assert.Throws<InvalidOperationException>(() => attribute.Validate("0000000000000001", s_testValidationContext));
 }
 public static void Validate_InvalidValue_ThrowsValidationException(object value)
 {
     var attribute = new CreditCardAttribute();
     Assert.Throws<ValidationException>(() => attribute.Validate(value, s_testValidationContext));
 }