Example #1
0
 public static void Validate_throws_for_invalid_phone_numbers()
 {
     var attribute = new PhoneAttribute();
     Assert.Throws<ValidationException>(() => attribute.Validate(new object(), s_testValidationContext));
     Assert.Throws<ValidationException>(() => attribute.Validate(string.Empty, s_testValidationContext));
     Assert.Throws<ValidationException>(() => attribute.Validate("abcdefghij", s_testValidationContext));
     Assert.Throws<ValidationException>(() => attribute.Validate("425+555+1212", s_testValidationContext));
     Assert.Throws<ValidationException>(() => attribute.Validate("425-555-1212 ext 123 ext 456", s_testValidationContext));
 }
Example #2
0
        public static void Validate_throws_for_invalid_phone_numbers()
        {
            var attribute = new PhoneAttribute();

            Assert.Throws <ValidationException>(() => attribute.Validate(new object(), s_testValidationContext));
            Assert.Throws <ValidationException>(() => attribute.Validate(string.Empty, s_testValidationContext));
            Assert.Throws <ValidationException>(() => attribute.Validate("abcdefghij", s_testValidationContext));
            Assert.Throws <ValidationException>(() => attribute.Validate("425+555+1212", s_testValidationContext));
            Assert.Throws <ValidationException>(() => attribute.Validate("425-555-1212 ext 123 ext 456", s_testValidationContext));
        }
Example #3
0
 public static void Validate_successful_for_valid_phone_numbers()
 {
     var attribute = new PhoneAttribute();
     AssertEx.DoesNotThrow(() => attribute.Validate("425-555-1212", s_testValidationContext));
     AssertEx.DoesNotThrow(() => attribute.Validate("+1 425-555-1212", s_testValidationContext));
     AssertEx.DoesNotThrow(() => attribute.Validate("(425)555-1212", s_testValidationContext));
     AssertEx.DoesNotThrow(() => attribute.Validate("(425) 555-1212", s_testValidationContext));
     AssertEx.DoesNotThrow(() => attribute.Validate("+44 (3456)987654", s_testValidationContext));
     AssertEx.DoesNotThrow(() => attribute.Validate("+777.456.789.123", s_testValidationContext));
     AssertEx.DoesNotThrow(() => attribute.Validate("425-555-1212 x123", s_testValidationContext));
     AssertEx.DoesNotThrow(() => attribute.Validate("425-555-1212 x 123", s_testValidationContext));
     AssertEx.DoesNotThrow(() => attribute.Validate("425-555-1212 ext123", s_testValidationContext));
     AssertEx.DoesNotThrow(() => attribute.Validate("425-555-1212 ext 123", s_testValidationContext));
 }
Example #4
0
        public static void Validate_successful_for_valid_phone_numbers()
        {
            var attribute = new PhoneAttribute();

            AssertEx.DoesNotThrow(() => attribute.Validate("425-555-1212", s_testValidationContext));
            AssertEx.DoesNotThrow(() => attribute.Validate("+1 425-555-1212", s_testValidationContext));
            AssertEx.DoesNotThrow(() => attribute.Validate("(425)555-1212", s_testValidationContext));
            AssertEx.DoesNotThrow(() => attribute.Validate("(425) 555-1212", s_testValidationContext));
            AssertEx.DoesNotThrow(() => attribute.Validate("+44 (3456)987654", s_testValidationContext));
            AssertEx.DoesNotThrow(() => attribute.Validate("+777.456.789.123", s_testValidationContext));
            AssertEx.DoesNotThrow(() => attribute.Validate("425-555-1212 x123", s_testValidationContext));
            AssertEx.DoesNotThrow(() => attribute.Validate("425-555-1212 x 123", s_testValidationContext));
            AssertEx.DoesNotThrow(() => attribute.Validate("425-555-1212 ext123", s_testValidationContext));
            AssertEx.DoesNotThrow(() => attribute.Validate("425-555-1212 ext 123", s_testValidationContext));
        }
Example #5
0
        public static void Validate_throws_InvalidOperationException_if_ErrorMessage_is_null()
        {
            var attribute = new PhoneAttribute();

            attribute.ErrorMessage = null; // note: this overrides the default value
            Assert.Throws <InvalidOperationException>(() => attribute.Validate("abcdefghij", s_testValidationContext));
        }
Example #6
0
 public static void Validate_throws_InvalidOperationException_if_ErrorMessageResourceName_set_but_ErrorMessageResourceType_not_set()
 {
     var attribute = new PhoneAttribute();
     attribute.ErrorMessageResourceName = "SomeErrorMessageResourceName";
     attribute.ErrorMessageResourceType = null;
     Assert.Throws<InvalidOperationException>(() => attribute.Validate("abcdefghij", s_testValidationContext));
 }
Example #7
0
        public static void Validate_throws_InvalidOperationException_if_ErrorMessageResourceType_set_but_ErrorMessageResourceName_not_set()
        {
            var attribute = new PhoneAttribute();

            attribute.ErrorMessageResourceName = null;
            attribute.ErrorMessageResourceType = typeof(ErrorMessageResources);
            Assert.Throws <InvalidOperationException>(() => attribute.Validate("abcdefghij", s_testValidationContext));
        }
Example #8
0
        public static void Validate_throws_InvalidOperationException_if_ErrorMessage_and_ErrorMessageResourceName_are_set()
        {
            var attribute = new PhoneAttribute();

            attribute.ErrorMessage             = "SomeErrorMessage";
            attribute.ErrorMessageResourceName = "SomeErrorMessageResourceName";
            Assert.Throws <InvalidOperationException>(() => attribute.Validate("abcdefghij", s_testValidationContext));
        }
Example #9
0
        public static void Validate_successful_for_null_value()
        {
            var attribute = new PhoneAttribute();

            AssertEx.DoesNotThrow(() => attribute.Validate(null, s_testValidationContext)); // Null is valid
        }
Example #10
0
 public static void Validate_throws_InvalidOperationException_if_ErrorMessage_is_null()
 {
     var attribute = new PhoneAttribute();
     attribute.ErrorMessage = null; // note: this overrides the default value
     Assert.Throws<InvalidOperationException>(() => attribute.Validate("abcdefghij", s_testValidationContext));
 }
Example #11
0
 public static void Validate_successful_for_null_value()
 {
     var attribute = new PhoneAttribute();
     AssertEx.DoesNotThrow(() => attribute.Validate(null, s_testValidationContext)); // Null is valid
 }