/// <summary> /// Converts the user entered data into a User object. /// </summary> /// <param name="encryption">Business class used to encrypt /// the password entered by the user.</param> /// <returns>User object made up of this data.</returns> public virtual User ToUser(IEncryption encryption) { var user = new User(); user.Username = Username; user.SetPassword(encryption.Encrypt(Password)); return user; }
public void SetPassword_ShouldSetPasswordSalt() { var password = new Encryption().Encrypt("password"); var user = new User(); user.SetPassword(password); Assert.That(user.PasswordSalt, Is.EqualTo(password.Salt)); }
/// <summary> /// Converts the user entered data into a User object. /// </summary> /// <param name="encryption">Business class used to encrypt /// the password entered by the user.</param> /// <returns>User object made up of this data.</returns> public virtual User ToUser(IEncryption encryption) { var user = new User(); user.Username = Username; user.MakeAdmin(); user.Password = encryption.Encrypt(Password); return user; }
public void Index_HttpPostWithValidModel_CallsCreateOnUserServiceWithUserFromModel() { var expectedUser = new User(); var mockInstallViewModel = _autoMoqer.GetMock<InstallViewModel>(); mockInstallViewModel.Setup(x => x.ToUser(_autoMoqer.GetMock<IEncryption>().Object)).Returns(expectedUser); _autoMoqer.Resolve<InstallController>().Index(mockInstallViewModel.Object); _autoMoqer.GetMock<IUserService>().Verify(x => x.Create(expectedUser), Times.Once()); }
public void MakeAdmin_NotAnAdmin_AddsAdminRoleToRoles() { var user = new User(); user.MakeAdmin(); Assert.That(user.Roles.Contains(Role.Admin), Is.True); }
public void MakeAdmin_AlreadyAdmin_DoesntDuplicateAdminRoleInRoles() { var user = new User { Roles = new List<string> { Role.Admin } }; user.MakeAdmin(); Assert.That(user.Roles.Where(x => x == Role.Admin).Count(), Is.EqualTo(1)); }
/// <summary> /// Inserts the user into the database, thus /// creating a new user in the system. /// </summary> /// <param name="user">User that is being created.</param> /// <returns>True if successful, otherwise false.</returns> public void Create(User user) { _db.Users.Insert(user); }
/// <summary> /// Sets data about the User onto the Session /// that is stored on the current context. /// </summary> /// <param name="user">User that the data being /// set on the Session.</param> public void SetSessionData(User user) { _httpContextProvider.Session["LoggedInAs"] = user.Username; }
/// <summary> /// Authenticates the session, which changes the clients /// state to logged in. /// </summary> /// <param name="user">User that has signed in.</param> /// <param name="remember">Whether the user should be /// remembered next time they visit.</param> public void Start(User user, bool remember) { var expireDate = GetExpiryDate(remember); var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, CreateEncryptedTicket(user.Id.ToString(), String.Empty, expireDate, remember)); if (remember) cookie.Expires = expireDate; _httpContextProvider.Response.Cookies.Add(cookie); SetSessionData(user); }
public void Create_InsertsUserIntoDatabase() { const string expectedUsername = "******"; var userBeingCreated = new User { Username = expectedUsername }; _autoMoqer.Resolve<UserService>().Create(userBeingCreated); Assert.That((User)_memoryDatabaseProvider.GetDb().Users.FindByUsername(expectedUsername), !Is.Null); }