Exemple #1
0
        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));
        }
Exemple #2
0
        public void TestGender_FemaleGenderCode()
        {
            var validator = new BiographicalTestClassValidator();
            var instance  = GetValidBiographical(() => true);
            var result    = validator.Validate(instance);

            Assert.IsTrue(result.IsValid);

            instance.Gender = Gender.SEVIS_FEMALE_GENDER_CODE_VALUE;
            result          = validator.Validate(instance);
            Assert.IsTrue(result.IsValid);
        }
Exemple #3
0
        public void TestEmailAddress_Null()
        {
            var validator = new BiographicalTestClassValidator();
            var instance  = GetValidBiographical(() => true);
            var result    = validator.Validate(instance);

            Assert.IsTrue(result.IsValid);

            instance.EmailAddress = null;
            result = validator.Validate(instance);
            Assert.IsTrue(result.IsValid);
            Assert.AreEqual(0, result.Errors.Count);
        }
Exemple #4
0
        public void TestFullName_ShouldRunFullNameValidator()
        {
            var validator = new BiographicalTestClassValidator();
            var instance  = GetValidBiographical(() => true);
            var result    = validator.Validate(instance);

            Assert.IsTrue(result.IsValid);

            instance.FullName = null;
            result            = validator.Validate(instance);
            Assert.IsFalse(result.IsValid);
            Assert.AreEqual(1, result.Errors.Count);
            Assert.AreEqual(BiographicalValidator <BiographicalTestClass> .FULL_NAME_NULL_ERROR_MESSAGE, result.Errors.First().ErrorMessage);
        }
Exemple #5
0
        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));
        }
Exemple #6
0
        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));
        }
Exemple #7
0
        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));
        }
Exemple #8
0
        public void TestBirthDate_IsNull()
        {
            var validator = new BiographicalTestClassValidator();
            var instance  = GetValidBiographical(() => true);
            var result    = validator.Validate(instance);

            Assert.IsTrue(result.IsValid);

            instance.BirthDate = null;
            result             = validator.Validate(instance);
            Assert.IsFalse(result.IsValid);
            Assert.AreEqual(1, result.Errors.Count);
            Assert.AreEqual(
                String.Format(BiographicalTestClassValidator.BIRTH_DATE_NULL_ERROR_MESSAGE, validator.GetPersonType(instance), validator.GetNameDelegate()(instance)),
                result.Errors.First().ErrorMessage);
            Assert.IsInstanceOfType(result.Errors.First().CustomState, typeof(BirthDateErrorPath));
        }
Exemple #9
0
        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));
        }
Exemple #10
0
        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));
        }
Exemple #11
0
        public void TestUSAddressShouldRunValidator()
        {
            var validator = new BiographicalTestClassValidator();
            var instance  = GetValidBiographical(() => true);
            var result    = validator.Validate(instance);

            Assert.IsTrue(result.IsValid);

            instance.USAddress = new AddressDTO
            {
                Street1    = "street 1",
                Division   = "FL",
                PostalCode = "12345",
                Country    = "hello world"
            };
            result = validator.Validate(instance);
            Assert.IsFalse(result.IsValid);
            Assert.AreEqual(1, result.Errors.Count);
            Assert.AreEqual(String.Format(AddressDTOValidator.COUNTRY_ERROR_MESSAGE, AddressDTOValidator.C_STREET_ADDRESS, LocationServiceAddressValidator.UNITED_STATES_COUNTRY_NAME), result.Errors.First().ErrorMessage);
        }
Exemple #12
0
        public void TestShouldValidate_ShouldNotValidate()
        {
            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);

            instance.ShouldValidateDelegate = () => false;

            result = validator.Validate(instance);
            Assert.IsTrue(result.IsValid);
        }