예제 #1
0
 public UserInvitedEvent(User user, string activationUri)
 {
     if (user == null) throw new ArgumentNullException("user");
     if (activationUri == null) throw new ArgumentNullException("activationUri");
     User = user;
     ActivationUri = activationUri;
 }
예제 #2
0
 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);
        }
예제 #5
0
        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);
        }
예제 #7
0
        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");
            }
        }
예제 #8
0
        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");
        }
예제 #9
0
        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");
        }
예제 #10
0
 public void ShouldNotBeActiveWhenCreated()
 {
     var user = new User("first name", "last name", "email", "password");
     Assert.False(user.IsActive);
 }
예제 #11
0
 public void CanActivate()
 {
     var user = new User("F", "L", "*****@*****.**", "pwd");
     user.Activate();
     Assert.True(user.IsActive);
 }
예제 #12
0
        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");
        }