Beispiel #1
0
        public void OneTimeSetUp()
        {
            var authenticatedIdentity = new MockIdentity(true);
            var authenticatedUser     = new ClaimsPrincipal(authenticatedIdentity);

            authenticatedIdentity.AddClaim(new Claim("ID", "123"));

            _authenticationManager = new FakeAuthenticationManager()
                                     .WithUser(authenticatedUser).Build().Object;
        }
Beispiel #2
0
        public void Login_ShouldDisplayLoginPageForUnauthenticatedUser()
        {
            // Setup Authentication Manager
            var unAuthenticatedIdentity = new MockIdentity();
            var authenticatedUser       = new ClaimsPrincipal(unAuthenticatedIdentity);

            var authenticationManager = new FakeAuthenticationManager()
                                        .WithUser(authenticatedUser).Build();

            // Call login method
            ActionResult result = _controller
                                  .WithAuthenticationManager(authenticationManager.Object).Build()
                                  .Login();

            // Verify Login view is returned
            result.AssertIsView("Login");
        }
Beispiel #3
0
        public void Login_ShouldRedirectAuthenticatedUserToHomePage()
        {
            // Setup Authentication Manager
            var authenticatedIdentity = new MockIdentity(true);
            var authenticatedUser     = new ClaimsPrincipal(authenticatedIdentity);

            var authenticationManager = new FakeAuthenticationManager()
                                        .WithUser(authenticatedUser).Build();

            // Call login method
            ActionResult result = _controller
                                  .WithAuthenticationManager(authenticationManager.Object).Build()
                                  .Login();

            // Verify user is redirected to Home page
            result.AssertIsRedirect("Home", "Index");
        }
Beispiel #4
0
        public void Login_ShouldSetReturnUrlIfProvided()
        {
            // Setup Authentication Manager
            var unAuthenticatedIdentity = new MockIdentity();
            var authenticatedUser       = new ClaimsPrincipal(unAuthenticatedIdentity);

            var authenticationManager = new FakeAuthenticationManager()
                                        .WithUser(authenticatedUser).Build();

            // Call login method
            ActionResult result = _controller
                                  .WithAuthenticationManager(authenticationManager.Object).Build()
                                  .Login("/TestReturnUrl");

            // Verify expected result
            ViewResult returnedView = result.AssertIsView("Login");

            Assert.AreEqual("/TestReturnUrl", returnedView.ViewBag.ReturnUrl.ToString());
        }