Esempio n. 1
0
        public void BirthdayTest()
        {
            IPerson person;
            IValidatorService validator = new ValidatorService();
            IValidationResult result = new ValidationResult();

            person = CreateTestPerson(result, validator, Data.ValidFName, Data.ValidLName, Data.ValidEmailId, Data.BirthdayToday);
            Assert.IsTrue(person.Birthday);

            person = CreateTestPerson(result, validator, Data.ValidFName, Data.ValidLName, Data.ValidEmailId, Data.BirthdayToday.AddDays(1));
            Assert.IsFalse(person.Birthday);

            person = CreateTestPerson(result, validator, Data.ValidFName, Data.ValidLName, Data.ValidEmailId, Data.BirthdayToday.AddMonths(-1));
            Assert.IsFalse(person.Birthday);

            try
            {
                person = CreateTestPerson(result, validator, Data.ValidFName, Data.ValidLName, Data.ValidEmailId);
                Assert.IsFalse(person.Birthday);
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.IsInstanceOfType(e, typeof(ArgumentNullException));
            }
        }
        public IValidationResult Validate(string firstName, string lastName, DateTime dateOfBirth)
        {
            {
                IValidationResult result = new ValidationResult();

                if (String.IsNullOrEmpty(firstName))
                    result.InvalidFields.Add(new ErrorMessage { FieldName = ErrorMessages.FirstName, Message = ErrorMessages.MissingFirstName });
                if (Regex.IsMatch(firstName, @"^[\p{L} \.\'\-]+$") == false)
                    result.InvalidFields.Add(new ErrorMessage { FieldName = ErrorMessages.FirstName, Message = ErrorMessages.InvalidFirstName });
                if (String.IsNullOrEmpty(lastName))
                    result.InvalidFields.Add(new ErrorMessage { FieldName = ErrorMessages.LastName, Message = ErrorMessages.MissingLastName });
                if (Regex.IsMatch(lastName, @"^[\p{L} \.\'\-]+$") == false)
                    result.InvalidFields.Add(new ErrorMessage { FieldName = ErrorMessages.LastName, Message = ErrorMessages.InvalidLastName });
                if (DateTime.Now - dateOfBirth < TimeSpan.Zero)
                    result.InvalidFields.Add(new ErrorMessage { FieldName = ErrorMessages.DOB, Message = ErrorMessages.FutureDOB });
                if (DateTime.Now - dateOfBirth > new TimeSpan(36500, 0, 0, 0))
                    result.InvalidFields.Add(new ErrorMessage { FieldName = ErrorMessages.DOB, Message = ErrorMessages.DOBtooMuchinPast });

                return result;
            }
        }
        public IValidationResult Validate(string firstName, string lastName, string emailId)
        {
            {
                IValidationResult result = new ValidationResult();

                if (String.IsNullOrEmpty(firstName))
                    result.InvalidFields.Add(new ErrorMessage { FieldName = ErrorMessages.FirstName, Message = ErrorMessages.MissingFirstName });
                if (Regex.IsMatch(firstName, @"^[\p{L} \.\'\-]+$") == false)
                    result.InvalidFields.Add(new ErrorMessage { FieldName = ErrorMessages.FirstName, Message = ErrorMessages.InvalidFirstName });
                if (String.IsNullOrEmpty(lastName))
                    result.InvalidFields.Add(new ErrorMessage { FieldName = ErrorMessages.LastName, Message = ErrorMessages.MissingLastName });
                if (Regex.IsMatch(lastName, @"^[\p{L} \.\'\-]+$") == false)
                    result.InvalidFields.Add(new ErrorMessage { FieldName = ErrorMessages.LastName, Message = ErrorMessages.InvalidLastName });
                if (String.IsNullOrEmpty(emailId))
                    result.InvalidFields.Add(new ErrorMessage { FieldName = ErrorMessages.EmailId, Message = ErrorMessages.MissingEmailId });
                if (Regex.IsMatch(emailId, @"\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}\b") == false)
                    result.InvalidFields.Add(new ErrorMessage { FieldName = ErrorMessages.EmailId, Message = ErrorMessages.InvalidEmailId });

                return result;
            }
        }
Esempio n. 4
0
        public void ZodiacSignTest()
        {
            for (int month = 1; month <= 12; month++)
            {
                IPerson person;
                IValidatorService validator = new ValidatorService();
                IValidationResult result = new ValidationResult();

                person = CreateTestPerson(result, validator, Data.ValidFName, Data.ValidLName, new DateTime(1991, month, 15));
                Assert.AreEqual(GetZodiacSign(new DateTime(1991, month, 15)), person.ZodiacSign);

                person = CreateTestPerson(result, validator, Data.ValidFName, Data.ValidLName, new DateTime(1991, month, 27));
                Assert.AreEqual(GetZodiacSign(new DateTime(1991, month, 27)), person.ZodiacSign);

            }
        }
Esempio n. 5
0
        public void ValidPersonTest()
        {
            IPerson person;
            IValidatorService validator = new ValidatorService();
            IValidationResult result = new ValidationResult();

            person = CreateTestPerson(result, validator, Data.ValidFName, Data.ValidLName, Data.ValidEmailId, Data.ValidDOB);

            person = CreateTestPerson(result, validator, Data.ValidFName, Data.ValidLName, Data.ValidEmailId);

            person = CreateTestPerson(result, validator, Data.ValidFName, Data.ValidLName, Data.ValidDOB);
        }
Esempio n. 6
0
        public void ScreenNameTest()
        {
            IPerson person;
            IValidatorService validator = new ValidatorService();
            IValidationResult result = new ValidationResult();

            person = CreateTestPerson(result, validator, Data.ValidFName, Data.ValidLName, Data.ValidEmailId);
            Assert.AreEqual(Data.ValidEmailId, person.ScreenName);

            person = CreateTestPerson(result, validator, Data.ValidFName, Data.ValidLName, Data.ValidDOB);

            StringBuilder screenName = new StringBuilder();
            screenName.Append(Data.ValidFName[0]);
            screenName.Append(Data.ValidLName.ToLowerInvariant());
            screenName.Append(Data.ValidDOB.Day.ToString());
            screenName.Append(Data.ValidDOB.Month.ToString());

            Assert.AreEqual(screenName.ToString(), person.ScreenName);
        }
Esempio n. 7
0
        public void PersonWithNullValuesTest()
        {
            IPerson person;
            IValidatorService validator = new ValidatorService();
            IValidationResult result = new ValidationResult();
            try
            {
                person = CreateTestPerson(result, validator, String.Empty, String.Empty, String.Empty);
                Assert.Fail();
            }
            catch (ValidationException e)
            {
                Assert.IsNotNull(e.Invalid.Find(invalid => invalid.FieldName.Equals(ErrorMessages.FirstName)));
                Assert.IsNotNull(e.Invalid.Find(invalid => invalid.Message.Equals(ErrorMessages.MissingFirstName)));
                Assert.IsNotNull(e.Invalid.Find(invalid => invalid.FieldName.Equals(ErrorMessages.LastName)));
                Assert.IsNotNull(e.Invalid.Find(invalid => invalid.Message.Equals(ErrorMessages.MissingLastName)));
                Assert.IsNotNull(e.Invalid.Find(invalid => invalid.FieldName.Equals(ErrorMessages.EmailId)));
                Assert.IsNotNull(e.Invalid.Find(invalid => invalid.Message.Equals(ErrorMessages.MissingEmailId)));
            }

            try
            {
                person = CreateTestPerson(result, validator, String.Empty, String.Empty, String.Empty, Data.TooOld);
                Assert.Fail();
            }
            catch (ValidationException e)
            {
                Assert.IsNotNull(e.Invalid.Find(invalid => invalid.FieldName.Equals(ErrorMessages.FirstName)));
                Assert.IsNotNull(e.Invalid.Find(invalid => invalid.Message.Equals(ErrorMessages.MissingFirstName)));
                Assert.IsNotNull(e.Invalid.Find(invalid => invalid.FieldName.Equals(ErrorMessages.LastName)));
                Assert.IsNotNull(e.Invalid.Find(invalid => invalid.Message.Equals(ErrorMessages.MissingLastName)));
                Assert.IsNotNull(e.Invalid.Find(invalid => invalid.FieldName.Equals(ErrorMessages.EmailId)));
                Assert.IsNotNull(e.Invalid.Find(invalid => invalid.Message.Equals(ErrorMessages.MissingEmailId)));
                Assert.IsNotNull(e.Invalid.Find(invalid => invalid.FieldName.Equals(ErrorMessages.DOB)));
                Assert.IsNotNull(e.Invalid.Find(invalid => invalid.Message.Equals(ErrorMessages.DOBtooMuchinPast)));
            }
            try
            {
                person = CreateTestPerson(result, validator, String.Empty, String.Empty, Data.FutureDOB);
                Assert.Fail();
            }
            catch (ValidationException e)
            {
                Assert.IsNotNull(e.Invalid.Find(invalid => invalid.FieldName.Equals(ErrorMessages.FirstName)));
                Assert.IsNotNull(e.Invalid.Find(invalid => invalid.Message.Equals(ErrorMessages.MissingFirstName)));
                Assert.IsNotNull(e.Invalid.Find(invalid => invalid.FieldName.Equals(ErrorMessages.LastName)));
                Assert.IsNotNull(e.Invalid.Find(invalid => invalid.Message.Equals(ErrorMessages.MissingLastName)));
                Assert.IsNotNull(e.Invalid.Find(invalid => invalid.FieldName.Equals(ErrorMessages.DOB)));
                Assert.IsNotNull(e.Invalid.Find(invalid => invalid.Message.Equals(ErrorMessages.FutureDOB)));
            }
        }
Esempio n. 8
0
 public void InvalidPersonTest()
 {
     IPerson person;
     IValidatorService validator = new ValidatorService();
     IValidationResult result = new ValidationResult();
     try
     {
         person = CreateTestPerson(result, validator, Data.InvalidFName, Data.InvalidLName, Data.TooOld);
         Assert.Fail();
     }
     catch (ValidationException e)
     {
         Assert.IsNotNull(e.Invalid.Find(invalid => invalid.FieldName.Equals(ErrorMessages.LastName)));
         Assert.IsNotNull(e.Invalid.Find(invalid => invalid.Message.Equals(ErrorMessages.InvalidLastName)));
         Assert.IsNotNull(e.Invalid.Find(invalid => invalid.FieldName.Equals(ErrorMessages.FirstName)));
         Assert.IsNotNull(e.Invalid.Find(invalid => invalid.Message.Equals(ErrorMessages.InvalidFirstName)));
         Assert.IsNotNull(e.Invalid.Find(invalid => invalid.FieldName.Equals(ErrorMessages.DOB)));
         Assert.IsNotNull(e.Invalid.Find(invalid => invalid.Message.Equals(ErrorMessages.DOBtooMuchinPast)));
     }
 }
Esempio n. 9
0
 public void ExceptionOnInvalidEmailTest()
 {
     IPerson person;
     IValidatorService validator = new ValidatorService();
     IValidationResult result = new ValidationResult();
     try
     {
         person = CreateTestPerson(result, validator, Data.ValidFName, Data.ValidLName, Data.InvalidEmailId, Data.ValidDOB);
         Assert.Fail();
     }
     catch (ValidationException e)
     {
         Assert.IsNotNull(e.Invalid.Find(invalid => invalid.FieldName.Equals(ErrorMessages.EmailId)));
         Assert.IsNotNull(e.Invalid.Find(invalid => invalid.Message.Equals(ErrorMessages.InvalidEmailId)));
     }
 }