public void ReturnUserObject_when_usercredentials_are_valid() { string username = "******"; string password = "******"; UserDataObject userobject = new UserDataObject { Id = 1, FirstName = "firstname", LastName = "lastname", EncryptedPassword = IGenProtector.Encrypt(password), IsActive = true, IsAccountActivated = true }; var userDataMock = new Mock <IUserData>(); userDataMock.Setup(x => x.Get(username)).Returns(userobject); IUserForgotPassword userForgotPassword = Mock.Of <IUserForgotPassword>(); ILoginProcess loginProcess = new LoginProcess(userDataMock.Object, userForgotPassword); UserDataObject result = loginProcess.Authenticate(username, password); Assert.AreEqual(userobject.Id, result.Id); Assert.AreEqual(userobject.FirstName, result.FirstName); Assert.AreEqual(userobject.LastName, result.LastName); }
public void ValidatePasswordProtector() { string password = "******"; string encryptedpassword = IGenProtector.Encrypt(password); string decryptedPassword = IGenProtector.Decrypt(encryptedpassword); Assert.AreEqual(password, decryptedPassword); }
private void SendActivationEmail(UserDataObject user) { string encryptedEmail = IGenProtector.Encrypt(user.Email); string url = string.Format("{0}Activate?code={1}", BaseUrl, HttpUtility.UrlEncode(encryptedEmail)); MailSettings settings = GetEmailSettings(); ProcessFactory.GetNotificationProcess(settings, UserId).ActivateAccount(url, user); }
public void ResetPassword_should_call_forgotpassworddata_method_when_token_password_are_valid() { string token = "1234567890"; string password = "******"; string repassword = "******"; ForgotPasswordTokenObject tokenObject = new ForgotPasswordTokenObject { Token = token, ExpiryDateTime = DateTime.UtcNow.AddDays(2) }; var userDataMock = new Mock <IUserData>(); var userForgotPasswordMock = new Mock <IUserForgotPassword>(); userForgotPasswordMock.Setup(x => x.Get(token)).Returns(tokenObject); IForgotPasswordProcess forgotPassword = new ForgotPasswordProcess(userDataMock.Object, userForgotPasswordMock.Object); forgotPassword.ResetPassword(token, password, repassword); userForgotPasswordMock.Verify(x => x.ResetPassword(token, IGenProtector.Encrypt(password))); }
public void Authenticate_throws_AccountNotActivatedException_when_account_is_not_activated() { string username = "******"; string password = "******"; UserDataObject userobject = new UserDataObject { Id = 1, FirstName = "firstname", LastName = "lastname", EncryptedPassword = IGenProtector.Encrypt(password), IsActive = true, IsAccountActivated = false }; var userDataMock = new Mock <IUserData>(); userDataMock.Setup(x => x.Get(username)).Returns(userobject); IUserForgotPassword userForgotPassword = Mock.Of <IUserForgotPassword>(); ILoginProcess loginProcess = new LoginProcess(userDataMock.Object, userForgotPassword); UserDataObject result = loginProcess.Authenticate(username, password); }
public void ThrowInvalidCredentialException_when_password_is_incorrect() { string username = "******"; string password = "******"; UserDataObject userobject = new UserDataObject { Id = 1, FirstName = "firstname", LastName = "lastname", EncryptedPassword = IGenProtector.Encrypt("somepassword"), IsActive = false, IsAccountActivated = true }; var userDataMock = new Mock <IUserData>(); userDataMock.Setup(x => x.Get(username)).Returns(userobject); IUserForgotPassword userForgotPassword = Mock.Of <IUserForgotPassword>(); ILoginProcess loginProcess = new LoginProcess(userDataMock.Object, userForgotPassword); loginProcess.Authenticate(username, password); }