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 CanLogOnAfterRegisteringAndVerifyingAccount()
        {
            // register
            var model = new RegisterViewModel
                {
                    FirstName = "F",
                    LastName = "L",
                    Email = "*****@*****.**",
                    ConfirmEmail = "*****@*****.**",
                    Password = "******"
                };

            var controller1 = new AccountController(Mock.Of<IAuthenticationService>()) { DocumentSession = Session };
            using (DomainEvent.Disable()) controller1.Register(model);

            // normally done by infrastructure (special action filter)
            Session.SaveChanges();

            // verify
            var registeredUser = Session.FindUserByEmail("*****@*****.**");
            Assert.NotNull(registeredUser);
            var key = registeredUser.ActivationKey;

            var controller2 = new AccountController(Mock.Of<IAuthenticationService>()) { DocumentSession = Session };
            controller2.Verify(Guid.Parse(key));

            // logon
            var loggedOn = false;
            var service = Mock.Of<IAuthenticationService>();
            Mock.Get(service)
                .Setup(s => s.SetAuthCookie(It.Is<string>(e => e == "*****@*****.**"), It.IsAny<bool>()))
                .Callback(() => loggedOn = true);

            var controller3 = new AccountController(service)
                {
                    DocumentSession = Session,
                    Url = CreateUrlHelper()
                };
            controller3.LogOn(
                new LogOnViewModel
                    {
                        Email = "*****@*****.**",
                        Password = "******"
                    },
                string.Empty);

            Assert.True(loggedOn);
        }
 public void UnknownIdFails()
 {
     var controller = new AccountController(Mock.Of<IAuthenticationService>()) { DocumentSession = Session };
     var result = controller.Verify(Guid.NewGuid());
     result.AssertActionRedirect().ToAction("Register");
 }