public void AddUser_should_save() { string username = "******" + Guid.NewGuid(); var user = new User { Email = "*****@*****.**", FirstName = "john", IsActive = true, LastName = "haigh", PasswordHash = "asdf", Username = username }; var svc = new UserService(); svc.AddUser(user); var repo = new UserRepository(); var repoUser = repo.Find(u => u.Username == username).FirstOrDefault(); // Test repoUser.ShouldNotBeNull(); // Cleanup user repo.Delete(repoUser); repo.Save(); var results2 = repo.Find(u => u.Username == username); var userFound2 = results2.FirstOrDefault(); Assert.IsNull(userFound2, "Tried to get user but the user was found"); }
public void Register(string username, string firstname, string lastname, string password, string email) { // Hash the password var hashedPassword = Hasher.CreateHash(password); var existUser = new UsersDataModel.User { Email = email, LastName = lastname, FirstName = firstname, PasswordHash = hashedPassword, Username = username }; // fail safe in case someone has registered this account after the register check user has been called. if (_userService.GetUserByUsername(existUser.Username) == null) { _userService.AddUser(existUser); } }
public void AddUser_should_save_with_user_properties() { string username = "******" + Guid.NewGuid(); var user = new User { Email = "*****@*****.**", FirstName = "john", IsActive = true, LastName = "haigh", PasswordHash = "asdf", Username = username }; var svc = new UserService(); svc.AddUser(user); var repo = new UserRepository(); var repoUser = repo.Find(u => u.Username == username).FirstOrDefault(); // Test repoUser.Email.ShouldEqual(user.Email); repoUser.FirstName.ShouldEqual(user.FirstName); repoUser.LastName.ShouldEqual(user.LastName); repoUser.IsActive.ShouldEqual(user.IsActive); repoUser.PasswordHash.ShouldEqual(user.PasswordHash); repoUser.Username.ShouldEqual(user.Username); // Cleanup user repo.Delete(repoUser); repo.Save(); var results2 = repo.Find(u => u.Username == username); var userFound2 = results2.FirstOrDefault(); userFound2.ShouldBeNull(); }
public void GetUserByUsername_should_getuser() { string username = "******" + Guid.NewGuid(); var user = new User { Email = "*****@*****.**", FirstName = "john", IsActive = true, LastName = "haigh", PasswordHash = "asdf", Username = username }; var svc = new UserService(); svc.AddUser(user); // main test var userAssert = svc.GetUserByUsername(username); userAssert.ShouldNotBeNull(); // Assert var repo = new UserRepository(); var repoUser = repo.Find(u => u.Username == username).FirstOrDefault(); // Cleanup user repo.Delete(repoUser); repo.Save(); var results2 = repo.Find(u => u.Username == username); var userFound2 = results2.FirstOrDefault(); userFound2.ShouldBeNull(); }