public ActionResult Create(UserInputModel userInputModel) { if (_session.Query<User>().Any(x => x.Username == userInputModel.Username)) { ModelState.AddModelError("Username", "Username is already in use"); } if (ModelState.IsValid) { var company = new Company(userInputModel.Username + " Co."); _session.Store(company); var user = new User( userInputModel.Username, Encryption.HashPassword(userInputModel.Password), new string[0], company); _session.Store(user); _authenticator.SetCookie(user.Id, false, user.Roles.ToArray()); return RedirectToAction("Index", "Home"); } return View("New", userInputModel); }
public void Post_Create_AddsANewUserToTheDatabase() { var userViewModel = new UserInputModel() { Username = "******", Password = "******" }; Act(() => { var controller = new UserController(Substitute.For<IAuthenticator>(), _session, null); controller.Create(userViewModel); }); AssertThat(() => { var newUser = _session.Query<User>() .SingleOrDefault(x => x.Username == userViewModel.Username); Assert.NotNull(newUser); }); }