Пример #1
0
        public ActionResult Login(LoginForm form)
        {
            if (form.Username == "admin" && form.Password == "admin")
            {
                FormsAuthentication.SetAuthCookie("admin", false);
                return Redirect(AppRoute.App);
            }

            return Redirect(AppRoute.Root);
        }
Пример #2
0
        protected override void Test()
        {
            Application.Execute(client =>
            {
                // Arrange.
                const string Username = "******";

                var form = new LoginForm
                {
                    Username = Username,
                    Password = "******"
                };

                var view = new CrowbarViewContext("_LoginForm").SetAnonymousPrincipal();

                // Act.
                var response = client.Render(view, form).Submit();

                // Assert.
                response.ShouldHaveTemporarilyRedirectTo(AppRoute.App);
                response.ShouldHaveCookie(FormsAuthentication.FormsCookieName);
            });
        }
Пример #3
0
        protected override void Test()
        {
            Application.Execute(client =>
            {
                // Arrange.
                const string Username = "******";
                var form = new LoginForm
                {
                    Username = Username,
                    Password = "******"
                };

                var view = new CrowbarViewContext("_LoginForm");
                view.SetFormsAuthPrincipal("invalid"); // simulate invalid anti-forgery request token.

                // Act.
                // Obviously the MVC application should handle this more gracefully, this is just an example.
                var exception = Assert.Throws<CrowbarException>(() => client.Render(view, form).Submit());

                // Assert.
                Assert.That(exception.InnerException, Is.TypeOf<HttpAntiForgeryException>());
            });
        }
Пример #4
0
        protected override void Test()
        {
            Application.Execute(client =>
            {
                // Arrange.
                var form = new LoginForm
                {
                    Username = "******",
                    Password = "******"
                };

                // Act.
                var response = client.Render("_LoginForm", form).Submit();

                // Assert.
                response.ShouldHaveTemporarilyRedirectTo(AppRoute.Root);
            });
        }