public void TestGetAllUsernames() { UserSqlDal dal = new UserSqlDal(); List <string> output = dal.GetAllUsernames(); Assert.AreEqual(3, output.Count); CollectionAssert.Contains(output, "Bob"); CollectionAssert.Contains(output, "Boo"); CollectionAssert.DoesNotContain(output, "Boa"); }
public ActionResult Register(UserModel user) { UserSqlDal dal = new UserSqlDal(); if (ModelState.IsValid) { var newUser = new UserModel { Username = user.Username, Password = user.Password, }; List <string> existingUsers = dal.GetAllUsernames(); foreach (string name in existingUsers) { if (name == user.Username) { user.IsTaken = true; return(View("Register", user)); } } var hashProvider = new HashProvider(); user.Password = hashProvider.HashPassword(user.Password); user.Salt = hashProvider.SaltValue; dal.Register(user); Session["user"] = user; Session["username"] = user.Username; user.IsTaken = false; return(RedirectToAction("LoggedInLanding", "Home")); } else { return(View("Register", user)); } }