public void TestPhoneNumber_HasCharacters() { var phonenumberUtil = PhoneNumberUtil.GetInstance(); var example = phonenumberUtil.GetExampleNumber(Data.PhoneNumber.US_PHONE_NUMBER_REGION_KEY); var formattedExample = phonenumberUtil.Format(example, PhoneNumberFormat.INTERNATIONAL); var validator = new BiographicalTestClassValidator(); var instance = GetValidBiographical(() => true); var result = validator.Validate(instance); Assert.IsTrue(result.IsValid); instance.PhoneNumber = "abc"; result = validator.Validate(instance); Assert.IsFalse(result.IsValid); Assert.AreEqual(1, result.Errors.Count); Assert.AreEqual( String.Format(BiographicalTestClassValidator.PHONE_NUMBER_ERROR_MESSAGE, Data.PhoneNumberType.Visiting.Value, instance.PhoneNumber, validator.GetPersonType(instance), validator.GetNameDelegate()(instance), formattedExample), result.Errors.First().ErrorMessage); Assert.IsInstanceOfType(result.Errors.First().CustomState, typeof(PhoneNumberErrorPath)); }
public void TestEmailAddress_ExceedsMaxLength() { var validator = new BiographicalTestClassValidator(); var instance = GetValidBiographical(() => true); var result = validator.Validate(instance); Assert.IsTrue(result.IsValid); instance.EmailAddress = "*****@*****.**" + new string('m', BiographicalValidator <BiographicalTestClass> .EMAIL_MAX_LENGTH); result = validator.Validate(instance); Assert.IsFalse(result.IsValid); Assert.AreEqual(1, result.Errors.Count); Assert.AreEqual( String.Format(BiographicalTestClassValidator.EMAIL_ERROR_MESSAGE, instance.EmailAddress, validator.GetPersonType(instance), validator.GetNameDelegate()(instance), BiographicalTestClassValidator.EMAIL_MAX_LENGTH), result.Errors.First().ErrorMessage); Assert.IsInstanceOfType(result.Errors.First().CustomState, typeof(EmailErrorPath)); }
public void TestCitizenshipCountry_ExceedsMaxLength() { var validator = new BiographicalTestClassValidator(); var instance = GetValidBiographical(() => true); var result = validator.Validate(instance); Assert.IsTrue(result.IsValid); instance.CitizenshipCountryCode = new String('c', BiographicalValidator <BiographicalTestClass> .COUNTRY_CODE_LENGTH + 1); result = validator.Validate(instance); Assert.IsFalse(result.IsValid); Assert.AreEqual(1, result.Errors.Count); Assert.AreEqual( String.Format(BiographicalTestClassValidator.CITIZENSHIP_COUNTRY_CODE_ERROR_MESSAGE, validator.GetPersonType(instance), validator.GetNameDelegate()(instance)), result.Errors.First().ErrorMessage); Assert.IsInstanceOfType(result.Errors.First().CustomState, typeof(CitizenshipErrorPath)); }
public void TestBirthCountryCode_EmptyString() { var validator = new BiographicalTestClassValidator(); var instance = GetValidBiographical(() => true); var result = validator.Validate(instance); Assert.IsTrue(result.IsValid); instance.BirthCountryCode = String.Empty; result = validator.Validate(instance); Assert.IsFalse(result.IsValid); Assert.AreEqual(1, result.Errors.Count); Assert.AreEqual( String.Format(BiographicalTestClassValidator.BIRTH_COUNTRY_CODE_ERROR_MESSAGE, validator.GetPersonType(instance), validator.GetNameDelegate()(instance)), result.Errors.First().ErrorMessage); Assert.IsInstanceOfType(result.Errors.First().CustomState, typeof(CountryOfBirthErrorPath)); }
public void TestBirthCity_ExceedsMaxLength() { var validator = new BiographicalTestClassValidator(); var instance = GetValidBiographical(() => true); var result = validator.Validate(instance); Assert.IsTrue(result.IsValid); instance.BirthCity = new String('c', BiographicalValidator <BiographicalTestClass> .CITY_MAX_LENGTH + 1); result = validator.Validate(instance); Assert.IsFalse(result.IsValid); Assert.AreEqual(1, result.Errors.Count); Assert.AreEqual( String.Format(BiographicalTestClassValidator.CITY_OF_BIRTH_REQUIRED_ERROR_MESSAGE, validator.GetPersonType(instance), validator.GetNameDelegate()(instance)), result.Errors.First().ErrorMessage); Assert.IsInstanceOfType(result.Errors.First().CustomState, typeof(CityOfBirthErrorPath)); }
public void TestGender_NotMaleOrFemaleGenderCode() { var validator = new BiographicalTestClassValidator(); var instance = GetValidBiographical(() => true); var result = validator.Validate(instance); Assert.IsTrue(result.IsValid); instance.Gender = "U"; result = validator.Validate(instance); Assert.IsFalse(result.IsValid); Assert.AreEqual(1, result.Errors.Count); Assert.AreEqual( String.Format(BiographicalTestClassValidator.GENDER_MUST_BE_A_VALUE_ERROR_MESSAGE, validator.GetPersonType(instance), validator.GetNameDelegate()(instance), Gender.SEVIS_MALE_GENDER_CODE_VALUE, Gender.SEVIS_FEMALE_GENDER_CODE_VALUE), result.Errors.First().ErrorMessage); Assert.IsInstanceOfType(result.Errors.First().CustomState, typeof(GenderErrorPath)); }
public void TestGender_IsNull() { var validator = new BiographicalTestClassValidator(); var instance = GetValidBiographical(() => true); var result = validator.Validate(instance); Assert.IsTrue(result.IsValid); instance.Gender = null; result = validator.Validate(instance); Assert.IsFalse(result.IsValid); Assert.AreEqual(1, result.Errors.Count); Assert.AreEqual( String.Format(BiographicalTestClassValidator.GENDER_REQUIRED_ERROR_MESSAGE, validator.GetPersonType(instance), validator.GetNameDelegate()(instance)), result.Errors.First().ErrorMessage); Assert.IsInstanceOfType(result.Errors.First().CustomState, typeof(GenderErrorPath)); }