public void IsValid_Returns_validCode_when_Required_fields_are_Empty() { var mockobject = new Mock <IUserData>(); mockobject.Setup(x => x.GetEmailAddress(string.Empty)).Returns(string.Empty); RegistrationValidator validator = new RegistrationValidator(mockobject.Object); validator.IsValid(new UserDataObject()); // Firstname is required Assert.IsTrue(validator.ErrorCodes.Contains(ErrorCodes.Registration.ERROR_FIRSTNAME_REQUIRED)); // Lastname is required Assert.IsTrue(validator.ErrorCodes.Contains(ErrorCodes.Registration.ERROR_LASTNAME_REQUIRED)); // Password is required Assert.IsTrue(validator.ErrorCodes.Contains(ErrorCodes.Password.ERROR_PASSWORD_REQUIRED)); // Retype password is required Assert.IsTrue(validator.ErrorCodes.Contains(ErrorCodes.Password.ERROR_REPASSWORD_REQUIRED)); // Email address is required Assert.IsTrue(validator.ErrorCodes.Contains(ErrorCodes.Registration.ERROR_EMAIL_REQUIRED)); // Company is required Assert.IsTrue(validator.ErrorCodes.Contains(ErrorCodes.Registration.ERROR_COMPANY_REQUIRED)); // Phone is required Assert.IsTrue(validator.ErrorCodes.Contains(ErrorCodes.Registration.ERROR_PHONE_REQUIRED)); }
public int Register(UserDataObject user) { RegistrationValidator validator = new RegistrationValidator(userData); if (!validator.IsValid(user)) { throw new RegistrationException(validator.ErrorCodes); } user.EncryptedPassword = IGenProtector.Encrypt(user.Password); return(userData.Add(user)); }
public void IsValid_should_not_return_any_phone_errorcodes_when_phonenumber_isvalid(string phone) { var mockobject = new Mock <IUserData>(); mockobject.Setup(x => x.GetEmailAddress(string.Empty)).Returns(string.Empty); RegistrationValidator validator = new RegistrationValidator(mockobject.Object); validator.IsValid(new UserDataObject { Phone = phone }); Assert.IsFalse(validator.ErrorCodes.Contains(ErrorCodes.Registration.ERROR_PHONE_INVALID)); }
public void IsValid_should_return_invalid_email_errorcode_when_invalid_email_ispassed(string email) { var mockobject = new Mock <IUserData>(); mockobject.Setup(x => x.GetEmailAddress(string.Empty)).Returns(string.Empty); RegistrationValidator validator = new RegistrationValidator(mockobject.Object); validator.IsValid(new UserDataObject { Email = email }); Assert.IsTrue(validator.ErrorCodes.Contains(ErrorCodes.Registration.ERROR_EMAIL_INVALID)); }
public void Isvalid_should_return_password_donotmatch_errorcode_when_passwords_are_different(string password, string repassword) { var mockobject = new Mock <IUserData>(); mockobject.Setup(x => x.GetEmailAddress(string.Empty)).Returns(string.Empty); RegistrationValidator validator = new RegistrationValidator(mockobject.Object); validator.IsValid(new UserDataObject { Password = password, RePassword = repassword }); Assert.IsTrue(validator.ErrorCodes.Contains(ErrorCodes.Password.ERROR_PASSWORD_DO_NOT_MATCH)); }
public void IsValid_should_return_password_invalid_errorcode_when_password_isabove_10_characters() { var mockobject = new Mock <IUserData>(); mockobject.Setup(x => x.GetEmailAddress(string.Empty)).Returns(string.Empty); RegistrationValidator validator = new RegistrationValidator(mockobject.Object); validator.IsValid(new UserDataObject { Password = "******", RePassword = "******" }); Assert.IsTrue(validator.ErrorCodes.Contains(ErrorCodes.Password.ERROR_PASSWORD_STRENGTH)); }
public void IsValid_should_return_email_registered_errorcode_when_registered_email_ispassed() { string email = "*****@*****.**"; var mockobject = new Mock <IUserData>(); mockobject.Setup(x => x.GetEmailAddress(email)).Returns(email); RegistrationValidator validator = new RegistrationValidator(mockobject.Object); validator.IsValid(new UserDataObject { Email = email }); Assert.IsTrue(validator.ErrorCodes.Contains(ErrorCodes.Registration.ERROR_EMAIL_IS_REGISTERED)); }
public void IsValid_should_not_return_any_password_errorcode_when_password_isvalid() { var mockobject = new Mock <IUserData>(); mockobject.Setup(x => x.GetEmailAddress(string.Empty)).Returns(string.Empty); RegistrationValidator validator = new RegistrationValidator(mockobject.Object); validator.IsValid(new UserDataObject { Password = "******", RePassword = "******" }); Assert.IsFalse(validator.ErrorCodes.Contains(ErrorCodes.Password.ERROR_PASSWORD_STRENGTH)); Assert.IsFalse(validator.ErrorCodes.Contains(ErrorCodes.Password.ERROR_PASSWORD_DO_NOT_MATCH)); Assert.IsFalse(validator.ErrorCodes.Contains(ErrorCodes.Password.ERROR_PASSWORD_REQUIRED)); Assert.IsFalse(validator.ErrorCodes.Contains(ErrorCodes.Password.ERROR_REPASSWORD_REQUIRED)); }
public void IsValid_should_return_true_when_user_information_isvalid() { UserDataObject user = new UserDataObject { FirstName = "Jeethendra", LastName = "dv", Password = "******", RePassword = "******", Company = "IMS Group", Phone = "02041170361", Email = "*****@*****.**" }; var mockobject = new Mock <IUserData>(); mockobject.Setup(x => x.GetEmailAddress(user.Email)).Returns(string.Empty); RegistrationValidator validator = new RegistrationValidator(mockobject.Object); Assert.IsTrue(validator.IsValid(user)); Assert.AreEqual(0, validator.ErrorCodes.Count); }