Inheritance: MaverickController
Esempio n. 1
0
        public void Land_Calls_GetReturnUrl_With_ControllerContext_If_IdentitySource_Found()
        {
            // Arrange
            var controller = new IdentityController();
            controller.IdentitySources.AddMock(UnusedMockIdentitySource);

            var mockSource = controller.IdentitySources.AddMock(SelectedMockIdentitySource);

            // Act
            controller.Land(SelectedMockIdentitySource);

            // Assert
            mockSource.Verify(s => s.GetReturnUrl(controller.ControllerContext));
        }
Esempio n. 2
0
        private static void TestExpectedNotFoundResult(Func<IdentityController, ActionResult> action)
        {
            // Arrange
            var controller = new IdentityController();
            controller.IdentitySources.AddMock(UnusedMockIdentitySource);
            controller.IdentitySources.AddMock(SelectedMockIdentitySource);

            // Act
            ActionResult result = action(controller);

            // Assert
            ResultAssert.IsResourceNotFound(result);
        }
Esempio n. 3
0
        public void Logout_Redirects_To_Home_Page()
        {
            // Arrange
            var controller = new IdentityController();
            controller.IdentitySources.AddMock(UnusedMockIdentitySource);

            var mockSessionManager = new Mock<ISessionIdentityManager>();
            controller.SessionIdentityManager = mockSessionManager.Object;

            // Act
            ActionResult result = controller.Logout();

            // Assert
            ResultAssert.IsRedirectToRoute(result, new {controller = "Page", action = "View", page = (Page)null});
        }
Esempio n. 4
0
        public void Logout_Removes_Session_Token()
        {
            // Arrange
            var controller = new IdentityController();
            controller.IdentitySources.AddMock(UnusedMockIdentitySource);

            var mockSessionManager = new Mock<ISessionIdentityManager>();
            controller.SessionIdentityManager = mockSessionManager.Object;

            // Act
            controller.Logout();

            // Assert
            mockSessionManager.Verify(s => s.ClearSessionPrincipal());
        }
Esempio n. 5
0
        public void LoginPost_Returns_Result_Of_OnLoginFormSubmit()
        {
            // Arrange
            var controller = new IdentityController();
            controller.IdentitySources.AddMock(UnusedMockIdentitySource);

            var mockSource = controller.IdentitySources.AddMock(SelectedMockIdentitySource);

            EmptyResult expectedResult = new EmptyResult();
            mockSource.Setup(s => s.OnLoginFormSubmit(It.IsAny<ControllerContext>(), TestReturnUrl))
                      .Returns(expectedResult);

            // Act
            ActionResult actualResult = controller.LoginPost(SelectedMockIdentitySource, TestReturnUrl.ToString());

            // Assert
            Assert.AreSame(expectedResult, actualResult);
        }
Esempio n. 6
0
        public void Logout_Calls_IdentitySource_To_Logout_If_Token_Contains_IdentifiedBy_Claim_Matching_Valid_IdentitySource()
        {
            // Arrange
            var controller = new IdentityController();
            controller.IdentitySources.AddMock(UnusedMockIdentitySource);

            var mockSource = controller.IdentitySources.AddMock(SelectedMockIdentitySource);

            var mockSessionManager = new Mock<ISessionIdentityManager>();
            controller.SessionIdentityManager = mockSessionManager.Object;

            Claim claim = new Claim(MaverickClaimTypes.IdentifiedBy, SelectedMockIdentitySource);
            IPrincipal oldPrincipal = Thread.CurrentPrincipal;
            Thread.CurrentPrincipal = new ClaimsPrincipal(new ClaimsIdentity(claim));

            // Act
            controller.Logout();

            // Assert
            mockSource.Verify(s => s.Logout(controller.ControllerContext));

            // Cleanup
            Thread.CurrentPrincipal = oldPrincipal;
        }
Esempio n. 7
0
        public void LoginPost_Calls_OnLoginFormSubmit_If_IdentitySource_Found()
        {
            // Arrange
            var controller = new IdentityController();
            controller.IdentitySources.AddMock(UnusedMockIdentitySource);

            var mockSource = controller.IdentitySources.AddMock(SelectedMockIdentitySource);

            // Act
            ActionResult actualResult = controller.LoginPost(SelectedMockIdentitySource, TestReturnUrl.ToString());

            // Assert
            mockSource.Verify(s => s.OnLoginFormSubmit(controller.ControllerContext, TestReturnUrl));
        }
Esempio n. 8
0
        public void LoginPost_Does_Not_Alter_ViewName_If_It_Starts_With_Tilde()
        {
            // Arrange
            var controller = new IdentityController();
            controller.IdentitySources.AddMock(UnusedMockIdentitySource);

            var mockSource = controller.IdentitySources.AddMock(SelectedMockIdentitySource);

            mockSource.Setup(s => s.OnLoginFormSubmit(It.IsAny<ControllerContext>(), TestReturnUrl))
                      .Returns(new ViewResult { ViewName = TestExplicitViewName });

            // Act
            ActionResult actualResult = controller.LoginPost(SelectedMockIdentitySource, TestReturnUrl.ToString());

            // Assert
            ResultAssert.IsView(actualResult, TestExplicitViewName, ExpectedMasterName);
        }
Esempio n. 9
0
        public void LoginGet_Returns_Result_Of_IdentitySource_Login()
        {
            // Arrange
            var controller = new IdentityController();
            controller.IdentitySources.AddMock(UnusedMockIdentitySource);

            var mockSource = controller.IdentitySources.AddMock(SelectedMockIdentitySource);

            EmptyResult expectedResult = new EmptyResult();
            mockSource.Setup(s => s.Login(It.IsAny<ControllerContext>(), TestReturnUrl))
                      .Returns(expectedResult);

            // Act
            ActionResult actualResult = controller.LoginGet(SelectedMockIdentitySource, TestReturnUrl.ToString());

            // Assert
            Assert.AreSame(expectedResult, actualResult, "Expected that the result of Login would be passed unmodified");
        }
Esempio n. 10
0
        public void LoginGet_Calls_Login_With_ControllerContext_And_ReturnUrl_If_IdentitySource_Found()
        {
            // Arrange
            var controller = new IdentityController();
            controller.IdentitySources.AddMock(UnusedMockIdentitySource);

            var mockSource = controller.IdentitySources.AddMock(SelectedMockIdentitySource);

            // Act
            controller.LoginGet(SelectedMockIdentitySource, TestReturnUrl.ToString());

            // Assert
            mockSource.Verify(s => s.Login(controller.ControllerContext, TestReturnUrl));
        }
Esempio n. 11
0
        public void LoginGet_Alters_Master_And_View_Name_If_Result_Is_ViewResult()
        {
            // Arrange
            var controller = new IdentityController();
            controller.IdentitySources.AddMock(UnusedMockIdentitySource);

            var mockSource = controller.IdentitySources.AddMock(SelectedMockIdentitySource);

            mockSource.Setup(s => s.Login(It.IsAny<ControllerContext>(), TestReturnUrl))
                      .Returns(new ViewResult {ViewName = TestViewName});

            // Act
            ActionResult actualResult = controller.LoginGet(SelectedMockIdentitySource, TestReturnUrl.ToString());

            // Assert
            ResultAssert.IsView(actualResult, ExpectedViewName, ExpectedMasterName);
        }
Esempio n. 12
0
        public void Land_Redirects_To_ReturnUrl_If_Present()
        {
            // Arrange
            var controller = new IdentityController();
            controller.IdentitySources.AddMock(UnusedMockIdentitySource);

            var mockSource = controller.IdentitySources.AddMock(SelectedMockIdentitySource);
            mockSource.Setup(s => s.GetReturnUrl(It.IsAny<ControllerContext>()))
                      .Returns(TestReturnUrl);

            // Act
            ActionResult result = controller.Land(SelectedMockIdentitySource);

            // Assert
            ResultAssert.IsRedirect(result, TestReturnUrl.ToString());
        }
Esempio n. 13
0
        public void Land_Redirects_To_HomePage_If_No_Return_Url()
        {
            // Arrange
            var controller = new IdentityController();
            controller.IdentitySources.AddMock(UnusedMockIdentitySource);

            var mockSource = controller.IdentitySources.AddMock(SelectedMockIdentitySource);

            // Act
            ActionResult result = controller.Land(SelectedMockIdentitySource);

            // Assert
            ResultAssert.IsRedirectToRoute(result, new {controller = "Page", action = "View", page = (Page)null});
        }