public void EqualsCompareDifferentUsersTest() { UserProfile userA = new UserProfile(); userA.userId = 1; userA.loginName = loginName; userA.firstName = firstName; userA.lastName = lastName; userA.language = language; userA.country = country; userA.email = email; userA.enPassword = PasswordEncrypter.Crypt(clearPassword); UserProfile userB = new UserProfile(); userB.userId = 2; userB.loginName = loginName; userB.firstName = firstName; userB.lastName = lastName; userB.language = language; userB.country = country; userB.email = email; userB.enPassword = PasswordEncrypter.Crypt(clearPassword); Assert.IsFalse(userA.Equals(userB)); }
public void GetHashCodeTest() { UserProfile userA = new UserProfile(); userA.userId = 1; userA.loginName = loginName; userA.firstName = firstName; userA.lastName = lastName; userA.language = language; userA.country = country; userA.email = email; userA.enPassword = PasswordEncrypter.Crypt(clearPassword); UserProfile userB = new UserProfile(); userB.userId = 1; userB.loginName = loginName; userB.firstName = firstName; userB.lastName = lastName; userB.language = language; userB.country = country; userB.email = email; userB.enPassword = PasswordEncrypter.Crypt(clearPassword); Assert.AreEqual(userA.GetHashCode(), userB.GetHashCode()); }
public void ToStringTest() { UserProfile userA = new UserProfile(); userA.userId = 1; userA.loginName = loginName; userA.firstName = firstName; userA.lastName = lastName; userA.language = language; userA.country = country; userA.email = email; userA.enPassword = PasswordEncrypter.Crypt(clearPassword); String toStringOutput = userA.ToString(); Assert.IsNotNull(toStringOutput); Assert.IsTrue(toStringOutput.Contains(Convert.ToString(userA.userId))); Assert.IsTrue(toStringOutput.Contains(userA.loginName)); Assert.IsTrue(toStringOutput.Contains(userA.firstName)); Assert.IsTrue(toStringOutput.Contains(userA.lastName)); Assert.IsTrue(toStringOutput.Contains(userA.language)); Assert.IsTrue(toStringOutput.Contains(userA.country)); Assert.IsTrue(toStringOutput.Contains(userA.email)); Assert.IsTrue(toStringOutput.Contains(userA.enPassword)); }
/// <exception cref="DuplicateInstanceException"/> public long RegisterUser(string loginName, string clearPassword, UserProfileDetails userProfileDetails) { try { UserProfileDao.FindByLoginName(loginName); throw new DuplicateInstanceException(loginName, typeof(UserProfile).FullName); } catch (InstanceNotFoundException) { String encryptedPassword = PasswordEncrypter.Crypt(clearPassword); UserProfile userProfile = UserProfile.CreateUserProfile(0, loginName, encryptedPassword, userProfileDetails.FirstName, userProfileDetails.Lastname, userProfileDetails.Email, userProfileDetails.Language, userProfileDetails.Country); UserProfileDao.Create(userProfile); return(userProfile.usrId); } }
public void ChangePassword(long userId, string oldClearPassword, string newClearPassword) { UserProfile userProfile; try { userProfile = UserProfileDao.Find(userId); } catch (InstanceNotFoundException <UserProfile> ex) { throw new InstanceNotFoundException <UserProfileDetails>(ex.Properties); } String storedPassword = userProfile.password; if (!PasswordEncrypter.IsClearPasswordCorrect(oldClearPassword, storedPassword)) { throw new IncorrectPasswordException(userProfile.userLogin); } userProfile.password = PasswordEncrypter.Crypt(newClearPassword); try { UserProfileDao.Update(userProfile); } catch (InstanceNotFoundException <UserProfile> ex) { throw new InternalErrorException(ex); } }
public long RegisterUser(string loginName, string clearPassword, UserProfileDetails userProfileDetails) { try { UserProfileDao.FindByLoginName(loginName); throw new DuplicateInstanceException(loginName, typeof(UserProfile).FullName); } catch (InstanceNotFoundException) { String encryptedPassword = PasswordEncrypter.Crypt(clearPassword); UserProfile userProfile = new UserProfile(); userProfile.loginName = loginName; userProfile.enPassword = encryptedPassword; userProfile.firstName = userProfileDetails.FirstName; userProfile.lastName = userProfileDetails.Lastname; userProfile.email = userProfileDetails.Email; userProfile.language = userProfileDetails.Language; userProfile.country = userProfileDetails.Country; UserProfileDao.Create(userProfile); return(userProfile.usrId); } }
public void MyTestInitialize() { transaction = new TransactionScope(); userProfile = new UserProfile(); userProfile.loginName = userLoginName; userProfile.enPassword = PasswordEncrypter.Crypt(clearPassword); userProfile.firstName = firstName; userProfile.lastName = lastName; userProfile.email = email; userProfile.language = language; userProfile.country = country; userProfileDao.Create(userProfile); category = new Category(); category.name = categoryName; categoryDao.Create(category); myEvent = new Event(); myEvent.categoryId = categoryId; myEvent.name = name; myEvent.eventDate = date; myEvent.review = review; myEvent.Category = category; myEvent.Comments = new List <Comment>(); myEvent.Recommendations = new List <Recommendation>(); eventDao.Create(myEvent); userGroup = new UserGroup(); userGroup.name = groupName; userGroup.description = groupDescription; userGroup.UserProfiles = new List <UserProfile>(); userGroup.UserProfiles.Add(userProfile); userGroup.Recommendations = new List <Recommendation>(); userGroupDao.Create(userGroup); recommendation1 = new Recommendation(); recommendation1.reason = recom; recommendation1.Event = myEvent; recommendation1.UserProfile = userProfile; recommendation1.UserGroup = userGroup; recommendation1.created = DateTime.Now; recommendationDao.Create(recommendation1); recommendation2 = new Recommendation(); recommendation2.Event = myEvent; recommendation2.reason = recom; recommendation2.UserProfile = userProfile; recommendation2.UserGroup = userGroup; recommendation2.created = DateTime.Now; recommendationDao.Create(recommendation2); }
public void MyTestInitialize() { transaction = new TransactionScope(); userProfile = new UserProfile(); userProfile.loginName = userLoginName; userProfile.enPassword = PasswordEncrypter.Crypt(clearPassword); userProfile.firstName = firstName; userProfile.lastName = lastName; userProfile.email = email; userProfile.language = language; userProfile.country = country; userProfileDao.Create(userProfile); category = new Category(); category.name = categoryName; categoryDao.Create(category); myEvent = new Event(); myEvent.categoryId = categoryId; myEvent.name = name; myEvent.eventDate = date; myEvent.review = review; myEvent.Category = category; myEvent.Comments = new List <Comment>(); myEvent.Recommendations = new List <Recommendation>(); eventDao.Create(myEvent); label = new Label(); label.name = categoryName; labelDao.Create(label); comment = new Comment(); comment.content = content; comment.Event = myEvent; comment.Labels = new List <Label>(); comment.loginName = userProfile.loginName; comment.UserProfile = userProfile; comment.commentDate = DateTime.Now; commentDao.Create(comment); comment2 = new Comment(); comment2.content = content; comment2.Event = myEvent; comment2.Labels = new List <Label>(); comment2.Labels.Add(label); comment2.loginName = userProfile.loginName; comment2.UserProfile = userProfile; comment2.commentDate = date; commentDao.Create(comment2); }
public void MyTestInitialize() { transaction = new TransactionScope(); userProfile = new UserProfile(); userProfile.loginName = loginName; userProfile.enPassword = PasswordEncrypter.Crypt(clearPassword); userProfile.firstName = firstName; userProfile.lastName = lastName; userProfile.email = email; userProfile.language = language; userProfile.country = country; userProfileDao.Create(userProfile); }
public void EqualsCompareSameInstanceTest() { UserProfile userA = new UserProfile(); userA.userId = 1; userA.loginName = loginName; userA.firstName = firstName; userA.lastName = lastName; userA.language = language; userA.country = country; userA.email = email; userA.enPassword = PasswordEncrypter.Crypt(clearPassword); Assert.IsTrue(userA.Equals(userA)); }
private UserProfile CreateTestUser(string login, string password, string name, string lastName, string email, string language, string country) { UserProfile user = UserProfile.CreateUserProfile( TestData.nonExistentUserId, login, PasswordEncrypter.Crypt(password), name, lastName, email, language, country); UserDao.Create(user); return(user); }
public void LoginEncryptedPasswordTest() { // Register user long userId = userService.RegisterUser(loginName, clearPassword, new UserProfileDetails(firstName, lastName, email, language, country)); LoginResult expected = new LoginResult(userId, firstName, PasswordEncrypter.Crypt(clearPassword), language, country); // Login with encrypted password LoginResult obtained = userService.Login(loginName, PasswordEncrypter.Crypt(clearPassword), true); // Check data Assert.AreEqual(expected, obtained); }
/// <exception cref="IncorrectPasswordException"/> /// <exception cref="InstanceNotFoundException"/> public void ChangePassword(long userProfileId, string oldClearPassword, string newClearPassword) { UserProfile userProfile = UserProfileDao.Find(userProfileId); String storedPassword = userProfile.enPassword; if (!PasswordEncrypter.IsClearPasswordCorrect(oldClearPassword, storedPassword)) { throw new IncorrectPasswordException(userProfile.loginName); } userProfile.enPassword = PasswordEncrypter.Crypt(newClearPassword); UserProfileDao.Update(userProfile); }
public void RegisterUserTest() { // Register user and find profile long userId = userService.RegisterUser(loginName, clearPassword, new UserProfileDetails(firstName, lastName, email, language, country)); UserProfile userProfile = userProfileDao.Find(userId); // Check data Assert.AreEqual(userId, userProfile.usrId); Assert.AreEqual(loginName, userProfile.loginName); Assert.AreEqual(PasswordEncrypter.Crypt(clearPassword), userProfile.enPassword); Assert.AreEqual(firstName, userProfile.firstName); Assert.AreEqual(lastName, userProfile.lastName); Assert.AreEqual(email, userProfile.email); Assert.AreEqual(language, userProfile.language); Assert.AreEqual(country, userProfile.country); }
public long Register(string loginName, string clearPassword, string firstName, string lastName, string email, string languageCode, string countryCode) { if (UserProfileDao.ExistsWithLoginName(loginName)) { throw new DuplicateInstanceException <UserProfileDetails>("loginName", loginName); } UserProfile userProfile = UserProfile.CreateUserProfile(0, loginName, PasswordEncrypter.Crypt(clearPassword), firstName, lastName, email, languageCode, countryCode); try { UserProfileDao.Create(userProfile); } catch (DuplicateInstanceException <UserProfile> ex) { throw new DuplicateInstanceException <UserProfileDetails>(ex.Properties); } return(userProfile.userId); }
public void LoginEncryptedPasswordTest() { using (var scope = new TransactionScope()) { // Register user var userId = userService.RegisterUser(loginName, clearPassword, new UserProfileDetails(firstName, lastName, email, language, country, role, address)); var expected = new LoginResult(userId, firstName, PasswordEncrypter.Crypt(clearPassword), language, country, role, address); // Login with encrypted password var obtained = userService.Login(loginName, PasswordEncrypter.Crypt(clearPassword), true); // Check data Assert.AreEqual(expected, obtained); } }
public void LoginClearPasswordTest() { using (var scope = new TransactionScope()) { // Register user var userId = userService.RegisterUser(loginName, clearPassword, new UserProfileDetails(firstName, lastName, email, language, country)); var expected = new LoginResult(userId, firstName, PasswordEncrypter.Crypt(clearPassword), language, country); // Login with clear password var actual = userService.Login(loginName, clearPassword, false); // Check data Assert.AreEqual(expected, actual); // transaction.Complete() is not called, so Rollback is executed. } }
public void LoginEncryptedPasswordTest() { using (TransactionScope scope = new TransactionScope()) { // Register user long userId = userService.RegisterUser(loginName, clearPassword, new UserProfileDetails(firstName, lastName, email, language, country, postalAddress)); LoginResult expected = new LoginResult(userId, firstName, PasswordEncrypter.Crypt(clearPassword), language, country); // Login with encrypted password LoginResult obtained = userService.Login(loginName, PasswordEncrypter.Crypt(clearPassword), true); // Check data Assert.AreEqual(expected, obtained); // transaction.Complete() is not called, so Rollback is executed. } }
public void RegisterUserTest() { using (TransactionScope scope = new TransactionScope()) { // Register user and find profile long userId = userService.RegisterUser(loginName, clearPassword, new UserProfileDetails(firstName, lastName, email, language, country, postalAddress)); UserProfile userProfile = userProfileDao.Find(userId); // Check data Assert.AreEqual(userId, userProfile.usrId); Assert.AreEqual(loginName, userProfile.loginName); Assert.AreEqual(PasswordEncrypter.Crypt(clearPassword), userProfile.enPassword); Assert.AreEqual(firstName, userProfile.firstName); Assert.AreEqual(lastName, userProfile.lastName); Assert.AreEqual(email, userProfile.email); Assert.AreEqual(language, userProfile.language); Assert.AreEqual(country, userProfile.country); // transaction.Complete() is not called, so Rollback is executed. } }
public void RegisterUserTest() { using (var scope = new TransactionScope()) { // Register user and find profile var userId = userService.RegisterUser(loginName, clearPassword, new UserProfileDetails(firstName, lastName, email, language, country, role, address)); var userProfile = userProfileDao.Find(userId); // Check data Assert.AreEqual(userId, userProfile.usrId); Assert.AreEqual(loginName, userProfile.loginName); Assert.AreEqual(PasswordEncrypter.Crypt(clearPassword), userProfile.enPassword); Assert.AreEqual(firstName, userProfile.firstName); Assert.AreEqual(lastName, userProfile.lastName); Assert.AreEqual(email, userProfile.email); Assert.AreEqual(language, userProfile.language); Assert.AreEqual(country, userProfile.country); Assert.AreEqual(role, userProfile.role); Assert.AreEqual(address, userProfile.address); } }