コード例 #1
0
        public void InactiveUserCannotLogon()
        {
            Session.Store(new User(firstName: "f", lastName: "l", email: "*****@*****.**", password: "******"));
            Session.SaveChanges();

            bool loggedOn = false;
            var service = Mock.Of<IAuthenticationService>();
            Mock.Get(service).Setup(s => s.SetAuthCookie(It.IsAny<string>(), It.IsAny<bool>())).Callback(
                () => loggedOn = true);
            var controller = new AccountController(service)
                {
                    DocumentSession = Session,
                    Url = CreateUrlHelper()
                };
            var result = controller.LogOn(
                new LogOnViewModel
                    {
                        Email = "*****@*****.**",
                        Password = "******"
                    },
                string.Empty);
            Assert.True(controller.ModelState.ContainsKey("Inactive"));
            result.AssertViewRendered().ForView(string.Empty);

            Assert.False(loggedOn);
        }
コード例 #2
0
        public void LogonReturnsView()
        {
            // Arrange
            var controller = new AccountController(Mock.Of<IAuthenticationService>()) { DocumentSession = Session };

            // Act
            var result = controller.LogOn();

            // Assert
            result.AssertViewRendered().ForView(string.Empty);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        public void UnknownUserCannotLogon()
        {
            var service = Mock.Of<IAuthenticationService>();
            bool cookieSet = false;
            Mock.Get(service)
                .Setup(x => x.SetAuthCookie(It.IsAny<string>(), It.IsAny<bool>()))
                .Callback(() => cookieSet = true);

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

            result.AssertViewRendered().ForView(string.Empty);
            Assert.False(cookieSet);
        }