public UserInvitedEvent(User user, string activationUri) { if (user == null) throw new ArgumentNullException("user"); if (activationUri == null) throw new ArgumentNullException("activationUri"); User = user; ActivationUri = activationUri; }
protected User CreateActivatedUser(string firstName, string lastName, string email, string password) { var user = new User(firstName, lastName, email, password); user.Activate(); Session.Store(user); Session.SaveChanges(); return user; }
private ActionResult VerifyActivationKeyForUser(User user) { bool loggedSomebodyOn = false; var service = Mock.Of<IAuthenticationService>(); Mock.Get(service) .Setup(s => s.SetAuthCookie(It.IsAny<string>(), It.IsAny<bool>())) .Callback(() => loggedSomebodyOn = true); var controller = new AccountController(service) { DocumentSession = Session }; var result = controller.Verify(Guid.Parse(user.ActivationKey)); Assert.False(loggedSomebodyOn); return result; }
public void KnownUserIsActivatedAndShownSuccess() { var user = new User("F", "L", "*****@*****.**", "some pwd"); Session.Store(user); Session.SaveChanges(); VerifyActivationKeyForUser(user) .AssertActionRedirect() .ToAction("VerifySuccess"); var storedUser = Session.FindUserByEmail("*****@*****.**"); Assert.NotNull(storedUser); Assert.True(storedUser.IsActive); }
public void ShouldRaiseEventWhenCreated() { NewUserCreatedEvent createdEvent = null; using (DomainEvent.TestWith(e => createdEvent = (NewUserCreatedEvent)e)) { var user = new User("first name", "last name", "email", "password"); user.Initialize(); } Assert.NotNull(createdEvent); Assert.Equal("first name", createdEvent.User.FirstName); Assert.Equal("last name", createdEvent.User.LastName); Assert.Equal("email", createdEvent.User.Email); Assert.False(createdEvent.User.IsActive); }
public void StoredCorrectly() { var original = new User("F", "L", "*****@*****.**", "some pwd"); using (DomainEvent.Disable()) { original.Activate(); Session.Store(original); Session.SaveChanges(); } var user = Session.FindUserByEmail("*****@*****.**"); Assert.Equal(original.ActivationKey, user.ActivationKey); Assert.Equal(original.Email, user.Email); Assert.Equal(original.FirstName, user.FirstName); Assert.Equal(original.Id, user.Id); Assert.Equal(original.IsActive, user.IsActive); Assert.Equal(original.LastName, user.LastName); }
public void CanSerializeUser() { // Arrange var user = new User("firstName", "lastName", "*****@*****.**", "some-pass"); // Act using (var session = Store.OpenSession()) { session.Store(user); session.SaveChanges(); } // Assert using (var session = Store.OpenSession()) { var loadedUser = session.Load<User>(user.Id); Assert.True(loadedUser.ValidatePassword("some-pass"), "Password validation failed"); } }
public ActionResult CreateAdmin(RegisterViewModel adminUser) { AssertAdminUserExists(); if (!ModelState.IsValid) return View("Index"); var user = new User( adminUser.FirstName, adminUser.LastName, adminUser.Email, adminUser.Password) { Id = "Admin" }; user.Activate(); DocumentSession.Store(user); return RedirectToAction("Success"); }
public ActionResult CreateUser(CreateUserViewModel vm) { // an existing user cannot be registered again if (DocumentSession.FindUserByEmail(vm.Email) != null) ModelState.AddModelError("Email", "Användaren finns redan"); // redisplay form if any errors at this point if (!ModelState.IsValid) return View(vm); var newUser = new User(string.Empty, string.Empty, vm.Email, string.Empty); DocumentSession.Store(newUser); return RedirectToAction("Users"); }
public void ShouldNotBeActiveWhenCreated() { var user = new User("first name", "last name", "email", "password"); Assert.False(user.IsActive); }
public void CanActivate() { var user = new User("F", "L", "*****@*****.**", "pwd"); user.Activate(); Assert.True(user.IsActive); }
public ActionResult Register(RegisterViewModel model) { // an existing user cannot be registered again if (DocumentSession.FindUserByEmail(model.Email) != null) ModelState.AddModelError("Email", "Adressen finns redan."); // redisplay form if any errors at this point if (!ModelState.IsValid) return View(model); var newUser = new User(model.FirstName, model.LastName, model.Email, model.Password); newUser.Initialize(); DocumentSession.Store(newUser); return RedirectToAction("RegisterSuccess"); }