public void ShouldReturnFalseForEmptyObject() { object testValue = new object(); Validator zipCodeValidator = new ZipCodeValidator(testValue); Assert.IsFalse(zipCodeValidator.Validate()); }
public void ShouldReturnFalseForValueType() { decimal testValue = 30816; Validator zipCodeValidator = new ZipCodeValidator(testValue); Assert.IsFalse(zipCodeValidator.Validate()); }
public void validate_invalid_zipcode_datarow(string zipcodeString) { bool result = ZipCodeValidator.Validate(zipcodeString, out string formattedZipCode); Assert.IsFalse(result); }
public void Create(Address address) { if (ZipCodeValidator.NotValid(address.Zip.ToString())) { throw new FieldValidationException("Zip", Resource.InvalidZip); } _addressRepository.Add(address); }
public void validate_valid_zipcode_datarow(string zipcodeString) { bool result = ZipCodeValidator.Validate(zipcodeString, out string formattedZipCode); Assert.IsTrue(result); Assert.AreEqual(formattedZipCode.Length, 6); }
private static void ValidateZipCode(string zipCode) { var validator = new ZipCodeValidator(); var result = validator.Validate(zipCode); if (!result.IsValid) { throw new IdentityDomainException(nameof(zipCode)); } }
public void ShouldReturnFalseForIncorrectPolishZipCode() { string[] testValues = new string[] { "30816", "308-16" }; foreach (string item in testValues) { Validator zipCodeValidator = new ZipCodeValidator(item); Assert.IsFalse(zipCodeValidator.Validate()); } }
public void ShouldReturnTrueForCorrectPolishZipCode() { string[] testValues = new string[] { "30-816", "75-123", "23-315" }; foreach (string item in testValues) { Validator zipCodeValidator = new ZipCodeValidator(item); Assert.IsTrue(zipCodeValidator.Validate()); } }
public void validate_valid_zipcode() { //string zipcodeText = "Nånting dumt här..."; string zipcodeText = "780 68"; //string zipcodeText = "784 32"; bool result = ZipCodeValidator.Validate(zipcodeText, out string formattedZipCode); Assert.IsTrue(result); }
public string ValidationMsg() { // If we have no text to validate... if (String.IsNullOrEmpty(_attachedTextControl.Text.Trim())) { if (_required) { return("Please enter a value into " + _nomenclature); } return(String.Empty); } // If we got here then there is text to validate if (_attachedTextControl.Text == _originalText) { // Assume the original text is in the proper validation style if (_validationStyle == ValidationStyle.NoOriginalValue) { return("Please enter a different value into " + _nomenclature); } return(String.Empty); } // Okay, we have something to validate and its not the original value... string returnMsg = String.Empty; TextValidator validator; string errSuffix = " into " + _nomenclature; switch (_validationStyle) { case ValidationStyle.NoValidation: returnMsg = String.Empty; break; case ValidationStyle.DateAny: validator = new DateValidator(DateStyle.DontCare); returnMsg = validator.Validate(_attachedTextControl.Text); if (returnMsg.Length > 0) { returnMsg = returnMsg + errSuffix; } break; case ValidationStyle.DateFuture: validator = new DateValidator(DateStyle.Future); returnMsg = validator.Validate(_attachedTextControl.Text); if (returnMsg.Length > 0) { returnMsg = returnMsg + errSuffix; } break; case ValidationStyle.DatePast: validator = new DateValidator(DateStyle.Past); returnMsg = validator.Validate(_attachedTextControl.Text); if (returnMsg.Length > 0) { returnMsg = returnMsg + errSuffix; } break; case ValidationStyle.DigitsOnly: validator = new DigitsValidator(DigitStyle.DigitsOnly); returnMsg = validator.Validate(_attachedTextControl.Text); if (returnMsg.Length > 0) { returnMsg = returnMsg + errSuffix; } break; case ValidationStyle.DigitsNotZero: validator = new DigitsValidator(DigitStyle.DigitsNotZero); returnMsg = validator.Validate(_attachedTextControl.Text); if (returnMsg.Length > 0) { returnMsg = returnMsg + errSuffix; } break; case ValidationStyle.Money: validator = new DigitsValidator(DigitStyle.Money); returnMsg = validator.Validate(_attachedTextControl.Text); if (returnMsg.Length > 0) { returnMsg = returnMsg + errSuffix; } break; case ValidationStyle.MoneyNotZero: validator = new DigitsValidator(DigitStyle.MoneyNotZero); returnMsg = validator.Validate(_attachedTextControl.Text); if (returnMsg.Length > 0) { returnMsg = returnMsg + errSuffix; } break; case ValidationStyle.Percentage: validator = new DigitsValidator(DigitStyle.Percentage); returnMsg = validator.Validate(_attachedTextControl.Text); if (returnMsg.Length > 0) { returnMsg = returnMsg + errSuffix; } break; case ValidationStyle.PercentageNotZero: validator = new DigitsValidator(DigitStyle.PercentageNotZero); returnMsg = validator.Validate(_attachedTextControl.Text); if (returnMsg.Length > 0) { returnMsg = returnMsg + errSuffix; } break; case ValidationStyle.PhoneNumber: validator = new PhoneNumberValidator(); returnMsg = validator.Validate(_attachedTextControl.Text); if (returnMsg.Length > 0) { returnMsg = returnMsg + errSuffix; } break; case ValidationStyle.EmailAddr: validator = new PureTextValidator(PureTextStyle.EmailAddress); returnMsg = validator.Validate(_attachedTextControl.Text); if (returnMsg.Length > 0) { returnMsg = returnMsg + errSuffix; } break; case ValidationStyle.StateAbbreviation: validator = new PureTextValidator(PureTextStyle.StateAbbreviation); returnMsg = validator.Validate(_attachedTextControl.Text); if (returnMsg.Length > 0) { returnMsg = returnMsg + errSuffix; } break; case ValidationStyle.NoWhiteSpace: validator = new PureTextValidator(PureTextStyle.NoWhiteSpace); returnMsg = validator.Validate(_attachedTextControl.Text); if (returnMsg.Length > 0) { returnMsg = returnMsg + errSuffix; } break; case ValidationStyle.NoPunctuation: validator = new PureTextValidator(PureTextStyle.NoPunctuation); returnMsg = validator.Validate(_attachedTextControl.Text); if (returnMsg.Length > 0) { returnMsg = returnMsg + errSuffix; } break; case ValidationStyle.NoWhiteSpaceAndNoPunct: validator = new PureTextValidator(PureTextStyle.NoWhiteSpaceAndNoPunct); returnMsg = validator.Validate(_attachedTextControl.Text); if (returnMsg.Length > 0) { returnMsg = returnMsg + errSuffix; } break; case ValidationStyle.SSN: validator = new SSNValidator(); returnMsg = validator.Validate(_attachedTextControl.Text); if (returnMsg.Length > 0) { returnMsg = returnMsg + errSuffix; } break; case ValidationStyle.Time: validator = new TimeValidator(); returnMsg = validator.Validate(_attachedTextControl.Text); if (returnMsg.Length > 0) { returnMsg = returnMsg + errSuffix; } break; case ValidationStyle.ZipPlus4: validator = new ZipCodeValidator(); returnMsg = validator.Validate(_attachedTextControl.Text); if (returnMsg.Length > 0) { returnMsg = returnMsg + errSuffix; } break; } return(returnMsg); }